FEATURE: move categories into own repository

This commit is contained in:
Michal Kváček
2017-08-22 14:10:50 +02:00
commit 16471b010f
27 changed files with 679 additions and 0 deletions
@@ -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');
});
}
}
View File
+20
View File
@@ -0,0 +1,20 @@
<?php namespace Modules\Categories\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class CategoriesDatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call("OthersTableSeeder");
}
}