forked from cebe/yii2-openapi
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathm200000_000002_create_table_blog_posts.php
More file actions
35 lines (33 loc) · 1.6 KB
/
m200000_000002_create_table_blog_posts.php
File metadata and controls
35 lines (33 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Table for Post
*/
class m200000_000002_create_table_blog_posts extends \yii\db\Migration
{
public function up()
{
$this->createTable('{{%blog_posts}}', [
0 => 'uid varchar(128) NOT NULL',
'title' => $this->string(255)->notNull(),
'slug' => $this->string(200)->notNull(),
'category_id' => $this->integer()->notNull()->comment('Category of posts'),
'active' => $this->boolean()->notNull()->defaultValue(false),
'created_at' => $this->date()->notNull(),
'created_by_id' => $this->integer()->notNull()->comment('The User'),
]);
$this->addPrimaryKey('pk_blog_posts_uid', '{{%blog_posts}}', 'uid');
$this->createIndex('blog_posts_title_key', '{{%blog_posts}}', 'title', true);
$this->createIndex('blog_posts_slug_key', '{{%blog_posts}}', 'slug', true);
$this->addForeignKey('fk_blog_posts_category_id_categories_id', '{{%blog_posts}}', 'category_id', '{{%categories}}', 'id');
$this->addForeignKey('fk_blog_posts_created_by_id_users_id', '{{%blog_posts}}', 'created_by_id', '{{%users}}', 'id');
}
public function down()
{
$this->dropForeignKey('fk_blog_posts_created_by_id_users_id', '{{%blog_posts}}');
$this->dropForeignKey('fk_blog_posts_category_id_categories_id', '{{%blog_posts}}');
$this->dropIndex('blog_posts_slug_key', '{{%blog_posts}}');
$this->dropIndex('blog_posts_title_key', '{{%blog_posts}}');
$this->dropPrimaryKey('pk_blog_posts_uid', '{{%blog_posts}}');
$this->dropTable('{{%blog_posts}}');
}
}