diff --git a/config/app.php b/config/app.php index 7967bb14..0eb76474 100644 --- a/config/app.php +++ b/config/app.php @@ -154,6 +154,7 @@ return [ App\Providers\ModuleManager::class, Pingpong\Modules\ModulesServiceProvider::class, Pingpong\Menus\MenusServiceProvider::class, + Franzose\ClosureTable\ClosureTableServiceProvider::class, \Watson\Sitemap\SitemapServiceProvider::class, /* * Application Service Providers... diff --git a/modules/Categories/Database/Migrations/.gitkeep b/modules/Categories/Database/Migrations/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/modules/Categories/Database/Migrations/2016_08_10_204045_create_categories_table.php b/modules/Categories/Database/Migrations/2016_08_10_204045_create_categories_table.php new file mode 100644 index 00000000..4878c2b1 --- /dev/null +++ b/modules/Categories/Database/Migrations/2016_08_10_204045_create_categories_table.php @@ -0,0 +1,61 @@ +increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('parent_id') + ->unsigned() + ->nullable(); + $table->integer('position', false, true); + $table->integer('real_depth', false, true); + $table->integer('user_id') + ->comment('Author of this category'); + $table->integer('module_id') + ->comment('ID of module, where this category is used'); + $table->string('name') + ->comment('Human readable name of category'); + $table->string('url') + ->index() + ->comment('URL slug of category'); + $table->text('description'); + + $table->unique(['url', 'module_id']); + }); + + Schema::table('categories', function (Blueprint $table) { + $table->foreign('parent_id') + ->references('id') + ->on('categories') + ->onDelete('set null'); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade') + ->onUpdate('cascade'); + + $table->foreign('module_id') + ->references('id') + ->on('modules') + ->onDelete('cascade') + ->onUpdate('cascade'); + }); + } + + public function down() + { + Schema::table('categories', function (Blueprint $table) { + Schema::dropIfExists('categories'); + }); + } +} diff --git a/modules/Categories/Database/Migrations/2016_08_10_204046_create_category_closures_table.php b/modules/Categories/Database/Migrations/2016_08_10_204046_create_category_closures_table.php new file mode 100644 index 00000000..d580f81a --- /dev/null +++ b/modules/Categories/Database/Migrations/2016_08_10_204046_create_category_closures_table.php @@ -0,0 +1,35 @@ +increments('closure_id'); + + $table->integer('ancestor', false, true); + $table->integer('descendant', false, true); + $table->integer('depth', false, true); + + $table->foreign('ancestor') + ->references('id') + ->on('categories') + ->onDelete('cascade'); + $table->foreign('descendant') + ->references('id') + ->on('categories') + ->onDelete('cascade'); + }); + } + + public function down() + { + Schema::table('category_closure', function (Blueprint $table) { + Schema::dropIfExists('category_closure'); + }); + } +}