From 214cc9f3f92d67b77a71f44ced82118a11274521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Thu, 18 Feb 2016 14:45:15 +0100 Subject: [PATCH] FEATURE #1452: add parent id and name to template_paths table --- ..._18_122645_RemoveModuleIdFromTemplates.php | 45 +++++++++++++++++ ...2248_AddNameAndParentIdToTemplatePaths.php | 50 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 database/migrations/2016_02_18_122645_RemoveModuleIdFromTemplates.php create mode 100644 database/migrations/2016_02_18_132248_AddNameAndParentIdToTemplatePaths.php diff --git a/database/migrations/2016_02_18_122645_RemoveModuleIdFromTemplates.php b/database/migrations/2016_02_18_122645_RemoveModuleIdFromTemplates.php new file mode 100644 index 00000000..0b5d1457 --- /dev/null +++ b/database/migrations/2016_02_18_122645_RemoveModuleIdFromTemplates.php @@ -0,0 +1,45 @@ +dropIndex('templates_module_id_template_name_unique'); + $table->dropForeign('templates_module_id_foreign'); + $table->dropColumn('module_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('templates', function (Blueprint $table) { + + $table->integer('module_id') + ->after('id') + ->comment('Template belongs to module specified with this ID.'); + + $table->index('module_id'); + $table->unique(['module_id', 'template_name']); + + $table->foreign('module_id') + ->references('id') + ->on('modules') + ->onDelete('cascade') + ->onUpdate('cascade'); + }); + } +} diff --git a/database/migrations/2016_02_18_132248_AddNameAndParentIdToTemplatePaths.php b/database/migrations/2016_02_18_132248_AddNameAndParentIdToTemplatePaths.php new file mode 100644 index 00000000..5f409f67 --- /dev/null +++ b/database/migrations/2016_02_18_132248_AddNameAndParentIdToTemplatePaths.php @@ -0,0 +1,50 @@ +string('name') + ->after('path') + ->comment('Human readable name'); + + $table->integer('parent_id') + ->after('id') + ->nullable() + ->default(null) + ->comment('ID of parent directory'); + + $table->index('parent_id'); + + // add FK to self + $table->foreign('parent_id') + ->references('id') + ->on('template_paths') + ->onDelete('cascade') + ->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('template_paths', function (Blueprint $table) { + $table->dropForeign('template_paths_parent_id_foreign'); + $table->dropColumn('parent_id'); + $table->dropColumn('name'); + }); + } +}