BytewaveMLP / sleeti

Simple, free, open source file sharing
Mozilla Public License 2.0
16 stars 4 forks source link

Breaking changes since file IDs were removed #3

Closed BytewaveMLP closed 7 years ago

BytewaveMLP commented 8 years ago

I recently removed file IDs from all routes, favoring owner IDs instead. As a result, you will need to use the following two snippets of code to migrate your database schema. Run the following in order, the first being PHP and the second SQL.

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

require __DIR__ . '/../vendor/autoload.php';

use \Sleeti\Models\User;
use \Sleeti\Models\File;

$settings = json_decode(file_get_contents(__DIR__ . '/../config/config.json'), true);

$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($settings['db'] ?? []);
$capsule->setAsGlobal();
$capsule->bootEloquent();

$files = File::all();

foreach ($files as $file) {
    $file->filename = $file->id . ($file->filename !== null ? '-' . $file->filename : '') . ($file->ext !== null ? '.' . $file->ext : '');
    $file->save();
}
ALTER TABLE `uploaded_files`
  DROP `ext`;
BytewaveMLP commented 7 years ago

It's been almost a year. If anyone still needs this, they can find it in the closed issues I guess. :>