-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
m170122_185806_init.php
141 lines (120 loc) · 5.89 KB
/
m170122_185806_init.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
use app\components\Migration;
/**
* Initial database structure
*/
class m170122_185806_init extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$this->createTable('{{%user}}', [
'id' => $this->primaryKey(),
'username' => $this->string()->notNull()->unique(),
'fullname' => $this->string(),
'auth_key' => $this->string(32)->notNull(),
'password_hash' => $this->string()->notNull(),
'password_reset_token' => $this->string()->notNull(),
'email' => $this->string(),
'github' => $this->string(),
'twitter' => $this->string(),
'facebook' => $this->string(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
]);
$this->createTable('{{%auth}}', [
'id' => $this->primaryKey(),
'user_id' => $this->integer()->notNull(),
'source' => $this->string()->notNull(),
'source_id' => $this->string()->notNull(),
]);
$this->addForeignKey('fk-auth-user_id-user-id', '{{%auth}}', 'user_id', '{{%user}}', 'id', 'CASCADE');
$this->createTable('{{%project}}', [
'id' => $this->primaryKey(),
'title' => $this->string()->notNull(),
'slug' => $this->string()->notNull(),
'url' => $this->string(),
'is_opensource' => $this->boolean()->notNull()->defaultValue(false),
'source_url' => $this->string(),
'created_by' => $this->integer(),
'updated_by' => $this->integer(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
'is_featured' => $this->boolean()->notNull()->defaultValue(false),
'yii_version' => $this->string()->notNull(),
]);
$this->addForeignKey('fk-project-created_by-user-id', '{{%project}}', 'created_by', '{{%user}}', 'id', 'SET NULL');
$this->addForeignKey('fk-project-updated_by-user-id', '{{%project}}', 'updated_by', '{{%user}}', 'id', 'SET NULL');
$this->createTable('{{%project_description}}', [
'id' => $this->primaryKey(),
'project_id' => $this->integer()->notNull(),
'language' => $this->string()->notNull()->defaultValue('en-US'),
'content' => $this->text()->notNull(),
]);
$this->createTable('{{%project_user}}', [
'project_id' => $this->integer()->notNull(),
'user_id' => $this->integer()->notNull(),
]);
$this->addPrimaryKey('pk-project_user', '{{%project_user}}', ['project_id', 'user_id']);
$this->addForeignKey('fk-project_user-project_id', '{{%project_user}}', 'project_id', '{{%project}}', 'id', 'CASCADE');
$this->addForeignKey('fk-project_user-user_id', '{{%project_user}}', 'user_id', '{{%user}}', 'id', 'CASCADE');
$this->createTable('{{%image}}', [
'id' => $this->primaryKey(),
'project_id' => $this->integer(),
'created_by' => $this->integer(),
'updated_by' => $this->integer(),
'status' => $this->smallInteger()->notNull()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
]);
$this->addForeignKey('fk-image-project_id', '{{%image}}', 'project_id', '{{%project}}', 'id', 'SET NULL');
$this->addForeignKey('fk-image-created_by-user-id', '{{%image}}', 'created_by', '{{%user}}', 'id', 'SET NULL');
$this->addForeignKey('fk-image-updated_by-user-id', '{{%image}}', 'updated_by', '{{%user}}', 'id', 'SET NULL');
$this->createTable('{{%vote}}', [
'id' => $this->primaryKey(),
'user_id' => $this->integer()->notNull(),
'project_id' => $this->integer()->notNull(),
'value' => $this->smallInteger()->notNull(),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
]);
$this->createIndex('idx-vote-unique', '{{%vote}}', ['user_id', 'project_id'], true);
$this->addForeignKey('fk-vote-user_id', '{{%vote}}', 'user_id', '{{%user}}', 'id', 'CASCADE');
$this->addForeignKey('fk-vote-project_id', '{{%vote}}', 'project_id', '{{%project}}', 'id', 'CASCADE');
$this->createTable('{{%tag}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull()->unique(),
'icon' => $this->string(),
'description' => $this->text(),
'type' => $this->smallInteger()->defaultValue(10),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
]);
$this->createTable('{{%project_tag}}', [
'project_id' => $this->integer()->notNull(),
'tag_id' => $this->integer()->notNull(),
]);
$this->addPrimaryKey('pk-project_tag', '{{%project_tag}}', ['project_id', 'tag_id']);
$this->addForeignKey('fk-project_tag-project_id', '{{%project_tag}}', 'project_id', '{{%project}}', 'id', 'CASCADE');
$this->addForeignKey('fk-project_tag-tag_id', '{{%project_tag}}', 'tag_id', '{{%tag}}', 'id', 'CASCADE');
}
/**
* @inheritdoc
*/
public function safeDown()
{
$this->dropTable('{{%project_tag}}');
$this->dropTable('{{%tag}}');
$this->dropTable('{{%vote}}');
$this->dropTable('{{%image}}');
$this->dropTable('{{%project_user}}');
$this->dropTable('{{%project_description}}');
$this->dropTable('{{%project}}');
$this->dropTable('{{%auth}}');
$this->dropTable('{{%user}}');
}
}