Commit e6ca281d41cc9b23f80d758e8d738091fa0dc4b4
1 parent
64ff9224
migration: delete default tables
Showing
3 changed files
with
324 additions
and
0 deletions
Show diff stats
1 | +<?php | ||
2 | + | ||
3 | +use Phalcon\Db\Column; | ||
4 | +use Phalcon\Db\Index; | ||
5 | +use Phalcon\Db\Reference; | ||
6 | +use Phalcon\Mvc\Model\Migration; | ||
7 | + | ||
8 | +/** | ||
9 | + * Class ProjectMigration_104 | ||
10 | + */ | ||
11 | +class ProjectMigration_104 extends Migration | ||
12 | +{ | ||
13 | + /** | ||
14 | + * Define the table structure | ||
15 | + * | ||
16 | + * @return void | ||
17 | + */ | ||
18 | + public function morph() | ||
19 | + { | ||
20 | + $this->morphTable('project', [ | ||
21 | + 'columns' => [ | ||
22 | + new Column( | ||
23 | + 'id', | ||
24 | + [ | ||
25 | + 'type' => Column::TYPE_INTEGER, | ||
26 | + 'notNull' => true, | ||
27 | + 'autoIncrement' => true, | ||
28 | + 'first' => true | ||
29 | + ] | ||
30 | + ), | ||
31 | + new Column( | ||
32 | + 'name', | ||
33 | + [ | ||
34 | + 'type' => Column::TYPE_VARCHAR, | ||
35 | + 'size' => 255, | ||
36 | + 'after' => 'id' | ||
37 | + ] | ||
38 | + ), | ||
39 | + new Column( | ||
40 | + 'user_id', | ||
41 | + [ | ||
42 | + 'type' => Column::TYPE_INTEGER, | ||
43 | + 'after' => 'name' | ||
44 | + ] | ||
45 | + ), | ||
46 | + new Column( | ||
47 | + 'created_at', | ||
48 | + [ | ||
49 | + 'type' => Column::TYPE_TIMESTAMP, | ||
50 | + 'size' => 1, | ||
51 | + 'after' => 'user_id' | ||
52 | + ] | ||
53 | + ), | ||
54 | + new Column( | ||
55 | + 'updated_at', | ||
56 | + [ | ||
57 | + 'type' => Column::TYPE_TIMESTAMP, | ||
58 | + 'size' => 1, | ||
59 | + 'after' => 'created_at' | ||
60 | + ] | ||
61 | + ), | ||
62 | + new Column( | ||
63 | + 'ga_view_id', | ||
64 | + [ | ||
65 | + 'type' => Column::TYPE_INTEGER, | ||
66 | + 'after' => 'updated_at' | ||
67 | + ] | ||
68 | + ), | ||
69 | + new Column( | ||
70 | + 'group', | ||
71 | + [ | ||
72 | + 'type' => Column::TYPE_INTEGER, | ||
73 | + 'after' => 'ga_view_id' | ||
74 | + ] | ||
75 | + ) | ||
76 | + ], | ||
77 | + 'indexes' => [ | ||
78 | + new Index('project_pkey', ['id'], null) | ||
79 | + ], | ||
80 | + 'references' => [ | ||
81 | + new Reference( | ||
82 | + 'project_fkey_user_id', | ||
83 | + [ | ||
84 | + 'referencedTable' => 'user', | ||
85 | + 'columns' => ['user_id'], | ||
86 | + 'referencedColumns' => ['id'], | ||
87 | + 'onUpdate' => '', | ||
88 | + 'onDelete' => '' | ||
89 | + ] | ||
90 | + ) | ||
91 | + ], | ||
92 | + ] | ||
93 | + ); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Run the migrations | ||
98 | + * | ||
99 | + * @return void | ||
100 | + */ | ||
101 | + public function up() | ||
102 | + { | ||
103 | + | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Reverse the migrations | ||
108 | + * | ||
109 | + * @return void | ||
110 | + */ | ||
111 | + public function down() | ||
112 | + { | ||
113 | + | ||
114 | + } | ||
115 | + | ||
116 | +} |
1 | +<?php | ||
2 | + | ||
3 | +use Phalcon\Db\Column; | ||
4 | +use Phalcon\Db\Index; | ||
5 | +use Phalcon\Db\Reference; | ||
6 | +use Phalcon\Mvc\Model\Migration; | ||
7 | + | ||
8 | +/** | ||
9 | + * Class UserMigration_104 | ||
10 | + */ | ||
11 | +class UserMigration_104 extends Migration | ||
12 | +{ | ||
13 | + /** | ||
14 | + * Define the table structure | ||
15 | + * | ||
16 | + * @return void | ||
17 | + */ | ||
18 | + public function morph() | ||
19 | + { | ||
20 | + $this->morphTable('user', [ | ||
21 | + 'columns' => [ | ||
22 | + new Column( | ||
23 | + 'id', | ||
24 | + [ | ||
25 | + 'type' => Column::TYPE_INTEGER, | ||
26 | + 'notNull' => true, | ||
27 | + 'autoIncrement' => true, | ||
28 | + 'first' => true | ||
29 | + ] | ||
30 | + ), | ||
31 | + new Column( | ||
32 | + 'username', | ||
33 | + [ | ||
34 | + 'type' => Column::TYPE_VARCHAR, | ||
35 | + 'size' => 1, | ||
36 | + 'after' => 'id' | ||
37 | + ] | ||
38 | + ), | ||
39 | + new Column( | ||
40 | + 'password', | ||
41 | + [ | ||
42 | + 'type' => Column::TYPE_VARCHAR, | ||
43 | + 'size' => 1, | ||
44 | + 'after' => 'username' | ||
45 | + ] | ||
46 | + ), | ||
47 | + new Column( | ||
48 | + 'email', | ||
49 | + [ | ||
50 | + 'type' => Column::TYPE_VARCHAR, | ||
51 | + 'size' => 255, | ||
52 | + 'after' => 'password' | ||
53 | + ] | ||
54 | + ), | ||
55 | + new Column( | ||
56 | + 'role', | ||
57 | + [ | ||
58 | + 'type' => Column::TYPE_VARCHAR, | ||
59 | + 'default' => "User", | ||
60 | + 'notNull' => true, | ||
61 | + 'size' => 1, | ||
62 | + 'after' => 'email' | ||
63 | + ] | ||
64 | + ), | ||
65 | + new Column( | ||
66 | + 'created_at', | ||
67 | + [ | ||
68 | + 'type' => Column::TYPE_TIMESTAMP, | ||
69 | + 'size' => 1, | ||
70 | + 'after' => 'role' | ||
71 | + ] | ||
72 | + ), | ||
73 | + new Column( | ||
74 | + 'updated_at', | ||
75 | + [ | ||
76 | + 'type' => Column::TYPE_TIMESTAMP, | ||
77 | + 'size' => 1, | ||
78 | + 'after' => 'created_at' | ||
79 | + ] | ||
80 | + ) | ||
81 | + ], | ||
82 | + 'indexes' => [ | ||
83 | + new Index('name_uniq', ['username'], null), | ||
84 | + new Index('users_pkey', ['id'], null) | ||
85 | + ], | ||
86 | + ] | ||
87 | + ); | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Run the migrations | ||
92 | + * | ||
93 | + * @return void | ||
94 | + */ | ||
95 | + public function up() | ||
96 | + { | ||
97 | + | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Reverse the migrations | ||
102 | + * | ||
103 | + * @return void | ||
104 | + */ | ||
105 | + public function down() | ||
106 | + { | ||
107 | + | ||
108 | + } | ||
109 | + | ||
110 | +} |
1 | +<?php | ||
2 | + | ||
3 | +use Phalcon\Db\Column; | ||
4 | +use Phalcon\Db\Index; | ||
5 | +use Phalcon\Db\Reference; | ||
6 | +use Phalcon\Mvc\Model\Migration; | ||
7 | + | ||
8 | +/** | ||
9 | + * Class UserProjectMigration_104 | ||
10 | + */ | ||
11 | +class UserProjectMigration_104 extends Migration | ||
12 | +{ | ||
13 | + /** | ||
14 | + * Define the table structure | ||
15 | + * | ||
16 | + * @return void | ||
17 | + */ | ||
18 | + public function morph() | ||
19 | + { | ||
20 | + $this->morphTable('user_project', [ | ||
21 | + 'columns' => [ | ||
22 | + new Column( | ||
23 | + 'id', | ||
24 | + [ | ||
25 | + 'type' => Column::TYPE_INTEGER, | ||
26 | + 'notNull' => true, | ||
27 | + 'autoIncrement' => true, | ||
28 | + 'first' => true | ||
29 | + ] | ||
30 | + ), | ||
31 | + new Column( | ||
32 | + 'user_id', | ||
33 | + [ | ||
34 | + 'type' => Column::TYPE_INTEGER, | ||
35 | + 'notNull' => true, | ||
36 | + 'after' => 'id' | ||
37 | + ] | ||
38 | + ), | ||
39 | + new Column( | ||
40 | + 'project_id', | ||
41 | + [ | ||
42 | + 'type' => Column::TYPE_INTEGER, | ||
43 | + 'notNull' => true, | ||
44 | + 'after' => 'user_id' | ||
45 | + ] | ||
46 | + ) | ||
47 | + ], | ||
48 | + 'indexes' => [ | ||
49 | + new Index('user_project_id_uindex', ['id'], null), | ||
50 | + new Index('user_project_pkey', ['id'], null) | ||
51 | + ], | ||
52 | + 'references' => [ | ||
53 | + new Reference( | ||
54 | + 'user_project_project_id_fk', | ||
55 | + [ | ||
56 | + 'referencedTable' => 'project', | ||
57 | + 'columns' => ['project_id'], | ||
58 | + 'referencedColumns' => ['id'], | ||
59 | + 'onUpdate' => '', | ||
60 | + 'onDelete' => '' | ||
61 | + ] | ||
62 | + ), | ||
63 | + new Reference( | ||
64 | + 'user_project_user_id_fk', | ||
65 | + [ | ||
66 | + 'referencedTable' => 'user', | ||
67 | + 'columns' => ['user_id'], | ||
68 | + 'referencedColumns' => ['id'], | ||
69 | + 'onUpdate' => '', | ||
70 | + 'onDelete' => '' | ||
71 | + ] | ||
72 | + ) | ||
73 | + ], | ||
74 | + ] | ||
75 | + ); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Run the migrations | ||
80 | + * | ||
81 | + * @return void | ||
82 | + */ | ||
83 | + public function up() | ||
84 | + { | ||
85 | + | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Reverse the migrations | ||
90 | + * | ||
91 | + * @return void | ||
92 | + */ | ||
93 | + public function down() | ||
94 | + { | ||
95 | + | ||
96 | + } | ||
97 | + | ||
98 | +} |