1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Phinx\Migration\AbstractMigration; |
4
|
|
|
|
5
|
|
|
class InitialMigration extends AbstractMigration { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Create basic database schema |
9
|
|
|
*/ |
10
|
|
|
public function change() |
11
|
|
|
{ |
12
|
|
|
// Session storage table |
13
|
|
|
if ( ! $this->hasTable('todo_ci_sessions')) |
14
|
|
|
{ |
15
|
|
|
$this->table('todo_ci_sessions', [ |
16
|
|
|
'id' => FALSE, |
17
|
|
|
'primary_key' => 'session_id' |
18
|
|
|
])->addColumn('session_id' , 'string', ['limit' => 40]) |
19
|
|
|
->addColumn('ip_address', 'string', ['limit' => 40]) |
20
|
|
|
->addColumn('user_agent', 'string', ['limit' => 255]) |
21
|
|
|
->addColumn('last_activity', 'integer') |
22
|
|
|
->addColumn('user_data', 'text') |
23
|
|
|
->create(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// User table |
27
|
|
|
if ( ! $this->hasTable('todo_user')) |
28
|
|
|
{ |
29
|
|
|
$this->table('todo_user') |
30
|
|
|
->addColumn('username', 'string', ['limit' => 255]) |
31
|
|
|
->addColumn('password', 'string', ['limit' => 255]) |
32
|
|
|
->addColumn('email', 'string', ['limit' => 128]) |
33
|
|
|
->addColumn('enabled', 'integer', ['default' => 1]) |
34
|
|
|
->addColumn('timezone', 'string', ['limit' => 32, 'default' => 'America/Detroit']) |
35
|
|
|
->addColumn('num_format', 'integer', ['default' => 0]) |
36
|
|
|
->addColumn('reset_token', 'string', ['limit' => 128]) |
37
|
|
|
->create(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// Group table |
41
|
|
|
if ( ! $this->hasTable('todo_group')) |
42
|
|
|
{ |
43
|
|
|
$this->table('todo_group') |
44
|
|
|
->addColumn('name', 'string', ['limit' => 128]) |
45
|
|
|
->create(); |
46
|
|
|
|
47
|
|
|
// Seed data |
48
|
|
|
$this->execute("INSERT INTO todo_group VALUES (0, 'global');"); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Category table |
52
|
|
|
if ( ! $this->hasTable('todo_category')) |
53
|
|
|
{ |
54
|
|
|
$this->table('todo_category') |
55
|
|
|
->addColumn('title', 'string', ['limit' => 128]) |
56
|
|
|
->addColumn('description', 'text', ['null' => FALSE]) |
57
|
|
|
->addColumn('group_id', 'integer', ['default' => 0]) |
58
|
|
|
//->addForeignKey('group_id', 'todo_group', 'id') |
59
|
|
|
->create(); |
60
|
|
|
|
61
|
|
|
// Seed the data |
62
|
|
|
$this->execute(" |
63
|
|
|
INSERT INTO todo_category VALUES (1, 'Work', 'Tasks related to work', 0); |
64
|
|
|
INSERT INTO todo_category VALUES (7, 'Optional ', 'Tasks that are not necessary, but it would be nice to see them completed.', 0); |
65
|
|
|
INSERT INTO todo_category VALUES (10, 'School', 'School related tasks', 0); |
66
|
|
|
INSERT INTO todo_category VALUES (11, 'Other', 'Tasks that don''t fit in another category.', 0); |
67
|
|
|
INSERT INTO todo_category VALUES (13, 'Personal', 'Personal tasks to do', 0); |
68
|
|
|
"); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Priority list table |
72
|
|
|
if ( ! $this->hasTable('todo_priority')) |
73
|
|
|
{ |
74
|
|
|
$this->table('todo_priority') |
75
|
|
|
->addColumn('value', 'string') |
76
|
|
|
->create(); |
77
|
|
|
|
78
|
|
|
// Seed the data |
79
|
|
|
$this->execute(" |
80
|
|
|
INSERT INTO todo_priority VALUES (1, 'Optional'); |
81
|
|
|
INSERT INTO todo_priority VALUES (2, 'Lowest'); |
82
|
|
|
INSERT INTO todo_priority VALUES (3, 'Lower'); |
83
|
|
|
INSERT INTO todo_priority VALUES (4, 'Low'); |
84
|
|
|
INSERT INTO todo_priority VALUES (5, 'Normal'); |
85
|
|
|
INSERT INTO todo_priority VALUES (6, 'High'); |
86
|
|
|
INSERT INTO todo_priority VALUES (7, 'Higher'); |
87
|
|
|
INSERT INTO todo_priority VALUES (8, 'Highest'); |
88
|
|
|
INSERT INTO todo_priority VALUES (9, 'Immediate'); |
89
|
|
|
"); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
// Status list table |
93
|
|
|
if ( ! $this->hasTable('todo_status')) |
94
|
|
|
{ |
95
|
|
|
$this->table('todo_status') |
96
|
|
|
->addColumn('value', 'string') |
97
|
|
|
->create(); |
98
|
|
|
|
99
|
|
|
// Seed the data |
100
|
|
|
$this->execute(" |
101
|
|
|
INSERT INTO todo_status VALUES (3, 'In Progress'); |
102
|
|
|
INSERT INTO todo_status VALUES (4, 'On Hold'); |
103
|
|
|
INSERT INTO todo_status VALUES (5, 'Canceled'); |
104
|
|
|
INSERT INTO todo_status VALUES (2, 'Completed'); |
105
|
|
|
INSERT INTO todo_status VALUES (1, 'Created'); |
106
|
|
|
"); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// Task table |
110
|
|
|
if ( ! $this->hasTable('todo_item')) |
111
|
|
|
{ |
112
|
|
|
$this->table('todo_item') |
113
|
|
|
->addColumn('user_id', 'integer') |
114
|
|
|
->addColumn('category_id', 'integer') |
115
|
|
|
->addColumn('priority', 'integer') |
116
|
|
|
->addColumn('status', 'integer', ['default' => 0]) |
117
|
|
|
->addColumn('title', 'string', ['limit' => 128]) |
118
|
|
|
->addColumn('description', 'text', ['null' => FALSE]) |
119
|
|
|
->addColumn('due', 'integer', ['default' => 0]) |
120
|
|
|
->addColumn('modified', 'integer') |
121
|
|
|
->addColumn('created', 'integer') |
122
|
|
|
->addForeignKey('category_id', 'todo_category', 'id') |
123
|
|
|
->addForeignKey('priority', 'todo_priority', 'id') |
124
|
|
|
->addForeignKey('status', 'todo_status', 'id') |
125
|
|
|
->addForeignKey('user_id', 'todo_user', 'id') |
126
|
|
|
->create(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// Checklist table |
130
|
|
|
if ( ! $this->hasTable('todo_checklist')) |
131
|
|
|
{ |
132
|
|
|
$this->table('todo_checklist') |
133
|
|
|
->addColumn('task_id', 'integer') |
134
|
|
|
->addColumn('desc', 'string', ['limit' => 128]) |
135
|
|
|
->addColumn('is_checked', 'integer') |
136
|
|
|
->addForeignKey('task_id', 'todo_item', 'id') |
137
|
|
|
->create(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
// Group task sharing table |
142
|
|
View Code Duplication |
if ( ! $this->hasTable('todo_group_task_link')) |
143
|
|
|
{ |
144
|
|
|
$this->table('todo_group_task_link', [ |
145
|
|
|
'id' => FALSE, |
146
|
|
|
'primary_key' => ['group_id', 'task_id'] |
147
|
|
|
])->addColumn('group_id', 'integer') |
148
|
|
|
->addColumn('task_id', 'integer') |
149
|
|
|
->addColumn('permissions', 'integer') |
150
|
|
|
->addForeignKey('group_id', 'todo_group', 'id') |
151
|
|
|
->addForeignKey('task_id', 'todo_item', 'id') |
152
|
|
|
->create(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// Group user sharing table |
156
|
|
View Code Duplication |
if ( ! $this->hasTable('todo_group_users_link')) |
157
|
|
|
{ |
158
|
|
|
$this->table('todo_group_users_link', [ |
159
|
|
|
'id' => FALSE, |
160
|
|
|
'primary_key' => ['group_id', 'user_id'] |
161
|
|
|
])->addColumn('group_id', 'integer') |
162
|
|
|
->addColumn('user_id', 'integer') |
163
|
|
|
->addColumn('is_admin', 'integer') |
164
|
|
|
->addForeignKey('group_id', 'todo_group', 'id') |
165
|
|
|
->addForeignKey('user_id', 'todo_user', 'id') |
166
|
|
|
->create(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
// Task comments table |
170
|
|
|
if ( ! $this->hasTable('todo_item_comments')) |
171
|
|
|
{ |
172
|
|
|
$this->table('todo_item_comments') |
173
|
|
|
->addColumn('user_id', 'integer') |
174
|
|
|
->addColumn('item_id', 'integer') |
175
|
|
|
->addColumn('comment', 'text') |
176
|
|
|
->addColumn('time_posted', 'integer') |
177
|
|
|
->addColumn('status', 'integer') |
178
|
|
|
->addForeignKey('item_id', 'todo_item', 'id') |
179
|
|
|
->addForeignKey('status', 'todo_status', 'id') |
180
|
|
|
->addForeignKey('user_id', 'todo_user', 'id') |
181
|
|
|
->create(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
// Reminder table |
185
|
|
|
if ( ! $this->hasTable('todo_reminder')) |
186
|
|
|
{ |
187
|
|
|
$this->table('todo_reminder') |
188
|
|
|
->addColumn('task_id', 'integer') |
189
|
|
|
->addColumn('reminder_time', 'integer') |
190
|
|
|
->addColumn('sent', 'integer', ['default' => 0]) |
191
|
|
|
->addColumn('user_id', 'integer') |
192
|
|
|
->addForeignKey('task_id', 'todo_item', 'id') |
193
|
|
|
->addForeignKey('user_id', 'todo_user', 'id', [ |
194
|
|
|
'update' => 'cascade', |
195
|
|
|
'delete' => 'cascade' |
196
|
|
|
])->create(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
// Friend link table |
200
|
|
View Code Duplication |
if ( ! $this->hasTable('todo_user_friend_link')) |
201
|
|
|
{ |
202
|
|
|
$this->table('todo_user_friend_link', [ |
203
|
|
|
'id' => FALSE, |
204
|
|
|
'primary_key' => ['user_id', 'user_friend_id'] |
205
|
|
|
])->addColumn('user_id', 'integer') |
206
|
|
|
->addColumn('user_friend_id', 'integer') |
207
|
|
|
->addColumn('confirmed', 'integer', ['default' => -1]) |
208
|
|
|
->addForeignKey('user_friend_id', 'todo_user', 'id') |
209
|
|
|
->addForeignKey('user_id', 'todo_user', 'id') |
210
|
|
|
->create(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
// Task shared by user table |
214
|
|
View Code Duplication |
if ( ! $this->hasTable('todo_user_task_link')) |
215
|
|
|
{ |
216
|
|
|
$this->table('todo_user_task_link', [ |
217
|
|
|
'id' => FALSE, |
218
|
|
|
'primary_key' => ['task_id', 'user_id'] |
219
|
|
|
])->addColumn('user_id', 'integer') |
220
|
|
|
->addColumn('task_id', 'integer') |
221
|
|
|
->addColumn('permissions', 'integer') |
222
|
|
|
->addForeignKey('task_id', 'todo_item', 'id') |
223
|
|
|
->addForeignKey('user_id', 'todo_user', 'id') |
224
|
|
|
->create(); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
} |