FEATURE: add support for submodules

This commit is contained in:
Michal Kváček
2016-08-15 20:46:54 +02:00
parent d54f160d6a
commit fa21c407b4
4 changed files with 150 additions and 0 deletions
@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class MakeModuleHandlerNullable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('modules', function (Blueprint $table) {
$table->string('handler')
->nullable(true)
->change();
$table->string('alias')
->nullable(true)
->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('modules', function (Blueprint $table) {
$table->string('alias')
->nullable(false)
->change();
// somehow I cannot change it back, sorry...
// $table->string('handler')
// ->nullable(false)
// ->change();
});
}
}
@@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddParentModuleIdToModules extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('modules', function (Blueprint $table) {
$table->integer('parent_id')
->nullable(true)
->comment('Parent module ID (when module is submodule)')
->after('id');
$table->boolean('has_submodules')
->default(false);
$table->foreign('parent_id')
->references('id')
->on('modules')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('modules', function (Blueprint $table) {
$table->dropForeign('modules_parent_id_foreign');
$table->dropColumn('has_submodules');
$table->dropColumn('parent_id');
});
}
}