From 97fc32c3ae71655f290f75b4716aa0fa92a1babf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Sun, 13 Mar 2016 14:41:05 +0100 Subject: [PATCH] FEATURE #1508: add database structure for directories --- ...03_13_131109_AddFileFirectoriesSupport.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 database/migrations/2016_03_13_131109_AddFileFirectoriesSupport.php diff --git a/database/migrations/2016_03_13_131109_AddFileFirectoriesSupport.php b/database/migrations/2016_03_13_131109_AddFileFirectoriesSupport.php new file mode 100644 index 00000000..00cea2e7 --- /dev/null +++ b/database/migrations/2016_03_13_131109_AddFileFirectoriesSupport.php @@ -0,0 +1,74 @@ +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'); + + } +}