FEATURE: move categories into own repository
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCategoriesTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
|
||||
Schema::create('categories', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCategoryClosuresTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('category_closure', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user