Passed
Push — dbal ( 46ec49...e8762b )
by Greg
13:28
created

anonymous//app/WebtreesSchema.php$0   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
rs 10
c 1
b 0
f 0
wmc 4
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2022 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees;
21
22
use Doctrine\DBAL\Connection;
23
use Doctrine\DBAL\Platforms\AbstractPlatform;
24
use Doctrine\DBAL\Platforms\SqlitePlatform;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Platforms\SqlitePlatform was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Doctrine\DBAL\Platforms\SQLServerPlatform;
26
use Doctrine\DBAL\Schema\Schema;
27
use Doctrine\DBAL\Schema\SchemaException;
28
use Doctrine\DBAL\Types\PhpDateTimeMappingType;
29
use Doctrine\DBAL\Types\Type;
30
use Doctrine\DBAL\Types\Types;
31
32
use function str_contains;
33
34
/**
35
 * Definitions for the webtrees database.
36
 */
37
class WebtreesSchema
38
{
39
    public function foo(): void
40
    {
41
        switch ('webtrees_schema') {
42
            case 1: // webtrees 1.0.0 - 1.0.3
43
            case 2: // webtrees 1.0.4
44
            case 3:
45
            case 4: // webtrees 1.0.5
46
            case 5: // webtrees 1.0.6
47
            case 6:
48
            case 7:
49
            case 8:
50
            case 9: // webtrees 1.1.0 - 1.1.1
51
            case 10: // webtrees 1.1.2
52
            case 11: // webtrees 1.2.0
53
            case 12: // webtrees 1.2.1 - 1.2.3
54
            case 13:
55
            case 14:
56
            case 15: // webtrees 1.2.4 - 1.2.5
57
            case 16: // webtrees 1.2.7
58
            case 17:
59
            case 18: // webtrees 1.3.0
60
            case 19: // webtrees 1.3.1
61
            case 20: // webtrees 1.3.2
62
            case 21:
63
            case 22:
64
            case 23: // webtrees 1.4.0 - 1.4.1
65
            case 24:
66
            case 25: // webtrees 1.4.2 - 1.4.4, 1.5.0
67
            case 26: // webtrees 1.4.5 - 1.4.6
68
            case 27: // webtrees 1.5.1 - 1.6.0
69
            case 28:
70
            case 29: // webtrees 1.6.1 - 1.6.2
71
            case 30:
72
            case 31: // webtrees 1.7.0 - 1.7.1
73
            case 32: // webtrees 1.7.2
74
            case 33:
75
            case 34: // webtrees 1.7.3 - 1.7.4
76
            case 35:
77
            case 36: // webtrees 1.7.5 - 1.7.7
78
            case 37: // webtrees 1.7.8 - 2.0.0
79
            case 38:
80
            case 39:
81
            case 40: // webtrees 2.0.1 - 2.1.7
82
        }
83
    }
84
85
    /**
86
     * @param Connection $connection
87
     * @param string     $prefix
88
     *
89
     * @return void
90
     *
91
     * @throws SchemaException
92
     * @throws \Doctrine\DBAL\Exception
93
     */
94
    public static function migrate(Connection $connection, string $prefix): void
95
    {
96
        $platform = $connection->getDatabasePlatform();
97
98
        // Existing databases may have enum columns.
99
        $platform->registerDoctrineTypeMapping('enum', 'string');
100
101
        // Timestamp
102
        if (!Type::hasType('timestamp')) {
103
            Type::addType('timestamp', new class extends Type implements PhpDateTimeMappingType {
104
                public function getName(): string {
105
                    return 'timestamp';
106
                }
107
                public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
108
                {
109
                    if ($platform instanceof SqlitePlatform) {
110
                        return 'DATETIME(' . $column['precision'] . ')';
111
                    }
112
113
                    if ($platform instanceof SQLServerPlatform) {
114
                        return 'DATETIME2(' . $column['precision'] . ')';
115
                    }
116
117
                    // Standard SQL
118
                    return 'TIMESTAMP(' . $column['precision'] . ')';
119
                }
120
            });
121
        }
122
123
        $schema_manager = $connection->createSchemaManager();
124
        $current_schema = $schema_manager->createSchema();
125
126
        $schema = new Schema();
127
128
        $table_gedcom = $schema->createTable($prefix . 'gedcom');
129
        $table_gedcom->addColumn('gedcom_id', Types::INTEGER, ['autoincrement' => true]);
130
        $table_gedcom->addColumn('gedcom_name', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
131
        $table_gedcom->addColumn('sort_order', Types::INTEGER, ['default' => 0]);
132
        $table_gedcom->setPrimaryKey(['gedcom_id']);
133
        $table_gedcom->addUniqueIndex(['gedcom_name']);
134
        $table_gedcom->addIndex(['sort_order']);
135
136
        $table_gedcom_setting = $schema->createTable($prefix . 'gedcom_setting');
137
        $table_gedcom_setting->addColumn('gedcom_id', Types::INTEGER);
138
        $table_gedcom_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
139
        $table_gedcom_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
140
        $table_gedcom_setting->setPrimaryKey(['gedcom_id', 'setting_name']);
141
        $table_gedcom_setting->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
142
143
        $table_site_setting = $schema->createTable($prefix . 'site_setting');
144
        $table_site_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
145
        $table_site_setting->addColumn('setting_value', Types::STRING, ['length' => 2000, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
146
        $table_site_setting->setPrimaryKey(['setting_name']);
147
148
        $table_user = $schema->createTable($prefix . 'user');
149
        $table_user->addColumn('user_id', Types::INTEGER, ['autoincrement' => true]);
150
        $table_user->addColumn('user_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
151
        $table_user->addColumn('real_name', Types::STRING, ['length' => 64, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
152
        $table_user->addColumn('email', Types::STRING, ['length' => 64, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
153
        $table_user->addColumn('password', Types::STRING, ['length' => 128, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
154
        $table_user->setPrimaryKey(['user_id']);
155
        $table_user->addUniqueIndex(['user_name']);
156
        $table_user->addUniqueIndex(['email']);
157
158
        $table_user_gedcom_setting = $schema->createTable($prefix . 'user_gedcom_setting');
159
        $table_user_gedcom_setting->addColumn('user_id', Types::INTEGER);
160
        $table_user_gedcom_setting->addColumn('gedcom_id', Types::INTEGER);
161
        $table_user_gedcom_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
162
        $table_user_gedcom_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
163
        $table_user_gedcom_setting->setPrimaryKey(['user_id', 'gedcom_id', 'setting_name']);
164
        $table_user_gedcom_setting->addIndex(['gedcom_id']);
165
        $table_user_gedcom_setting->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
166
        $table_user_gedcom_setting->addForeignKeyConstraint($table_user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
167
168
        $table_user_setting = $schema->createTable($prefix . 'user_setting');
169
        $table_user_setting->addColumn('user_id', Types::INTEGER);
170
        $table_user_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
171
        $table_user_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
172
        $table_user_setting->setPrimaryKey(['user_id', 'setting_name']);
173
        $table_user_setting->addForeignKeyConstraint($table_user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
174
175
        $table_module = $schema->createTable($prefix . 'module');
176
        $table_module->addColumn('module_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
177
        $table_module->addColumn('status', Types::STRING, ['length' => 8, 'platformOptions' => ['collation' => 'ascii_bin']]);
178
        $table_module->addColumn('tab_order', Types::INTEGER, ['notnull' => false]);
179
        $table_module->addColumn('menu_order', Types::INTEGER, ['notnull' => false]);
180
        $table_module->addColumn('sidebar_order', Types::INTEGER, ['notnull' => false]);
181
        $table_module->addColumn('footer_order', Types::INTEGER, ['notnull' => false]);
182
        $table_module->setPrimaryKey(['module_name']);
183
184
        $table_module_privacy = $schema->createTable($prefix . 'module_privacy');
185
        $table_module_privacy->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
186
        $table_module_privacy->addColumn('module_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
187
        $table_module_privacy->addColumn('gedcom_id', Types::INTEGER);
188
        $table_module_privacy->addColumn('interface', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'ascii_bin']]);
189
        $table_module_privacy->addColumn('access_level', Types::SMALLINT);
190
        $table_module_privacy->addUniqueIndex(['gedcom_id', 'module_name', 'interface']);
191
        $table_module_privacy->addUniqueIndex(['module_name', 'gedcom_id', 'interface']);
192
        $table_module_privacy->setPrimaryKey(['id']);
193
        $table_module_privacy->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
194
        $table_module_privacy->addForeignKeyConstraint($table_module, ['module_name'], ['module_name'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
195
196
        $table_module_setting = $schema->createTable($prefix . 'module_setting');
197
        $table_module_setting->addColumn('module_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
198
        $table_module_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
199
        $table_module_setting->addColumn('setting_value', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
200
        $table_module_setting->setPrimaryKey(['module_name', 'setting_name']);
201
        $table_module_setting->addForeignKeyConstraint($table_module, ['module_name'], ['module_name'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
202
203
        $table_block = $schema->createTable($prefix . 'block');
204
        $table_block->addColumn('block_id', Types::INTEGER, ['autoincrement' => true]);
205
        $table_block->addColumn('gedcom_id', Types::INTEGER, ['notnull' => false]);
206
        $table_block->addColumn('user_id', Types::INTEGER, ['notnull' => false]);
207
        $table_block->addColumn('xref', Types::STRING, ['length' => 20, 'notnull' => false]);
208
        $table_block->addColumn('location', Types::STRING, ['length' => 4, 'notnull' => false]);
209
        $table_block->addColumn('block_order', Types::INTEGER);
210
        $table_block->addColumn('module_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
211
        $table_block->setPrimaryKey(['block_id']);
212
        $table_block->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
213
        $table_block->addForeignKeyConstraint($table_user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
214
        $table_block->addForeignKeyConstraint($table_module, ['module_name'], ['module_name'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
215
216
        $table_block_setting = $schema->createTable($prefix . 'block_setting');
217
        $table_block_setting->addColumn('block_id', Types::INTEGER);
218
        $table_block_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
219
        $table_block_setting->addColumn('setting_value', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
220
        $table_block_setting->setPrimaryKey(['block_id', 'setting_name']);
221
        $table_block_setting->addForeignKeyConstraint($table_block, ['block_id'], ['block_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
222
223
        $table_change = $schema->createTable($prefix . 'change');
224
        $table_change->addColumn('change_id', Types::INTEGER, ['autoincrement' => true]);
225
        $table_change->addColumn('change_time', Types::DATETIME_MUTABLE, ['default' => 'CURRENT_TIMESTAMP']);
226
        $table_change->addColumn('status', Types::STRING, ['length' => 8, 'default' => 'pending']);
227
        $table_change->addColumn('gedcom_id', Types::INTEGER);
228
        $table_change->addColumn('xref', Types::STRING, ['length' => 20]);
229
        $table_change->addColumn('old_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
230
        $table_change->addColumn('new_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
231
        $table_change->addColumn('user_id', Types::INTEGER);
232
        $table_change->setPrimaryKey(['change_id']);
233
        $table_change->addIndex(['gedcom_id', 'status', 'xref']);
234
        $table_change->addIndex(['user_id']);
235
        $table_change->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
236
        $table_change->addForeignKeyConstraint($table_user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
237
238
        $table_log = $schema->createTable($prefix . 'log');
239
        $table_log->addColumn('log_id', Types::INTEGER, ['autoincrement' => true]);
240
        $table_log->addColumn('log_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'precision' => 0]);
241
        $table_log->addColumn('log_type', Types::STRING, ['length' => 6]);
242
        $table_log->addColumn('log_message', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
243
        $table_log->addColumn('ip_address', Types::STRING, ['length' => 45]);
244
        $table_log->addColumn('user_id', Types::INTEGER, ['notnull' => false]);
245
        $table_log->addColumn('gedcom_id', Types::INTEGER, ['notnull' => false]);
246
        $table_log->setPrimaryKey(['log_id']);
247
        $table_log->addIndex(['log_time']);
248
        $table_log->addIndex(['log_type']);
249
        $table_log->addIndex(['ip_address']);
250
        $table_log->addIndex(['user_id']);
251
        $table_log->addIndex(['gedcom_id']);
252
        $table_log->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
253
        $table_log->addForeignKeyConstraint($table_user, ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
254
255
        $table_dates = $schema->createTable($prefix . 'dates');
256
        $table_dates->addColumn('d_day', Types::SMALLINT);
257
        $table_dates->addColumn('d_month', Types::STRING, ['length' => 5, 'fixed' => true]);
258
        $table_dates->addColumn('d_mon', Types::SMALLINT);
259
        $table_dates->addColumn('d_year', Types::SMALLINT);
260
        $table_dates->addColumn('d_julianday1', Types::INTEGER);
261
        $table_dates->addColumn('d_julianday2', Types::INTEGER);
262
        $table_dates->addColumn('d_fact', Types::STRING, ['length' => 15, 'platformOptions' => ['collation' => 'ascii_bin']]);
263
        $table_dates->addColumn('d_gid', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
264
        $table_dates->addColumn('d_file', Types::INTEGER);
265
        $table_dates->addColumn('d_type', Types::STRING, ['length' => 13, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
266
        $table_dates->addIndex(['d_day']);
267
        $table_dates->addIndex(['d_month']);
268
        $table_dates->addIndex(['d_mon']);
269
        $table_dates->addIndex(['d_year']);
270
        $table_dates->addIndex(['d_julianday1']);
271
        $table_dates->addIndex(['d_julianday2']);
272
        $table_dates->addIndex(['d_gid']);
273
        $table_dates->addIndex(['d_file']);
274
        $table_dates->addIndex(['d_type']);
275
        $table_dates->addIndex(['d_fact', 'd_gid']);
276
277
        $table_default_resn = $schema->createTable($prefix . 'default_resn');
278
        $table_default_resn->addColumn('default_resn_id', Types::INTEGER, ['autoincrement' => true]);
279
        $table_default_resn->addColumn('gedcom_id', Types::INTEGER);
280
        $table_default_resn->addColumn('xref', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
281
        $table_default_resn->addColumn('tag_type', Types::STRING, ['length' => 15, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
282
        $table_default_resn->addColumn('resn', Types::STRING, ['length' => 12, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
283
        $table_default_resn->addColumn('comment', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
284
        $table_default_resn->addColumn('updated', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'precision' => 0]);
285
        $table_default_resn->setPrimaryKey(['default_resn_id']);
286
        $table_default_resn->addIndex(['gedcom_id', 'xref', 'tag_type']);
287
        $table_default_resn->addForeignKeyConstraint($table_gedcom, ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
288
289
        $table_families = $schema->createTable($prefix . 'families');
290
        $table_families->addColumn('f_id', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
291
        $table_families->addColumn('f_file', Types::INTEGER);
292
        $table_families->addColumn('f_husb', Types::STRING, ['length' => 20, 'notNull' => false, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
293
        $table_families->addColumn('f_wife', Types::STRING, ['length' => 20, 'notNull' => false, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
294
        $table_families->addColumn('f_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
295
        $table_families->addColumn('f_numchil', Types::INTEGER);
296
        $table_families->setPrimaryKey(['f_id', 'f_file']);
297
        $table_families->addUniqueIndex(['f_file', 'f_id']);
298
        $table_families->addUniqueIndex(['f_husb']);
299
        $table_families->addUniqueIndex(['f_wife']);
300
301
        $table_individuals = $schema->createTable($prefix . 'individuals');
302
        $table_individuals->addColumn('i_id', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
303
        $table_individuals->addColumn('i_file', Types::INTEGER);
304
        $table_individuals->addColumn('i_rin', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
305
        $table_individuals->addColumn('i_sex', Types::STRING, ['length' => 1, 'platformOptions' => ['collation' => 'ascii_bin']]);
306
        $table_individuals->addColumn('i_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
307
        $table_individuals->setPrimaryKey(['i_id', 'i_file']);
308
        $table_individuals->addUniqueIndex(['i_file', 'i_id']);
309
310
        $table_media = $schema->createTable($prefix . 'media');
311
        $table_media->addColumn('m_id', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
312
        $table_media->addColumn('m_file', Types::INTEGER);
313
        $table_media->addColumn('m_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
314
        $table_media->setPrimaryKey(['m_file', 'm_id']);
315
        $table_media->addUniqueIndex(['m_id', 'm_file']);
316
317
        $table_media_file = $schema->createTable($prefix . 'media_file');
318
        $table_media_file->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
319
        $table_media_file->addColumn('m_id', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
320
        $table_media_file->addColumn('m_file', Types::INTEGER);
321
        $table_media_file->addColumn('multimedia_file_refn', Types::STRING, ['length' => 246, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
322
        $table_media_file->addColumn('multimedia_format', Types::STRING, ['length' => 4, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
323
        $table_media_file->addColumn('source_media_type', Types::STRING, ['length' => 15, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
324
        $table_media_file->addColumn('descriptive_title', Types::STRING, ['length' => 248, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
325
        $table_media_file->setPrimaryKey(['id']);
326
        $table_media_file->addIndex(['m_id', 'm_file']);
327
        $table_media_file->addIndex(['m_file', 'm_id']);
328
        $table_media_file->addIndex(['m_file', 'multimedia_file_refn']);
329
        $table_media_file->addIndex(['m_file', 'multimedia_format']);
330
        $table_media_file->addIndex(['m_file', 'source_media_type']);
331
        $table_media_file->addIndex(['m_file', 'descriptive_title']);
332
333
        $table_other = $schema->createTable($prefix . 'other');
334
        $table_other->addColumn('o_id', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
335
        $table_other->addColumn('o_file', Types::INTEGER);
336
        $table_other->addColumn('o_type', Types::STRING, ['length' => 15, 'platformOptions' => ['collation' => 'ascii_bin']]);
337
        $table_other->addColumn('o_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
338
        $table_other->setPrimaryKey(['o_id', 'o_file']);
339
        $table_other->addUniqueIndex(['o_file', 'o_id']);
340
341
        $table_places = $schema->createTable($prefix . 'places');
342
        $table_places->addColumn('p_id', Types::INTEGER, ['autoincrement' => true]);
343
        $table_places->addColumn('p_place', Types::STRING, ['length' => 150]);
344
        $table_places->addColumn('p_parent_id', Types::INTEGER, ['notNull' => false]);
345
        $table_places->addColumn('p_file', Types::INTEGER);
346
        $table_places->addColumn('p_std_soundex', Types::TEXT, ['platformOptions' => ['collation' => 'ascii_bin']]);
347
        $table_places->addColumn('p_dm_soundex', Types::TEXT, ['platformOptions' => ['collation' => 'ascii_bin']]);
348
        $table_places->setPrimaryKey(['p_id']);
349
        $table_places->addUniqueIndex(['p_parent_id', 'p_file', 'p_place']);
350
        $table_places->addIndex(['p_file', 'p_place']);
351
352
        $table_placelinks = $schema->createTable($prefix . 'placelinks');
353
        $table_placelinks->addColumn('pl_p_id', Types::INTEGER);
354
        $table_placelinks->addColumn('pl_gid', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
355
        $table_placelinks->addColumn('pl_file', Types::INTEGER);
356
        $table_placelinks->setPrimaryKey(['pl_p_id', 'pl_gid', 'pl_file']);
357
        $table_placelinks->addIndex(['pl_p_id']);
358
        $table_placelinks->addIndex(['pl_gid']);
359
        $table_placelinks->addIndex(['pl_file']);
360
361
        $table_sources = $schema->createTable($prefix . 'session');
362
        $table_sources->addColumn('session_id', Types::STRING, ['length' => 32, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
363
        $table_sources->addColumn('session_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP']);
364
        $table_sources->addColumn('user_id', Types::INTEGER);
365
        $table_sources->addColumn('ip_address', Types::STRING, ['length' => 45, 'platformOptions' => ['collation' => 'ascii_bin']]);
366
        $table_sources->addColumn('session_data', Types::BLOB);
367
        $table_sources->setPrimaryKey(['session_id']);
368
        $table_sources->addIndex(['session_time']);
369
        $table_sources->addIndex(['user_id', 'ip_address']);
370
371
        $table_sources = $schema->createTable($prefix . 'sources');
372
        $table_sources->addColumn('s_id', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
373
        $table_sources->addColumn('s_file', Types::INTEGER);
374
        $table_sources->addColumn('s_name', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
375
        $table_sources->addColumn('s_gedcom', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
376
        $table_sources->setPrimaryKey(['s_id', 's_file']);
377
        $table_sources->addUniqueIndex(['s_file', 's_id']);
378
        $table_sources->addIndex(['s_name']);
379
380
        /*
381
        $site = $schema->createTable($prefix . 'site');
382
        $site->addColumn('uuid', Types::STRING, ['length' => 36, 'platformOptions' => ['collation' => 'ascii_bin']]);
383
        $site->addColumn('db_schema', Types::STRING, ['length' => 20, 'platformOptions' => ['collation' => 'ascii_bin']]);
384
        $site->addColumn('created_at', Types::TIME_MUTABLE);
385
        $site->addColumn('updated_at', Types::TIME_MUTABLE);
386
        $site->setPrimaryKey(['uuid']);
387
388
        $job = $schema->createTable($prefix . 'job');
389
        $job->addColumn('uuid', Types::STRING, ['length' => 36, 'platformOptions' => ['collation' => 'ascii_bin']]);
390
        $job->addColumn('failures', Types::INTEGER, ['default' => 0]);
391
        $job->addColumn('job', Types::STRING, ['length' => 255, 'platformOptions' => ['collation' => 'ascii_bin']]);
392
        $job->addColumn('parameters', Types::TEXT, ['platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
393
        $job->addColumn('error', Types::TEXT, ['notnull' => false, 'platformOptions' => ['collation' => 'utf8mb4_unicode_ci']]);
394
        $job->addColumn('created_at', Types::TIME_MUTABLE);
395
        $job->addColumn('updated_at', Types::TIME_MUTABLE);
396
        $job->setPrimaryKey(['uuid']);
397
398
        $job_dependency = $schema->createTable($prefix . 'job_dependency');
399
        $job_dependency->addColumn('uuid1', Types::STRING, ['length' => 36, 'platformOptions' => ['collation' => 'ascii_bin']]);
400
        $job_dependency->addColumn('uuid2', Types::STRING, ['length' => 36, 'platformOptions' => ['collation' => 'ascii_bin']]);
401
        $job_dependency->addUniqueIndex(['uuid1', 'uuid2']);
402
        $job_dependency->addUniqueIndex(['uuid2', 'uuid1']);
403
        $job_dependency->addForeignKeyConstraint($job, ['uuid1'], ['uuid'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
404
        $job_dependency->addForeignKeyConstraint($job, ['uuid2'], ['uuid'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
405
        */
406
407
        $comparator = $schema_manager->createComparator();
408
        $difference = $comparator->compareSchemas($current_schema, $schema);
409
        $queries    = $difference->toSaveSql($platform);
0 ignored issues
show
Unused Code introduced by
The assignment to $queries is dead and can be removed.
Loading history...
410
        $queries    = $difference->toSql($platform);
411
412
        foreach ($queries as $query) {
413
            if (str_contains($query, 'RENAME INDEX')) {
414
                continue;
415
            }
416
            echo '<p>' . $query . '</p>';
417
        }
418
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
419
    }
420
}
421