Created
July 12, 2016 21:32
-
-
Save Piterden/9cb349aa07b21507e3d7149b9bb1f538 to your computer and use it in GitHub Desktop.
[Laravel 5] Migrations example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateCategoriesTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
if (!Schema::hasTable('categories')) { | |
Schema::create('categories', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->integer('parent_id')->default(0)->nullable(); | |
$table->integer('lft')->unsigned()->nullable(); | |
$table->integer('rgt')->unsigned()->nullable(); | |
$table->integer('depth')->unsigned()->nullable(); | |
$table->string('name'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
}); | |
} | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('categories'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateEventsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
if (!Schema::hasTable('events')) | |
{ | |
Schema::create('events', function (Blueprint $table) | |
{ | |
/** | |
* Columns | |
*/ | |
$table->increments('id'); | |
$table->boolean('published')->default(1)->comment('Опубликовано'); | |
$table->string('title', 255)->comment('Название события'); | |
$table->string('slug', 255)->comment('Псевдоним (необходим для формирования маршрута)'); | |
$table->integer('category_id')->unsigned()->comment('ID типа события'); | |
$table->mediumtext('description')->comment('Описание'); | |
$table->string('orig_title', 255)->default('')->comment('Оригинальное название'); | |
$table->string('year', 50)->default('')->comment('Год'); | |
$table->string('country', 100)->default('')->comment('Страна'); | |
$table->string('carrier', 50)->default('')->comment('Носитель (DCP, 35 mm, Blu-ray)'); | |
$table->string('language', 50)->default('')->comment('Язык'); | |
$table->string('subtitles', 100)->default('')->comment('Субтитры или дубляж'); | |
$table->string('director', 255)->default('')->comment('Режиссер'); | |
$table->string('writtenby', 255)->default('')->comment('Сценарист'); | |
$table->string('operator', 255)->default('')->comment('Оператор'); | |
$table->string('producer', 255)->default('')->comment('Продюсер'); | |
$table->string('link')->default('')->comment('Ссылка на официальный сайт'); | |
$table->integer('chrono')->unsigned()->default(0)->comment('Хронометраж'); | |
$table->integer('age_restrictions')->unsigned()->default(0)->comment('Возрастные ограничения'); | |
$table->mediumtext('meta')->comment('META Tags'); | |
$table->mediumtext('actors')->comment('Актеры в главных ролях'); | |
$table->mediumtext('awards')->comment('Награды и фестивали'); | |
$table->mediumtext('videos')->comment('Видеоролик'); | |
$table->mediumtext('images')->comment('Изображение или набор изображений'); | |
$table->mediumtext('properties'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
/** | |
* Indexes | |
*/ | |
$table->index('published'); | |
$table->index('title'); | |
$table->index('slug'); | |
$table->index('category_id'); | |
$table->index('orig_title'); | |
$table->index('year'); | |
$table->index('country'); | |
$table->index('language'); | |
$table->index('subtitles'); | |
$table->index('age_restrictions'); | |
$table->index('director'); | |
$table->index('writtenby'); | |
$table->index('operator'); | |
$table->index('producer'); | |
// $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade'); | |
}); | |
} | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('events'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateProgramsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
if (!Schema::hasTable('programs')) | |
{ | |
Schema::create('programs', function (Blueprint $table) | |
{ | |
/** | |
* Columns | |
*/ | |
$table->increments('id'); | |
$table->boolean('published')->default(1)->comment('Опубликовано'); | |
$table->string('title', 255)->comment('Название события'); | |
$table->string('slug', 255)->comment('Псевдоним (необходим для формирования маршрута)'); | |
$table->mediumtext('description')->comment('Описание'); | |
$table->dateTimeTz('start_date')->comment('Дата начала'); | |
$table->dateTimeTz('end_date')->comment('Дата конца'); | |
$table->string('slogan', 255)->default('')->comment('Слоган'); | |
$table->mediumtext('videos')->comment('Видеоролик {video}'); | |
$table->mediumtext('images')->comment('Изображение или набор изображений {$Images}'); | |
$table->mediumtext('meta')->comment('META Tags'); | |
$table->mediumtext('properties'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
/** | |
* Indexes | |
*/ | |
$table->index('published'); | |
$table->index('title'); | |
$table->index('slug'); | |
$table->index('start_date'); | |
$table->index('end_date'); | |
}); | |
} | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('programs'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateSeancesTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
if (!Schema::hasTable('seances')) | |
{ | |
Schema::create('seances', function (Blueprint $table) | |
{ | |
/** | |
* Columns | |
*/ | |
$table->increments('id'); | |
$table->integer('event_id')->unsigned()->comment('Событие'); | |
$table->integer('program_id')->unsigned()->nullable()->comment('Программа'); | |
$table->integer('place_id')->unsigned()->comment('Площадка (кинотеатр)'); | |
$table->integer('price')->unsigned()->nullable()->comment('Цена билета'); | |
$table->dateTimeTz('start_time')->comment('Дата и время проведения'); | |
$table->string('description')->comment('Описание'); | |
$table->mediumtext('speaker_info')->comment('Информация о спикере'); | |
$table->mediumtext('images')->comment('Изображение или набор изображений'); | |
$table->mediumtext('videos')->comment('Видеоролик'); | |
$table->mediumtext('properties'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
/** | |
* Indexes | |
*/ | |
$table->index('event_id'); | |
$table->index('program_id'); | |
$table->index('place_id'); | |
$table->index('start_time'); | |
$table->index('price'); | |
/** | |
* Foreign keys | |
*/ | |
// $table->foreign('event_id')->references('id')->on('events')->onDelete('cascade'); | |
// $table->foreign('program_id')->references('id')->on('programs')->onDelete('cascade'); | |
}); | |
} | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::dropIfExists('seances'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment