Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 152
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Version000007Date20190401053312
0.00% covered (danger)
0.00%
0 / 152
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 preSchemaChange
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 changeSchema
0.00% covered (danger)
0.00%
0 / 150
0.00% covered (danger)
0.00%
0 / 1
72
 postSchemaChange
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace OCA\Cospend\Migration;
6
7use Closure;
8use OCP\DB\ISchemaWrapper;
9use OCP\Migration\SimpleMigrationStep;
10use OCP\Migration\IOutput;
11
12/**
13 * Auto-generated migration step: Please modify to your needs!
14 */
15class Version000007Date20190401053312 extends SimpleMigrationStep {
16
17    /**
18     * @param IOutput $output
19     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20     * @param array $options
21     */
22    public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
23    }
24
25    /**
26     * @param IOutput $output
27     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28     * @param array $options
29     * @return null|ISchemaWrapper
30     */
31    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
32        /** @var ISchemaWrapper $schema */
33        $schema = $schemaClosure();
34
35        if (!$schema->hasTable('cospend_projects')) {
36            $table = $schema->createTable('cospend_projects');
37            $table->addColumn('id', 'string', [
38                'notnull' => true,
39                'length' => 64,
40            ]);
41            $table->addColumn('userid', 'string', [
42                'notnull' => false,
43                'length' => 64,
44            ]);
45            $table->addColumn('name', 'string', [
46                'notnull' => true,
47                'length' => 300,
48            ]);
49            $table->addColumn('email', 'string', [
50                'notnull' => true,
51                'length' => 300,
52            ]);
53            $table->addColumn('password', 'string', [
54                'notnull' => true,
55                'length' => 300,
56            ]);
57        }
58
59        if (!$schema->hasTable('cospend_ext_projects')) {
60            $table = $schema->createTable('cospend_ext_projects');
61            $table->addColumn('id', 'integer', [
62                'autoincrement' => true,
63                'notnull' => true,
64                'length' => 4,
65            ]);
66            $table->addColumn('projectid', 'string', [
67                'notnull' => true,
68                'length' => 64,
69            ]);
70            $table->addColumn('ncurl', 'string', [
71                'notnull' => false,
72                'length' => 300,
73            ]);
74            $table->addColumn('userid', 'string', [
75                'notnull' => false,
76                'length' => 64,
77            ]);
78            $table->addColumn('password', 'string', [
79                'notnull' => true,
80                'length' => 300,
81            ]);
82            $table->setPrimaryKey(['id']);
83        }
84
85        if (!$schema->hasTable('cospend_shares')) {
86            $table = $schema->createTable('cospend_shares');
87            $table->addColumn('id', 'integer', [
88                'autoincrement' => true,
89                'notnull' => true,
90                'length' => 4,
91            ]);
92            $table->addColumn('projectid', 'string', [
93                'notnull' => true,
94                'length' => 64,
95            ]);
96            $table->addColumn('userid', 'string', [
97                'notnull' => false,
98                'length' => 64,
99            ]);
100            $table->addColumn('isgroupshare', 'smallint', [
101                'notnull' => true,
102                'length' => 1,
103                'default' => 0,
104            ]);
105            $table->setPrimaryKey(['id']);
106        }
107        else {
108            // if previous version had the table
109            // but was old enough not to have isgroupshare column
110            $table = $schema->getTable('cospend_shares');
111            if (!$table->hasColumn('isgroupshare')) {
112                $table->addColumn('isgroupshare', 'smallint', [
113                    'notnull' => true,
114                    'length' => 1,
115                    'default' => 0,
116                ]);
117            }
118        }
119
120        if (!$schema->hasTable('cospend_members')) {
121            $table = $schema->createTable('cospend_members');
122            $table->addColumn('id', 'integer', [
123                'autoincrement' => true,
124                'notnull' => true,
125                'length' => 4,
126            ]);
127            $table->addColumn('projectid', 'string', [
128                'notnull' => true,
129                'length' => 64,
130            ]);
131            $table->addColumn('name', 'string', [
132                'notnull' => true,
133                'length' => 300,
134            ]);
135            $table->addColumn('weight', 'float', [
136                'notnull' => true,
137                'length' => 10,
138            ]);
139            $table->addColumn('activated', 'integer', [
140                'notnull' => true,
141                'length' => 4,
142                'default' => 1,
143            ]);
144            $table->setPrimaryKey(['id']);
145        }
146
147        if (!$schema->hasTable('cospend_bills')) {
148            $table = $schema->createTable('cospend_bills');
149            $table->addColumn('id', 'integer', [
150                'autoincrement' => true,
151                'notnull' => true,
152                'length' => 4,
153            ]);
154            $table->addColumn('projectid', 'string', [
155                'notnull' => true,
156                'length' => 64,
157            ]);
158            $table->addColumn('what', 'string', [
159                'notnull' => true,
160                'length' => 300,
161            ]);
162            $table->addColumn('date', 'string', [
163                'notnull' => true,
164                'length' => 20,
165            ]);
166            $table->addColumn('amount', 'float', [
167                'notnull' => true,
168                'length' => 10,
169            ]);
170            $table->addColumn('payerid', 'integer', [
171                'notnull' => true,
172                'length' => 4,
173            ]);
174            $table->addColumn('repeat', 'string', [
175                'notnull' => true,
176                'length' => 1,
177                'default' => 'n',
178            ]);
179            $table->setPrimaryKey(['id']);
180        }
181
182        if (!$schema->hasTable('cospend_bill_owers')) {
183            $table = $schema->createTable('cospend_bill_owers');
184            $table->addColumn('id', 'integer', [
185                'autoincrement' => true,
186                'notnull' => true,
187                'length' => 4,
188            ]);
189            $table->addColumn('billid', 'integer', [
190                'notnull' => true,
191                'length' => 4,
192            ]);
193            $table->addColumn('memberid', 'integer', [
194                'notnull' => true,
195                'length' => 4,
196            ]);
197            $table->setPrimaryKey(['id']);
198        }
199        return $schema;
200    }
201
202    /**
203     * @param IOutput $output
204     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
205     * @param array $options
206     */
207    public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
208    }
209}