InitialMigration::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
/**
6
 * Initial migration to create a PHPCI v1.2 database.
7
 */
8
class InitialMigration extends AbstractMigration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * Migrate Up.
12
     */
13
    public function up()
14
    {
15
        // Set up tables:
16
        $this->createBuildTable();
17
        $this->createBuildMetaTable();
18
        $this->createProjectTable();
19
        $this->createUserTable();
20
21
        // Set up foreign keys:
22
        $build = $this->table('build');
23
24
        if (!$build->hasForeignKey('project_id')) {
25
            $build->addForeignKey('project_id', 'project', 'id', array('delete' => 'CASCADE', 'update' => 'CASCADE'));
26
        }
27
28
        $build->save();
29
30
        $buildMeta = $this->table('build_meta');
31
32
        if (!$buildMeta->hasForeignKey('build_id')) {
33
            $buildMeta->addForeignKey('build_id', 'build', 'id', array('delete' => 'CASCADE', 'update' => 'CASCADE'));
34
        }
35
36
        if (!$buildMeta->hasForeignKey('project_id')) {
37
            $buildMeta->addForeignKey('project_id', 'project', 'id', array('delete' => 'CASCADE', 'update' => 'CASCADE'));
38
        }
39
40
        $buildMeta->save();
41
    }
42
43
    /**
44
     * Migrate Down.
45
     */
46
    public function down()
47
    {
48
    }
49
50
    protected function createBuildTable()
51
    {
52
        $table = $this->table('build');
53
54
        if (!$this->hasTable('build')) {
55
            $table->create();
56
        }
57
58
        if (!$table->hasColumn('project_id')) {
59
            $table->addColumn('project_id', 'integer');
60
        }
61
62
        if (!$table->hasColumn('commit_id')) {
63
            $table->addColumn('commit_id', 'string', array('limit' => 50));
64
        }
65
66
        if (!$table->hasColumn('status')) {
67
            $table->addColumn('status', 'integer', array('limit' => 4));
68
        }
69
70
        if (!$table->hasColumn('log')) {
71
            $table->addColumn('log', 'text');
72
        }
73
74
        if (!$table->hasColumn('branch')) {
75
            $table->addColumn('branch', 'string', array('limit' => 50));
76
        }
77
78
        if (!$table->hasColumn('created')) {
79
            $table->addColumn('created', 'datetime');
80
        }
81
82
        if (!$table->hasColumn('started')) {
83
            $table->addColumn('started', 'datetime');
84
        }
85
86
        if (!$table->hasColumn('finished')) {
87
            $table->addColumn('finished', 'datetime');
88
        }
89
90
        if (!$table->hasColumn('committer_email')) {
91
            $table->addColumn('committer_email', 'string', array('limit' => 250));
92
        }
93
94
        if (!$table->hasColumn('commit_message')) {
95
            $table->addColumn('commit_message', 'text');
96
        }
97
98
        if (!$table->hasColumn('extra')) {
99
            $table->addColumn('extra', 'text');
100
        }
101
102
        if ($table->hasColumn('plugins')) {
103
            $table->removeColumn('plugins');
104
        }
105
106
        if (!$table->hasIndex(array('project_id'))) {
107
            $table->addIndex(array('project_id'));
108
        }
109
110
        if (!$table->hasIndex(array('status'))) {
111
            $table->addIndex(array('status'));
112
        }
113
114
        $table->save();
115
    }
116
117
    protected function createBuildMetaTable()
118
    {
119
        $table = $this->table('build_meta');
120
121
        if (!$this->hasTable('build_meta')) {
122
            $table->create();
123
        }
124
125
        if (!$table->hasColumn('project_id')) {
126
            $table->addColumn('project_id', 'integer');
127
        }
128
129
        if (!$table->hasColumn('build_id')) {
130
            $table->addColumn('build_id', 'integer');
131
        }
132
133
        if (!$table->hasColumn('meta_key')) {
134
            $table->addColumn('meta_key', 'string', array('limit' => 250));
135
        }
136
137
        if (!$table->hasColumn('meta_value')) {
138
            $table->addColumn('meta_value', 'text');
139
        }
140
141
        if (!$table->hasIndex(array('build_id', 'meta_key'))) {
142
            $table->addIndex(array('build_id', 'meta_key'));
143
        }
144
145
        $table->save();
146
    }
147
148
    protected function createProjectTable()
149
    {
150
        $table = $this->table('project');
151
152
        if (!$this->hasTable('project')) {
153
            $table->create();
154
        }
155
156
        if (!$table->hasColumn('title')) {
157
            $table->addColumn('title', 'string', array('limit' => 250));
158
        }
159
160
        if (!$table->hasColumn('reference')) {
161
            $table->addColumn('reference', 'string', array('limit' => 250));
162
        }
163
164
        if (!$table->hasColumn('git_key')) {
165
            $table->addColumn('git_key', 'text');
166
        }
167
168
        if (!$table->hasColumn('public_key')) {
169
            $table->addColumn('public_key', 'text');
170
        }
171
172
        if (!$table->hasColumn('type')) {
173
            $table->addColumn('type', 'string', array('limit' => 50));
174
        }
175
176
        if (!$table->hasColumn('access_information')) {
177
            $table->addColumn('access_information', 'string', array('limit' => 250));
178
        }
179
180
        if (!$table->hasColumn('last_commit')) {
181
            $table->addColumn('last_commit', 'string', array('limit' => 250));
182
        }
183
184
        if (!$table->hasColumn('build_config')) {
185
            $table->addColumn('build_config', 'text');
186
        }
187
188
        if (!$table->hasColumn('allow_public_status')) {
189
            $table->addColumn('allow_public_status', 'integer');
190
        }
191
192
        if ($table->hasColumn('token')) {
193
            $table->removeColumn('token');
194
        }
195
196
        if (!$table->hasIndex(array('title'))) {
197
            $table->addIndex(array('title'));
198
        }
199
200
        $table->save();
201
    }
202
203
    protected function createUserTable()
204
    {
205
        $table = $this->table('user');
206
207
        if (!$this->hasTable('user')) {
208
            $table->create();
209
        }
210
211
        if (!$table->hasColumn('email')) {
212
            $table->addColumn('email', 'string', array('limit' => 250));
213
        }
214
215
        if (!$table->hasColumn('hash')) {
216
            $table->addColumn('hash', 'string', array('limit' => 250));
217
        }
218
219
        if (!$table->hasColumn('name')) {
220
            $table->addColumn('name', 'string', array('limit' => 250));
221
        }
222
223
        if (!$table->hasColumn('is_admin')) {
224
            $table->addColumn('is_admin', 'integer');
225
        }
226
227
        if (!$table->hasIndex(array('email'))) {
228
            $table->addIndex(array('email'));
229
        }
230
231
        $table->save();
232
    }
233
}
234