Passed
Push — dbal ( b6c9ce...9b470f )
by Greg
06:51
created

WebtreesSchema::tableLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 21
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2023 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\DB;
21
22
use Doctrine\DBAL\Schema\Column;
23
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Schema\ForeignKeyConstraint 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...
24
use Doctrine\DBAL\Schema\Index;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Schema\Index 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...
Bug introduced by
This use statement conflicts with another class in this namespace, Fisharebest\Webtrees\DB\Index. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
use Doctrine\DBAL\Schema\Schema;
26
use Doctrine\DBAL\Schema\Table;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Fisharebest\Webtrees\DB\Table. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
27
use Doctrine\DBAL\Types\AsciiStringType;
28
use Doctrine\DBAL\Types\DateTimeType;
29
use Doctrine\DBAL\Types\IntegerType;
30
use Doctrine\DBAL\Types\StringType;
31
use Doctrine\DBAL\Types\TextType;
32
use Fisharebest\Webtrees\DB;
33
use Illuminate\Database\DBAL\TimestampType;
34
use Illuminate\Support\Str;
35
36
/**
37
 * Definitions for the webtrees database.
38
 */
39
class WebtreesSchema
40
{
41
    /**
42
     * @return void
43
     */
44
    public function historicSchemaVersions(): void
45
    {
46
        switch ('webtrees_schema') {
47
            case 1: // webtrees 1.0.0 - 1.0.3
48
            case 2: // webtrees 1.0.4
49
            case 3:
50
            case 4: // webtrees 1.0.5
51
            case 5: // webtrees 1.0.6
52
            case 6:
53
            case 7:
54
            case 8:
55
            case 9: // webtrees 1.1.0 - 1.1.1
56
            case 10: // webtrees 1.1.2
57
            case 11: // webtrees 1.2.0
58
            case 12: // webtrees 1.2.1 - 1.2.3
59
            case 13:
60
            case 14:
61
            case 15: // webtrees 1.2.4 - 1.2.5
62
            case 16: // webtrees 1.2.7
63
            case 17:
64
            case 18: // webtrees 1.3.0
65
            case 19: // webtrees 1.3.1
66
            case 20: // webtrees 1.3.2
67
            case 21:
68
            case 22:
69
            case 23: // webtrees 1.4.0 - 1.4.1
70
            case 24:
71
            case 25: // webtrees 1.4.2 - 1.4.4, 1.5.0
72
            case 26: // webtrees 1.4.5 - 1.4.6
73
            case 27: // webtrees 1.5.1 - 1.6.0
74
            case 28:
75
            case 29: // webtrees 1.6.1 - 1.6.2
76
            case 30:
77
            case 31: // webtrees 1.7.0 - 1.7.1
78
            case 32: // webtrees 1.7.2
79
            case 33:
80
            case 34: // webtrees 1.7.3 - 1.7.4
81
            case 35:
82
            case 36: // webtrees 1.7.5 - 1.7.7
83
            case 37: // webtrees 1.7.8 - 2.0.0
84
            case 38:
85
            case 39:
86
            case 40: // webtrees 2.0.1 - 2.1.15
87
        }
88
    }
89
90
    // Options for columns
91
    private const AUTO_INCREMENT = ['autoincrement' => true];
92
    private const NULLABLE       = ['notnull' => false];
93
    private const DEFAULT_NOW    = ['default' => 'CURRENT_TIMESTAMP'];
94
95
    // Options for foreign key constraints.
96
    private const ON_DELETE_CASCADE  = ['onDelete' => 'CASCADE'];
97
    private const ON_DELETE_SET_NULL = ['onDelete' => 'SET NULL'];
98
    private const ON_UPDATE_CASCADE  = ['onUpdate' => 'CASCADE'];
99
100
    public static function tableBlock(): Table
101
    {
102
        return new Table(
103
            name: DB::prefix('block'),
104
            columns: [
105
                new Column(name: 'block_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
106
                new Column(name: 'gedcom_id', type: new IntegerType(), options: self::NULLABLE),
107
                new Column(name: 'user_id', type: new IntegerType(), options: self::NULLABLE),
108
                new Column(name: 'xref', type: new AsciiStringType(), options: ['length' => 20] + self::NULLABLE),
109
                new Column(name: 'location', type: new AsciiStringType(), options: ['length' => 4, 'fixed' => true] + self::NULLABLE),
110
                new Column(name: 'block_order', type: new IntegerType()),
111
                new Column(name: 'module_name', type: new AsciiStringType(), options: ['length' => 32]),
112
            ],
113
            indexes: [
114
                new Index(name: 'primary', columns: ['block_id'], isPrimary: true),
115
                new Index(name: DB::prefix('block_ix_gedcom_id'), columns: ['gedcom_id']),
116
                new Index(name: DB::prefix('block_ix_user_id'), columns: ['user_id']),
117
                new Index(name: DB::prefix('block_ix_module_name'), columns: ['module_name']),
118
            ],
119
            fkConstraints: [
120
                new ForeignKeyConstraint(
121
                    localColumnNames: ['gedcom_id'],
122
                    foreignTableName: DB::prefix('gedcom'),
123
                    foreignColumnNames: ['gedcom_id'],
124
                    name: DB::prefix('block_fk_gedcom'),
125
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
126
                ),
127
                new ForeignKeyConstraint(
128
                    localColumnNames: ['user_id'],
129
                    foreignTableName: DB::prefix('user'),
130
                    foreignColumnNames: ['user_id'],
131
                    name: DB::prefix('block_fk_user'),
132
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
133
                ),
134
                new ForeignKeyConstraint(
135
                    localColumnNames: ['module_name'],
136
                    foreignTableName: DB::prefix('module'),
137
                    foreignColumnNames: ['module_name'],
138
                    name: DB::prefix('block_fk_module'),
139
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
140
                ),
141
            ],
142
        );
143
    }
144
145
    public static function tableBlockSetting(): Table
146
    {
147
        return new Table(
148
            name: DB::prefix('block_setting'),
149
            columns: [
150
                new Column(name: 'block_id', type: new IntegerType(), options: []),
151
                new Column('setting_name', type: new AsciiStringType(), options: ['length' => 32]),
152
                new Column('setting_value', type: new TextType()),
153
            ],
154
            indexes: [
155
                new Index(name: 'primary', columns: ['block_id', 'setting_name'], isPrimary: true),
156
            ],
157
            fkConstraints: [
158
                new ForeignKeyConstraint(
159
                    localColumnNames: ['block_id'],
160
                    foreignTableName: DB::prefix('block'),
161
                    foreignColumnNames: ['block_id'],
162
                    name: DB::prefix('block_setting_fk_block'),
163
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
164
                ),
165
            ],
166
        );
167
    }
168
169
    public static function tableChange(): Table
170
    {
171
        return new Table(
172
            name: DB::prefix('change'),
173
            columns: [
174
                new Column(name: 'change_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
175
                new Column(name: 'change_time', type: new DateTimeType(), options: self::DEFAULT_NOW),
176
                new Column(name: 'status', type: new AsciiStringType(), options: ['length' => 8]),
177
                new Column(name: 'gedcom_id', type: new IntegerType()),
178
                new Column(name: 'xref', type: new AsciiStringType(), options: ['length' => 20]),
179
                new Column(name: 'old_gedcom', type: new TextType()),
180
                new Column(name: 'new_gedcom', type: new TextType()),
181
                new Column(name: 'user_id', type: new IntegerType()),
182
            ],
183
            indexes: [
184
                new Index(name: 'primary', columns: ['change_id'], isPrimary: true),
185
                new Index(name: DB::prefix('change_ix_gedcom_id'), columns: ['gedcom_id']),
186
                new Index(name: DB::prefix('change_ix_user_id'), columns: ['user_id']),
187
            ],
188
            fkConstraints: [
189
                new ForeignKeyConstraint(
190
                    localColumnNames: ['user_id'],
191
                    foreignTableName: DB::prefix('user'),
192
                    foreignColumnNames: ['user_id'],
193
                    name: DB::prefix('change_fk_user'),
194
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
195
                ),
196
                new ForeignKeyConstraint(
197
                    localColumnNames: ['gedcom_id'],
198
                    foreignTableName: DB::prefix('gedcom'),
199
                    foreignColumnNames: ['gedcom_id'],
200
                    name: DB::prefix('change_fk_gedcom'),
201
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
202
                ),
203
            ],
204
        );
205
    }
206
207
    public static function tableDates(): Table
208
    {
209
        return new Table(
210
            name: DB::prefix('dates'),
211
            columns: [
212
                new Column(name: 'd_day', type: new IntegerType()),
213
                new Column(name: 'd_month', type: new AsciiStringType(), options: ['length' => 5, 'fixed' => true]),
214
                new Column(name: 'd_mon', type: new IntegerType()),
215
                new Column(name: 'd_year', type: new IntegerType()),
216
                new Column(name: 'd_julianday1', type: new IntegerType()),
217
                new Column(name: 'd_julianday2', type: new IntegerType()),
218
                new Column(name: 'd_fact', type: new AsciiStringType(), options: ['length' => 15]),
219
                new Column(name: 'd_gid', type: new AsciiStringType(), options: ['length' => 20]),
220
                new Column(name: 'd_file', type: new IntegerType()),
221
                new Column(name: 'd_type', type: new AsciiStringType(), options: ['length' => 13]),
222
            ],
223
            indexes: [
224
                new Index(name: DB::prefix('dates_ix_d_day'), columns: ['d_day']),
225
                new Index(name: DB::prefix('dates_ix_d_month'), columns: ['d_month']),
226
                new Index(name: DB::prefix('dates_ix_d_mon'), columns: ['d_mon']),
227
                new Index(name: DB::prefix('dates_ix_d_year'), columns: ['d_year']),
228
                new Index(name: DB::prefix('dates_ix_d_julianday1'), columns: ['d_julianday1']),
229
                new Index(name: DB::prefix('dates_ix_d_julianday2'), columns: ['d_julianday2']),
230
                new Index(name: DB::prefix('dates_ix_d_gid'), columns: ['d_gid']),
231
                new Index(name: DB::prefix('dates_ix_d_file'), columns: ['d_file']),
232
                new Index(name: DB::prefix('dates_ix_d_type'), columns: ['d_type']),
233
                new Index(name: DB::prefix('dates_ix_d_fact_d_gid'), columns: ['d_fact', 'd_gid']),
234
            ],
235
            fkConstraints: [
236
                new ForeignKeyConstraint(
237
                    localColumnNames: ['d_file'],
238
                    foreignTableName: DB::prefix('gedcom'),
239
                    foreignColumnNames: ['gedcom_id'],
240
                    name: DB::prefix('dates_fk_gedcom'),
241
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
242
                ),
243
            ],
244
        );
245
    }
246
247
    public static function tableDefaultResn(): Table
248
    {
249
        return new Table(
250
            name: DB::prefix('default_resn'),
251
            columns: [
252
                new Column(name: 'default_resn_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
253
                new Column(name: 'gedcom_id', type: new IntegerType()),
254
                new Column(name: 'xref', type: new AsciiStringType(), options: ['length' => 20] + self::NULLABLE),
255
                new Column(name: 'tag_type', type: new AsciiStringType(), options: ['length' => 15] + self::NULLABLE),
256
                new Column(name: 'resn', type: new AsciiStringType(), options: ['length' => 12]),
257
            ],
258
            indexes: [
259
                new Index(name: 'primary', columns: ['default_resn_id'], isPrimary: true),
260
                new Index(name: DB::prefix('default_resn_ux_gedcom_id_xref_tag_type'), columns: ['gedcom_id', 'xref', 'tag_type'], isUnique: true),
261
            ],
262
            fkConstraints: [
263
                new ForeignKeyConstraint(
264
                    localColumnNames: ['gedcom_id'],
265
                    foreignTableName: DB::prefix('gedcom'),
266
                    foreignColumnNames: ['gedcom_id'],
267
                    name: DB::prefix('default_resn_fk_gedcom'),
268
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
269
                ),
270
            ],
271
        );
272
    }
273
274
    public static function tableFamilies(): Table
275
    {
276
        return new Table(
277
            name: DB::prefix('families'),
278
            columns: [
279
                new Column(name: 'f_id', type: new AsciiStringType(), options: ['length' => 20]),
280
                new Column(name: 'f_file', type: new IntegerType()),
281
                new Column(name: 'f_husb', type: new AsciiStringType(), options: ['length' => 20] + self::NULLABLE),
282
                new Column(name: 'f_wife', type: new AsciiStringType(), options: ['length' => 20] + self::NULLABLE),
283
                new Column(name: 'f_gedcom', type: new TextType()),
284
                new Column(name: 'f_numchil', type: new IntegerType()),
285
            ],
286
            indexes: [
287
                new Index(name: 'primary', columns: ['f_file', 'f_id'], isPrimary: true),
288
                new Index(name: DB::prefix('families_ux_f_id_f_file'), columns: ['f_id', 'f_file'], isUnique: true),
289
                new Index(name: DB::prefix('families_ix_f_husb'), columns: ['f_file', 'f_husb']),
290
                new Index(name: DB::prefix('families_ix_f_wife'), columns: ['f_file', 'f_wife']),
291
                new Index(name: DB::prefix('families_ix_f_file_f_numchil'), columns: ['f_file', 'f_numchil']),
292
            ],
293
            fkConstraints: [
294
                new ForeignKeyConstraint(
295
                    localColumnNames: ['f_file'],
296
                    foreignTableName: DB::prefix('gedcom'),
297
                    foreignColumnNames: ['gedcom_id'],
298
                    name: DB::prefix('families_fk_gedcom'),
299
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
300
                ),
301
            ],
302
        );
303
    }
304
305
    public static function tableFavorite(): Table
306
    {
307
        return new Table(
308
            name: DB::prefix('favorite'),
309
            columns: [
310
                new Column(name: 'favorite_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
311
                new Column(name: 'user_id', type: new IntegerType()),
312
                new Column(name: 'gedcom_id', type: new IntegerType()),
313
                new Column(name: 'xref', type: new AsciiStringType(), options: ['length' => 20] + self::NULLABLE),
314
                new Column(name: 'favorite_type', type: new AsciiStringType(), options: ['length' => 4, 'fixed' => true]),
315
                new Column(name: 'url', type: new StringType(), options: ['length' => 255] + self::NULLABLE),
316
                new Column(name: 'title', type: new StringType(), options: ['length' => 255] + self::NULLABLE),
317
                new Column(name: 'note', type: new StringType(), options: ['length' => 1000] + self::NULLABLE),
318
            ],
319
            indexes: [
320
                new Index(name: 'primary', columns: ['favorite_id'], isPrimary: true),
321
                new Index(name: DB::prefix('favorite_ix_gedcom_id'), columns: ['gedcom_id']),
322
                new Index(name: DB::prefix('favorite_ix_user_id'), columns: ['user_id']),
323
            ],
324
            fkConstraints: [
325
                new ForeignKeyConstraint(
326
                    localColumnNames: ['user_id'],
327
                    foreignTableName: DB::prefix('user'),
328
                    foreignColumnNames: ['user_id'],
329
                    name: DB::prefix('favorite_fk_user'),
330
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
331
                ),
332
                new ForeignKeyConstraint(
333
                    localColumnNames: ['gedcom_id'],
334
                    foreignTableName: DB::prefix('gedcom'),
335
                    foreignColumnNames: ['gedcom_id'],
336
                    name: DB::prefix('favorite_fk_gedcom'),
337
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
338
                ),
339
            ],
340
        );
341
    }
342
343
    public static function tableGedcom(): Table
344
    {
345
        return new Table(
346
            name: DB::prefix('gedcom'),
347
            columns: [
348
                new Column(name: 'gedcom_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
349
                new Column(name: 'gedcom_name', type: new StringType(), options: ['length' => 255]),
350
                new Column(name: 'sort_order', type: new IntegerType(), options: ['default' => 0])
351
            ],
352
            indexes: [
353
                new Index(name: 'primary', columns: ['gedcom_id'], isPrimary: true),
354
                new Index(name: DB::prefix('gedcom_ux_gedcom_name'), columns: ['gedcom_name'], isUnique: true),
355
                new Index(name: DB::prefix('gedcom_ix_sort_order'), columns: ['sort_order']),
356
            ],
357
            fkConstraints: [
358
            ],
359
        );
360
    }
361
362
    public static function tableGedcomChunk(): Table
363
    {
364
        return new Table(
365
            name: DB::prefix('gedcom_chunk'),
366
            columns: [
367
                new Column(name: 'gedcom_chunk_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
368
                new Column(name: 'gedcom_id', type: new IntegerType()),
369
                new Column(name: 'chunk_data', type: new TextType()),
370
                new Column(name: 'imported', type: new IntegerType(), options: ['default' => 0]),
371
            ],
372
            indexes: [
373
                new Index(name: 'primary', columns: ['gedcom_chunk_id'], isPrimary: true),
374
                new Index(name: DB::prefix('gedcom_chunk_ix_gedcom_id_imported'), columns: ['gedcom_id', 'imported']),
375
            ],
376
            fkConstraints: [
377
                new ForeignKeyConstraint(
378
                    localColumnNames: ['gedcom_id'],
379
                    foreignTableName: DB::prefix('gedcom'),
380
                    foreignColumnNames: ['gedcom_id'],
381
                    name: DB::prefix('gedcom_chunk_fk_gedcom'),
382
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
383
                ),
384
            ],
385
        );
386
    }
387
388
    public static function tableGedcomSetting(): Table
389
    {
390
        return new Table(
391
            name: DB::prefix('gedcom_setting'),
392
            columns: [
393
                new Column('gedcom_id', new IntegerType()),
394
                new Column('setting_name', new AsciiStringType(), options: ['length' => 32]),
395
                new Column('setting_value', new StringType(), options: ['length' =>255]),
396
            ],
397
            indexes: [
398
                new Index(name: 'primary', columns: ['gedcom_id', 'setting_name'], isPrimary: true),
399
            ],
400
            fkConstraints: [
401
                new ForeignKeyConstraint(
402
                    localColumnNames: ['gedcom_id'],
403
                    foreignTableName: DB::prefix('gedcom'),
404
                    foreignColumnNames: ['gedcom_id'],
405
                    name: DB::prefix('gedcom_setting_fk_gedcom'),
406
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
407
                ),
408
            ],
409
        );
410
    }
411
412
    public static function tableHitCounter(): Table
413
    {
414
        return new Table(
415
            name: DB::prefix('hit_counter'),
416
            columns: [
417
                new Column('gedcom_id', new IntegerType()),
418
                new Column('page_name', new AsciiStringType(), options: ['length' => 32]),
419
                new Column('page_parameter', new AsciiStringType(), options: ['length' => 32]),
420
                new Column('page_count', new IntegerType()),
421
            ],
422
            indexes: [
423
                new Index(name: 'primary', columns: ['gedcom_id', 'page_name', 'page_parameter'], isPrimary: true),
424
            ],
425
            fkConstraints: [
426
                new ForeignKeyConstraint(
427
                    localColumnNames: ['gedcom_id'],
428
                    foreignTableName: DB::prefix('gedcom'),
429
                    foreignColumnNames: ['gedcom_id'],
430
                    name: DB::prefix('hit_counter_fk_gedcom'),
431
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
432
                ),
433
            ],
434
        );
435
    }
436
437
    public static function tableIndividuals(): Table
438
    {
439
        return new Table(
440
            name: DB::prefix('individuals'),
441
            columns: [
442
                new Column(name: 'i_id', type: new AsciiStringType(), options: ['length' => 20]),
443
                new Column(name: 'i_file', type: new IntegerType()),
444
                new Column(name: 'i_rin', type: new AsciiStringType(), options: ['length' => 20]),
445
                new Column(name: 'i_sex', type: new AsciiStringType(), options: ['length' => 1, 'fixed' => true]),
446
                new Column(name: 'i_gedcom', type: new TextType()),
447
            ],
448
            indexes: [
449
                new Index(name: 'primary', columns: ['i_id', 'i_file'], isPrimary: true),
450
                new Index(name: DB::prefix('individuals_ux_i_file_i_id'), columns: ['i_file', 'i_id'], isUnique: true),
451
            ],
452
            fkConstraints: [
453
                new ForeignKeyConstraint(
454
                    localColumnNames: ['i_file'],
455
                    foreignTableName: DB::prefix('gedcom'),
456
                    foreignColumnNames: ['gedcom_id'],
457
                    name: DB::prefix('individuals_fk_gedcom'),
458
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
459
                ),
460
            ],
461
        );
462
    }
463
464
    public static function tableLink(): Table
465
    {
466
        return new Table(
467
            name: DB::prefix('link'),
468
            columns: [
469
                new Column(name: 'l_file', type: new IntegerType()),
470
                new Column(name: 'l_from', type: new AsciiStringType(), options: ['length' => 20]),
471
                new Column(name: 'l_type', type: new AsciiStringType(), options: ['length' => 15]),
472
                new Column(name: 'l_to', type: new AsciiStringType(), options: ['length' => 20]),
473
            ],
474
            indexes: [
475
                new Index(name: 'primary', columns: ['l_from', 'l_file', 'l_type', 'l_to'], isPrimary: true),
476
                new Index(name: DB::prefix('individuals_ux_l_to_l_file_l_type_l_from'), columns: ['l_to', 'l_file', 'l_type', 'l_from'], isUnique: true),
477
            ],
478
            fkConstraints: [
479
                new ForeignKeyConstraint(
480
                    localColumnNames: ['l_file'],
481
                    foreignTableName: DB::prefix('gedcom'),
482
                    foreignColumnNames: ['gedcom_id'],
483
                    name: DB::prefix('individuals_fk_gedcom'),
484
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
485
                ),
486
            ],
487
        );
488
    }
489
490
    public static function tableLog(): Table
491
    {
492
        return new Table(
493
            name: DB::prefix('log'),
494
            columns: [
495
                new Column(name: 'log_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
496
                new Column(name: 'log_time', type: new TimestampType(), options: self::DEFAULT_NOW),
497
                new Column(name: 'log_type', type: new AsciiStringType(), options: ['length' => 6]),
498
                new Column(name: 'log_message', type: new TextType()),
499
                new Column(name: 'ip_address', type: new AsciiStringType(), options: ['length' => 45]),
500
                new Column(name: 'user_id', type: new IntegerType(), options: self::NULLABLE),
501
                new Column(name: 'gedcom_id', type: new IntegerType(), options: self::NULLABLE),
502
            ],
503
            indexes: [
504
                new Index(name: 'primary', columns: ['log_id'], isPrimary: true),
505
                new Index(name: DB::prefix('log_ix_gedcom_id'), columns: ['gedcom_id']),
506
                new Index(name: DB::prefix('log_ix_user_id'), columns: ['user_id']),
507
                new Index(name: DB::prefix('log_ix_log_time'), columns: ['log_time']),
508
                new Index(name: DB::prefix('log_ix_log_type'), columns: ['log_type']),
509
                new Index(name: DB::prefix('log_ix_ip_address'), columns: ['ip_address']),
510
            ],
511
            fkConstraints: [
512
                new ForeignKeyConstraint(
513
                    localColumnNames: ['user_id'],
514
                    foreignTableName: DB::prefix('user'),
515
                    foreignColumnNames: ['user_id'],
516
                    name: DB::prefix('log_fk_user'),
517
                    options: self::ON_DELETE_SET_NULL + self::ON_UPDATE_CASCADE,
518
                ),
519
                new ForeignKeyConstraint(
520
                    localColumnNames: ['gedcom_id'],
521
                    foreignTableName: DB::prefix('gedcom'),
522
                    foreignColumnNames: ['gedcom_id'],
523
                    name: DB::prefix('log_fk_gedcom'),
524
                    options: self::ON_DELETE_SET_NULL + self::ON_UPDATE_CASCADE,
525
                ),
526
            ],
527
        );
528
    }
529
530
    public static function tableMedia(): Table
531
    {
532
        return new Table(
533
            name: DB::prefix('media'),
534
            columns: [
535
                new Column(name: 'm_id', type: new AsciiStringType(), options: ['length' => 20]),
536
                new Column(name: 'm_file', type: new IntegerType()),
537
                new Column(name: 'm_gedcom', type: new TextType()),
538
            ],
539
            indexes: [
540
                new Index(name: 'primary', columns: ['m_file', 'm_id'], isPrimary: true),
541
                new Index(name: DB::prefix('media_ux_m_file_m_id'), columns: ['m_id', 'm_file'], isUnique: true),
542
            ],
543
            fkConstraints: [
544
                new ForeignKeyConstraint(
545
                    localColumnNames: ['m_file'],
546
                    foreignTableName: DB::prefix('gedcom'),
547
                    foreignColumnNames: ['gedcom_id'],
548
                    name: DB::prefix('individuals_fk_gedcom'),
549
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
550
                ),
551
            ],
552
        );
553
    }
554
555
    public static function tableMediaFile(): Table
556
    {
557
        return new Table(
558
            name: DB::prefix('media_file'),
559
            columns: [
560
                new Column(name: 'id', type: new IntegerType(), options: self::AUTO_INCREMENT),
561
                new Column(name: 'm_id', type: new AsciiStringType(), options: ['length' => 20]),
562
                new Column(name: 'm_file', type: new IntegerType()),
563
                new Column(name: 'multimedia_file_refn', type: new StringType(), options: ['length' => 248]),
564
                new Column(name: 'multimedia_format', type: new StringType(), options: ['length' => 4]),
565
                new Column(name: 'source_media_type', type: new StringType(), options: ['length' => 15]),
566
                new Column(name: 'descriptive_title', type: new StringType(), options: ['length' => 248]),
567
            ],
568
            indexes: [
569
                new Index(name: 'primary', columns: ['id'], isPrimary: true),
570
                new Index(name: DB::prefix('media_ix_m_file_m_id'), columns: ['m_id', 'm_file']),
571
                new Index(name: DB::prefix('media_ix_m_id_m_file'), columns: ['m_file', 'm_id']),
572
                new Index(name: DB::prefix('media_ix_m_id_multimedia_file_refn'), columns: ['m_file', 'multimedia_file_refn']),
573
                new Index(name: DB::prefix('media_ix_m_id_multimedia_format'), columns: ['m_file', 'multimedia_format']),
574
                new Index(name: DB::prefix('media_ix_m_id_source_media_type'), columns: ['m_file', 'source_media_type']),
575
                new Index(name: DB::prefix('media_ix_m_id_descriptive_title'), columns: ['m_file', 'descriptive_title']),
576
            ],
577
            fkConstraints: [
578
            ],
579
        );
580
    }
581
582
    public static function tableMessage(): Table
583
    {
584
        return new Table(
585
            name: DB::prefix('message'),
586
            columns: [
587
                new Column(name: 'message_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
588
                new Column(name: 'sender', type: new StringType(), options: ['length' => 64]),
589
                new Column(name: 'ip_address', type: new StringType(), options: ['length' => 45]),
590
                new Column(name: 'user_id', type: new IntegerType()),
591
                new Column(name: 'subject', type: new StringType(), options: ['length' => 255]),
592
                new Column(name: 'body', type: new TextType()),
593
                new Column(name: 'created', type: new TimestampType(), options: self::DEFAULT_NOW),
594
            ],
595
            indexes: [
596
                new Index(name: 'primary', columns: ['message_id'], isPrimary: true),
597
                new Index(name: DB::prefix('message_user_id'), columns: ['user_id']),
598
            ],
599
            fkConstraints: [
600
                new ForeignKeyConstraint(
601
                    localColumnNames: ['user_id'],
602
                    foreignTableName: DB::prefix('user'),
603
                    foreignColumnNames: ['user_id'],
604
                    name: DB::prefix('log_fk_user'),
605
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
606
                ),
607
            ],
608
        );
609
    }
610
611
    public static function tableModule(): Table
612
    {
613
        return new Table(
614
            name: DB::prefix('module'),
615
            columns: [
616
                new Column(name: 'module', type: new AsciiStringType(), options: ['length' => 32]),
617
                new Column(name: 'status', type: new AsciiStringType(), options: ['length' => 8, 'default' => 'enabled']),
618
                new column(name: 'tab_order', type: new IntegerType(), options: ['default' => 0]),
619
                new column(name: 'menu_order', type: new IntegerType(), options: ['default' => 0]),
620
                new column(name: 'sidebar_order', type: new IntegerType(), options: ['default' => 0]),
621
                new column(name: 'footer_order', type: new IntegerType(), options: ['default' => 0]),
622
            ],
623
            indexes: [
624
                new Index('primary', columns: ['module_name'], isPrimary: true),
625
            ],
626
        );
627
    }
628
629
    public static function tableModulePrivacy(): Table
630
    {
631
        return new Table(
632
            name: DB::prefix('module_privacy'),
633
            columns: [
634
                new Column(name: 'id', type: new IntegerType(), options: self::AUTO_INCREMENT),
635
                new Column(name: 'module_name', type: new AsciiStringType(), options: ['length' => 32]),
636
                new Column(name: 'gedcom_id', type: new IntegerType()),
637
                new Column(name: 'interface', type: new AsciiStringType(), options: ['length' => 255]),
638
                new Column(name: 'access_level', type: new IntegerType()),
639
            ],
640
            indexes: [
641
                new Index(name: 'primary', columns: ['id']),
642
                new Index(name: DB::prefix('module_privacy_ix_gedcom_id'), columns: ['gedcom_id']),
643
                new Index(name: DB::prefix('module_privacy_ix_module_name'), columns: ['module_name']),
644
            ],
645
            fkConstraints: [
646
                new ForeignKeyConstraint(
647
                    localColumnNames: ['gedcom_id'],
648
                    foreignTableName: DB::prefix('gedcom'),
649
                    foreignColumnNames: ['gedcom_id'],
650
                    name: DB::prefix('module_privacy_fk_gedcom'),
651
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
652
                ),
653
                new ForeignKeyConstraint(
654
                    localColumnNames: ['module_name'],
655
                    foreignTableName: DB::prefix('module'),
656
                    foreignColumnNames: ['module_name'],
657
                    name: DB::prefix('module_privacy_fk_module'),
658
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
659
                ),
660
            ],
661
        );
662
    }
663
664
    public static function tableModuleSetting(): Table
665
    {
666
        return new Table(
667
            name: DB::prefix('module_setting'),
668
            columns: [
669
                new Column(name: 'module_name', type: new AsciiStringType(), options: ['length' => 32]),
670
                new Column(name: 'setting_name', type: new AsciiStringType(), options: ['length' => 32]),
671
                new Column(name: 'setting_value', type: new TextType()),
672
            ],
673
            indexes: [
674
                new Index(name: DB::prefix('module_setting_ix_module_name'), columns: ['module_name']),
675
            ],
676
            fkConstraints: [
677
                new ForeignKeyConstraint(
678
                    localColumnNames: ['module_name'],
679
                    foreignTableName: DB::prefix('module'),
680
                    foreignColumnNames: ['module_name'],
681
                    name: DB::prefix('module_privacy_fk_module'),
682
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
683
                ),
684
            ],
685
        );
686
    }
687
688
    public static function tableName(): Table
689
    {
690
        return new Table(
691
            name: DB::prefix('name'),
692
            columns: [
693
                new Column(name: 'n_file', type: new IntegerType()),
694
                new Column(name: 'n_id', type: new AsciiStringType(), options: ['length' => 20]),
695
                new Column(name: 'n_num', type: new IntegerType()),
696
                new Column(name: 'n_type', type: new AsciiStringType(), options: ['length' => 15, 'default' => '']),
697
                new Column(name: 'n_sort', type: new StringType(), options: ['length' => 255, 'default' => '']),
698
                new Column(name: 'n_full', type: new StringType(), options: ['length' => 255, 'default' => '']),
699
                new Column(name: 'n_surname', type: new StringType(), options: ['length' => 255, 'default' => '']),
700
                new Column(name: 'n_surn', type: new StringType(), options: ['length' => 255, 'default' => '']),
701
                new Column(name: 'n_givn', type: new StringType(), options: ['length' => 255, 'default' => '']),
702
                new Column(name: 'n_soundex_givn_std', type: new AsciiStringType(), options: ['length' => 255, 'default' => '']),
703
                new Column(name: 'n_soundex_surn_std', type: new AsciiStringType(), options: ['length' => 255, 'default' => '']),
704
                new Column(name: 'n_soundex_givn_dm', type: new AsciiStringType(), options: ['length' => 255, 'default' => '']),
705
                new Column(name: 'n_soundex_surn_dm', type: new AsciiStringType(), options: ['length' => 255, 'default' => '']),
706
            ],
707
            indexes: [
708
                new Index(name: 'primary', columns: ['n_id', 'n_file', 'n_num'], isPrimary: true),
709
                new Index(name: DB::prefix('name_ix_n_full_n_id_n_file'), columns: ['n_full', 'n_id', 'n_file']),
710
                new Index(name: DB::prefix('name_ix_n_givn_n_file_n_type_n_id'), columns: ['n_givn', 'n_file', 'n_type', 'n_id']),
711
                new Index(name: DB::prefix('name_ix_n_surn_n_file_n_type_n_id'), columns: ['n_surn', 'n_file', 'n_type', 'n_id']),
712
            ],
713
            fkConstraints: [
714
            ],
715
        );
716
    }
717
718
    public static function tableNews(): Table
719
    {
720
        return new Table(
721
            name: DB::prefix('news'),
722
            columns: [
723
                new Column(name: 'news_id', type: new IntegerType(), options: self::AUTO_INCREMENT),
724
                new Column(name: 'user_id', type: new IntegerType(), options: self::NULLABLE),
725
                new Column(name: 'gedcom_id', type: new IntegerType(), options: self::NULLABLE),
726
                new Column(name: 'subject', type: new StringType(), options: ['length' => 255]),
727
                new Column(name: 'body', type: new TextType()),
728
                new Column(name: 'updated', type: new TimestampType(), options: self::DEFAULT_NOW),
729
            ],
730
            indexes: [
731
                new Index(name: 'primary', columns: ['news_id'], isPrimary: true),
732
            ],
733
            fkConstraints: [
734
                new ForeignKeyConstraint(
735
                    localColumnNames: ['user_id'],
736
                    foreignTableName: DB::prefix('user'),
737
                    foreignColumnNames: ['user_id'],
738
                    name: DB::prefix('news_fk_user'),
739
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
740
                ),
741
                new ForeignKeyConstraint(
742
                    localColumnNames: ['gedcom_id'],
743
                    foreignTableName: DB::prefix('gedcom'),
744
                    foreignColumnNames: ['gedcom_id'],
745
                    name: DB::prefix('news_fk_gedcom'),
746
                    options: self::ON_DELETE_CASCADE + self::ON_UPDATE_CASCADE,
747
                ),
748
            ],
749
        );
750
    }
751
752
    public static function tableOther(): Table
753
    {
754
        return new Table(
755
            name: DB::prefix('other'),
756
            columns: [
757
            ],
758
            indexes: [
759
            ],
760
            fkConstraints: [
761
            ],
762
        );
763
    }
764
765
    public static function tablePlaceLocation(): Table
766
    {
767
        return new Table(
768
            name: DB::prefix('place_location'),
769
            columns: [
770
            ],
771
            indexes: [
772
            ],
773
            fkConstraints: [
774
            ],
775
        );
776
    }
777
778
    public static function tablePlaceLinks(): Table
779
    {
780
        return new Table(
781
            name: DB::prefix('placelinks'),
782
            columns: [
783
            ],
784
            indexes: [
785
            ],
786
            fkConstraints: [
787
            ],
788
        );
789
    }
790
791
    public static function tablePlaces(): Table
792
    {
793
        return new Table(
794
            name: DB::prefix('places'),
795
            columns: [
796
            ],
797
            indexes: [
798
            ],
799
            fkConstraints: [
800
            ],
801
        );
802
    }
803
804
    public static function tableSession(): Table
805
    {
806
        return new Table(
807
            name: DB::prefix('session'),
808
            columns: [
809
            ],
810
            indexes: [
811
            ],
812
            fkConstraints: [
813
            ],
814
        );
815
    }
816
817
    public static function tableSiteSetting(): Table
818
    {
819
        return new Table(
820
            name: DB::prefix('site_setting'),
821
            columns: [
822
            ],
823
            indexes: [
824
            ],
825
            fkConstraints: [
826
            ],
827
        );
828
    }
829
830
    public static function tableSources(): Table
831
    {
832
        return new Table(
833
            name: DB::prefix('sources'),
834
            columns: [
835
            ],
836
            indexes: [
837
            ],
838
            fkConstraints: [
839
            ],
840
        );
841
    }
842
843
    public static function tableUser(): Table
844
    {
845
        return new Table(
846
            name: DB::prefix('user'),
847
            columns: [
848
            ],
849
            indexes: [
850
            ],
851
            fkConstraints: [
852
            ],
853
        );
854
    }
855
856
    public static function tableUserGedcomSetting(): Table
857
    {
858
        return new Table(
859
            name: DB::prefix('user_gedcom_setting'),
860
            columns: [
861
            ],
862
            indexes: [
863
            ],
864
            fkConstraints: [
865
            ],
866
        );
867
    }
868
869
    public static function tableUserSetting(): Table
870
    {
871
        return new Table(
872
            name: DB::prefix('user_setting'),
873
            columns: [
874
            ],
875
            indexes: [
876
            ],
877
            fkConstraints: [
878
            ],
879
        );
880
    }
881
882
    public static function schema(): Schema
883
    {
884
        return new Schema(
885
            tables: [
886
                self::tableBlock(),
887
                self::tableBlockSetting(),
888
                self::tableChange(),
889
                self::tableDates(),
890
                self::tableDefaultResn(),
891
                self::tableFamilies(),
892
                self::tableFavorite(),
893
                self::tableGedcom(),
894
                self::tableGedcomChunk(),
895
                self::tableGedcomSetting(),
896
                self::tableHitCounter(),
897
                self::tableIndividuals(),
898
                self::tableLink(),
899
                self::tableLog(),
900
                self::tableMedia(),
901
                self::tableMediaFile(),
902
                self::tableMessage(),
903
                self::tableModule(),
904
                self::tableModulePrivacy(),
905
                self::tableModuleSetting(),
906
                self::tableName(),
907
                self::tableNews(),
908
                self::tableOther(),
909
                self::tablePlaceLocation(),
910
                self::tablePlaceLinks(),
911
                self::tablePlaces(),
912
                self::tableSession(),
913
                self::tableSiteSetting(),
914
                self::tableSources(),
915
                self::tableUser(),
916
                self::tableUserGedcomSetting(),
917
                self::tableUserSetting(),
918
            ],
919
        );
920
    }
921
}
922