misuzu/database/2018_04_13_140000_create_news_tables.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2018-04-14 04:58:53 +02:00
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
2018-04-30 23:39:43 +02:00
use Misuzu\DatabaseV1;
2018-04-14 04:58:53 +02:00
// phpcs:disable
class CreateNewsTables extends Migration
{
/**
* @SuppressWarnings(PHPMD)
*/
public function up()
{
2018-04-30 23:39:43 +02:00
$schema = DatabaseV1::connection()->getSchemaBuilder();
2018-04-14 04:58:53 +02:00
$schema->create('news_categories', function (Blueprint $table) {
$table->increments('category_id');
$table->string('category_name');
$table->text('category_description');
$table->boolean('is_hidden')->default(false);
$table->timestamps();
});
$schema->create('news_posts', function (Blueprint $table) {
$table->increments('post_id');
$table->integer('category_id')->unsigned();
$table->boolean('is_featured')->default(false);
$table->integer('user_id')->unsigned()->nullable();
$table->string('post_title');
$table->text('post_text');
$table->timestamp('scheduled_for')->useCurrent();
$table->timestamps();
$table->softDeletes();
$table->foreign('category_id')
->references('category_id')
->on('news_categories')
->onUpdate('cascade')
->onDelete('cascade');
$table->foreign('user_id')
->references('user_id')
->on('users')
->onUpdate('cascade')
->onDelete('set null');
});
}
/**
* @SuppressWarnings(PHPMD)
*/
public function down()
{
2018-04-30 23:39:43 +02:00
$schema = DatabaseV1::connection()->getSchemaBuilder();
2018-04-14 04:58:53 +02:00
$schema->drop('news_posts');
$schema->drop('news_categories');
}
}