m180304_112835_create_article_table
Код: Выделить всё
<?php
use yii\db\Migration;
/**
* Handles the creation of table `article`.
*/
class m180304_112835_create_article_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('article', [
'id' => $this->primaryKey(),
'title' => $this->string(),
'discription' => $this->text(),
'content' => $this->text(),
'date' => $this->date(),
'image' => $this->string(),
'viewed' => $this->integer(),
'user_id' => $this->integer(),
'status' => $this->integer(),
'category_id' => $this->integer(),
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('article');
}
}
Код: Выделить всё
<?php
use yii\db\Migration;
/**
* Handles the creation of table `category`.
*/
class m180304_113659_create_category_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('category', [
'id' => $this->primaryKey(),
'title' => $this->string()
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('category');
}
}
Код: Выделить всё
<?php
use yii\db\Migration;
/**
* Handles the creation of table `tag`.
*/
class m180304_112914_create_tag_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('tag', [
'id' => $this->primaryKey(),
'title' => $this->string()
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('tag');
}
}
Код: Выделить всё
<?php
use yii\db\Migration;
/**
* Handles the creation of table `article_tag`.
*/
class m180304_113052_create_article_tag_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('article_tag', [
'id' => $this->primaryKey(),
'article_id'=>$this->integer(),
'tag_id'=>$this->integer()
]);
// creates index for column `user_id`
$this->createIndex(
'tag_article_article_id',
'article_tag',
'article_id'
);
// add foreign key for table `user`
$this->addForeignKey(
'tag_article_article_id',
'article_tag',
'article_id',
'article',
'id',
'CASCADE'
);
// creates index for column `user_id`
$this->createIndex(
'idx_tag_id',
'article_tag',
'tag_id'
);
// add foreign key for table `user`
$this->addForeignKey(
'fk-tag_id',
'article_tag',
'tag_id',
'tag',
'id',
'CASCADE'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('article_tag');
}
}