FEATURE #1508: add database structure for directories
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddFileFirectoriesSupport extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('directories', function (Blueprint $table) {
|
||||
$table->integer('id', true);
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')
|
||||
->comment('ID of user, who created this directory.')
|
||||
->index();
|
||||
$table->integer('parent_id')
|
||||
->index()
|
||||
->comment('ID of parent directory')
|
||||
->nullable()
|
||||
->default(null);
|
||||
$table->string('name')
|
||||
->comment('Directory name used for better navigation');
|
||||
$table->mediumText('description')
|
||||
->comment('Description of directory')
|
||||
->nullable()
|
||||
->default(null);
|
||||
$table->boolean('hidden')
|
||||
->comment('Hide this directory from view of all directories?')
|
||||
->default(false);
|
||||
$table->unique(['parent_id', 'name']);
|
||||
});
|
||||
|
||||
Schema::table('files', function (Blueprint $table) {
|
||||
$table->dropColumn('directory');
|
||||
$table->integer('directory_id')
|
||||
->index()
|
||||
->after('filename')
|
||||
->comment('FK to directories table')
|
||||
->nullable()
|
||||
->default(null);
|
||||
|
||||
$table->foreign('directory_id')
|
||||
->references('id')
|
||||
->on('directories')
|
||||
->onDelete('restrict')
|
||||
->onUpdate('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('files', function (Blueprint $table) {
|
||||
$table->dropForeign('files_directory_id_foreign');
|
||||
$table->dropColumn('directory_id');
|
||||
$table->string('directory')
|
||||
->comment('Not real directory on FS, only virtual one - used for better user orientation in large file collections')
|
||||
->default('/');
|
||||
});
|
||||
|
||||
Schema::drop('directories');
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user