|
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\DB; |
|
21
|
|
|
|
|
22
|
|
|
use Exception; |
|
23
|
|
|
use Fisharebest\Webtrees\DB\Schema\ReferentialAction; |
|
24
|
|
|
use Fisharebest\Webtrees\DB\Schema\Schema; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Definitions for the webtrees database. |
|
28
|
|
|
*/ |
|
29
|
|
|
class WebtreesSchema |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public function foo(): void |
|
35
|
|
|
{ |
|
36
|
|
|
switch ('webtrees_schema') { |
|
37
|
|
|
case 1: // webtrees 1.0.0 - 1.0.3 |
|
38
|
|
|
case 2: // webtrees 1.0.4 |
|
39
|
|
|
case 3: |
|
40
|
|
|
case 4: // webtrees 1.0.5 |
|
41
|
|
|
case 5: // webtrees 1.0.6 |
|
42
|
|
|
case 6: |
|
43
|
|
|
case 7: |
|
44
|
|
|
case 8: |
|
45
|
|
|
case 9: // webtrees 1.1.0 - 1.1.1 |
|
46
|
|
|
case 10: // webtrees 1.1.2 |
|
47
|
|
|
case 11: // webtrees 1.2.0 |
|
48
|
|
|
case 12: // webtrees 1.2.1 - 1.2.3 |
|
49
|
|
|
case 13: |
|
50
|
|
|
case 14: |
|
51
|
|
|
case 15: // webtrees 1.2.4 - 1.2.5 |
|
52
|
|
|
case 16: // webtrees 1.2.7 |
|
53
|
|
|
case 17: |
|
54
|
|
|
case 18: // webtrees 1.3.0 |
|
55
|
|
|
case 19: // webtrees 1.3.1 |
|
56
|
|
|
case 20: // webtrees 1.3.2 |
|
57
|
|
|
case 21: |
|
58
|
|
|
case 22: |
|
59
|
|
|
case 23: // webtrees 1.4.0 - 1.4.1 |
|
60
|
|
|
case 24: |
|
61
|
|
|
case 25: // webtrees 1.4.2 - 1.4.4, 1.5.0 |
|
62
|
|
|
case 26: // webtrees 1.4.5 - 1.4.6 |
|
63
|
|
|
case 27: // webtrees 1.5.1 - 1.6.0 |
|
64
|
|
|
case 28: |
|
65
|
|
|
case 29: // webtrees 1.6.1 - 1.6.2 |
|
66
|
|
|
case 30: |
|
67
|
|
|
case 31: // webtrees 1.7.0 - 1.7.1 |
|
68
|
|
|
case 32: // webtrees 1.7.2 |
|
69
|
|
|
case 33: |
|
70
|
|
|
case 34: // webtrees 1.7.3 - 1.7.4 |
|
71
|
|
|
case 35: |
|
72
|
|
|
case 36: // webtrees 1.7.5 - 1.7.7 |
|
73
|
|
|
case 37: // webtrees 1.7.8 - 2.0.0 |
|
74
|
|
|
case 38: |
|
75
|
|
|
case 39: |
|
76
|
|
|
case 40: // webtrees 2.0.1 - 2.1.15 |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param Connection $connection |
|
82
|
|
|
* |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function migrate(Connection $connection): Schema |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
$gedcom = Schema::table('gedcom', [ |
|
88
|
|
|
Schema::integer('gedcom_id')->autoIncrement(), |
|
89
|
|
|
Schema::nChar('gedcom_name', 255), |
|
90
|
|
|
Schema::integer('sort_order')->default(0), |
|
91
|
|
|
Schema::primaryKey(['gedcom_id']), |
|
92
|
|
|
Schema::uniqueIndex(['gedcom_name']), |
|
93
|
|
|
Schema::index(['sort_order']), |
|
94
|
|
|
]); |
|
95
|
|
|
|
|
96
|
|
|
$user = Schema::table('user', [ |
|
97
|
|
|
Schema::integer('user_id')->autoIncrement(), |
|
98
|
|
|
Schema::nVarchar('user_name', 32), |
|
99
|
|
|
Schema::nVarchar('real_name', 64), |
|
100
|
|
|
Schema::nVarchar('email', 64), |
|
101
|
|
|
Schema::nVarchar('password', 128), |
|
102
|
|
|
Schema::primaryKey(['user_id']), |
|
103
|
|
|
Schema::uniqueIndex(['user_name']), |
|
104
|
|
|
Schema::uniqueIndex(['email']), |
|
105
|
|
|
]); |
|
106
|
|
|
|
|
107
|
|
|
$module = Schema::table('module', [ |
|
108
|
|
|
Schema::varchar('module_name', 32), |
|
109
|
|
|
Schema::varchar('status', 8), |
|
110
|
|
|
Schema::integer('tab_order')->nullable(), |
|
111
|
|
|
Schema::integer('menu_order')->nullable(), |
|
112
|
|
|
Schema::integer('sidebar_order')->nullable(), |
|
113
|
|
|
Schema::integer('footer_order')->nullable(), |
|
114
|
|
|
Schema::primaryKey(['module_name']), |
|
115
|
|
|
]); |
|
116
|
|
|
|
|
117
|
|
|
$block = Schema::table('block', [ |
|
118
|
|
|
Schema::integer('block_id')->autoIncrement(), |
|
119
|
|
|
Schema::integer('gedcom_id')->nullable(), |
|
120
|
|
|
Schema::integer('user_id')->nullable(), |
|
121
|
|
|
Schema::varchar('location', 20)->nullable(), |
|
122
|
|
|
Schema::integer('block_order'), |
|
123
|
|
|
Schema::varchar('module_name', 32), |
|
124
|
|
|
Schema::primaryKey(['block_id']), |
|
125
|
|
|
Schema::foreignKey(['gedcom_id'], 'gedcom', ['gedcom_id'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::CASCADE), |
|
126
|
|
|
Schema::foreignKey(['user_id'], 'user', ['user_id'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::CASCADE), |
|
127
|
|
|
Schema::foreignKey(['module_name'], 'module', ['module_name'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::CASCADE), |
|
128
|
|
|
]); |
|
129
|
|
|
|
|
130
|
|
|
$block_setting = Schema::table('block_setting', [ |
|
131
|
|
|
Schema::integer('block_id')->autoIncrement(), |
|
132
|
|
|
Schema::varchar('setting_name', 32), |
|
133
|
|
|
Schema::text('setting_value'), |
|
134
|
|
|
Schema::primaryKey(['block_id', 'setting_name']), |
|
135
|
|
|
Schema::foreignKey(['block_id'], 'block', ['block_id'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::CASCADE), |
|
136
|
|
|
]); |
|
137
|
|
|
|
|
138
|
|
|
$change = Schema::table('change', [ |
|
139
|
|
|
Schema::integer('change_id')->autoIncrement(), |
|
140
|
|
|
Schema::timestamp('change_time')->default(new Expression('CURRENT_TIMESTAMP')), |
|
141
|
|
|
Schema::varchar('status', 8)->default('pending'), |
|
142
|
|
|
Schema::integer('gedcom_id'), |
|
143
|
|
|
Schema::varchar('xref', 20), |
|
144
|
|
|
Schema::text('old_gedcom'), |
|
145
|
|
|
Schema::text('new_gedcom'), |
|
146
|
|
|
Schema::integer('user_id')->nullable(), |
|
147
|
|
|
Schema::primaryKey(['change_id']), |
|
148
|
|
|
Schema::index(['gedcom_id', 'status', 'xref']), |
|
149
|
|
|
Schema::foreignKey(['gedcom_id'], 'gedcom', ['gedcom_id'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::CASCADE), |
|
150
|
|
|
Schema::foreignKey(['user_id'], 'user', ['user_id'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::SET_NULL), |
|
151
|
|
|
]); |
|
152
|
|
|
|
|
153
|
|
|
$dates = Schema::table('dates', [ |
|
154
|
|
|
Schema::smallInteger('d_day'), |
|
155
|
|
|
Schema::varchar('d_month', 5), |
|
156
|
|
|
Schema::tinyInteger('d_mon'), |
|
157
|
|
|
Schema::smallInteger('d_year'), |
|
158
|
|
|
Schema::integer('d_julianday1'), |
|
159
|
|
|
Schema::integer('d_julianday2'), |
|
160
|
|
|
Schema::varchar('d_fact', 15), |
|
161
|
|
|
Schema::varchar('d_gid', 20), |
|
162
|
|
|
Schema::integer('d_file'), |
|
163
|
|
|
Schema::varchar('d_type', 13), |
|
164
|
|
|
Schema::index(['d_day']), |
|
165
|
|
|
Schema::index(['d_month']), |
|
166
|
|
|
Schema::index(['d_mon']), |
|
167
|
|
|
Schema::index(['d_year']), |
|
168
|
|
|
Schema::index(['d_julianday1']), |
|
169
|
|
|
Schema::index(['d_julianday2']), |
|
170
|
|
|
Schema::index(['d_gid']), |
|
171
|
|
|
Schema::index(['d_file']), |
|
172
|
|
|
Schema::index(['d_type']), |
|
173
|
|
|
Schema::index(['d_fact', 'd_gid']), |
|
174
|
|
|
]); |
|
175
|
|
|
|
|
176
|
|
|
$default_resn = Schema::table('default_resn', [ |
|
177
|
|
|
Schema::integer('default_resn_id')->autoIncrement(), |
|
178
|
|
|
Schema::integer('gedcom_id'), |
|
179
|
|
|
Schema::varchar('xref', 20), |
|
180
|
|
|
Schema::primaryKey(['default_resn_id']), |
|
181
|
|
|
Schema::index(['gedcom_id', 'xref', 'tag_type']), |
|
182
|
|
|
Schema::foreignKey(['gedcom_id'], 'gedcom', ['gedcom_id'])->onUpdate(ReferentialAction::CASCADE)->onDelete(ReferentialAction::CASCADE), |
|
183
|
|
|
]); |
|
184
|
|
|
|
|
185
|
|
|
$families = Schema::table('families', [ |
|
186
|
|
|
Schema::varchar('f_id', 20), |
|
187
|
|
|
Schema::integer('f_file'), |
|
188
|
|
|
Schema::varchar('f_husb', 20), |
|
189
|
|
|
Schema::varchar('f_wife', 20), |
|
190
|
|
|
Schema::integer('f_numchil'), |
|
191
|
|
|
Schema::primaryKey(['f_id', 'f_file']), |
|
192
|
|
|
Schema::uniqueIndex(['f_file', 'f_id']), |
|
193
|
|
|
Schema::index(['f_husb']), |
|
194
|
|
|
Schema::index(['f_wife']), |
|
195
|
|
|
]); |
|
196
|
|
|
|
|
197
|
|
|
return new Schema([ |
|
198
|
|
|
$gedcom, |
|
199
|
|
|
$user, |
|
200
|
|
|
$module, |
|
201
|
|
|
$block, |
|
202
|
|
|
$block_setting, |
|
203
|
|
|
$change, |
|
204
|
|
|
$dates, |
|
205
|
|
|
$default_resn, |
|
206
|
|
|
$families, |
|
207
|
|
|
]); |
|
208
|
|
|
|
|
209
|
|
|
$table_favorite = $schema->createTable('favorite'); |
|
|
|
|
|
|
210
|
|
|
$table_favorite->addColumn('favorite_id', Types::INTEGER, ['autoincrement' => true]); |
|
|
|
|
|
|
211
|
|
|
$table_favorite->addColumn('user_id', Types::INTEGER, ['notNull' => false]); |
|
212
|
|
|
$table_favorite->addColumn('xref', Types::STRING, ['length' => 20, 'notNull' => false, 'platformOptions' => $ascii_bin]); |
|
213
|
|
|
$table_favorite->addColumn('favorite_type', Types::STRING, ['length' => 4, 'platformOptions' => $ascii_bin]); |
|
214
|
|
|
$table_favorite->addColumn('url', Types::STRING, ['length' => 255, 'notNull' => false, 'platformOptions' => $utf8_bin]); |
|
215
|
|
|
$table_favorite->addColumn('title', Types::STRING, ['length' => 255, 'notNull' => false, 'platformOptions' => $utf8_bin]); |
|
216
|
|
|
$table_favorite->addColumn('note', Types::STRING, ['length' => 1000, 'notNull' => false, 'platformOptions' => $utf8_bin]); |
|
217
|
|
|
$table_favorite->addColumn('gedcom_id', Types::INTEGER); |
|
218
|
|
|
$table_favorite->setPrimaryKey(['favorite_id']); |
|
219
|
|
|
$table_favorite->addIndex(['user_id']); |
|
220
|
|
|
$table_favorite->addIndex(['gedcom_id', 'user_id']); |
|
221
|
|
|
$table_favorite->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
222
|
|
|
$table_favorite->addForeignKeyConstraint($user->getName(), ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
223
|
|
|
|
|
224
|
|
|
$table_gedcom_chunk = $schema->createTable('gedcom_chunk'); |
|
225
|
|
|
$table_gedcom_chunk->addColumn('gedcom_chunk_id', Types::INTEGER, ['autoincrement' => true]); |
|
226
|
|
|
$table_gedcom_chunk->addColumn('gedcom_id', Types::INTEGER); |
|
227
|
|
|
$table_gedcom_chunk->addColumn('chunk_data', Types::BLOB); |
|
228
|
|
|
$table_gedcom_chunk->addColumn('imported', Types::INTEGER, ['default' => 0]); |
|
229
|
|
|
$table_gedcom_chunk->setPrimaryKey(['gedcom_chunk_id']); |
|
230
|
|
|
$table_gedcom_chunk->addIndex(['gedcom_id', 'imported']); |
|
231
|
|
|
$table_gedcom_chunk->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
232
|
|
|
|
|
233
|
|
|
$table_gedcom_setting = $schema->createTable('gedcom_setting'); |
|
234
|
|
|
$table_gedcom_setting->addColumn('gedcom_id', Types::INTEGER); |
|
235
|
|
|
$table_gedcom_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
236
|
|
|
$table_gedcom_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
237
|
|
|
$table_gedcom_setting->setPrimaryKey(['gedcom_id', 'setting_name']); |
|
238
|
|
|
$table_gedcom_setting->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
239
|
|
|
|
|
240
|
|
|
$table_hit_counter = $schema->createTable('hit_counter'); |
|
241
|
|
|
$table_hit_counter->addColumn('gedcom_id', Types::INTEGER); |
|
242
|
|
|
$table_hit_counter->addColumn('page_name', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
243
|
|
|
$table_hit_counter->addColumn('page_parameter', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
244
|
|
|
$table_hit_counter->addColumn('page_count', Types::INTEGER); |
|
245
|
|
|
$table_hit_counter->setPrimaryKey(['gedcom_id', 'page_name', 'page_parameter']); |
|
246
|
|
|
$table_hit_counter->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
247
|
|
|
|
|
248
|
|
|
$table_individuals = $schema->createTable('individuals'); |
|
249
|
|
|
$table_individuals->addColumn('i_id', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
250
|
|
|
$table_individuals->addColumn('i_file', Types::INTEGER); |
|
251
|
|
|
$table_individuals->addColumn('i_rin', Types::STRING, ['length' => 20, 'platformOptions' => $utf8_bin]); |
|
252
|
|
|
$table_individuals->addColumn('i_sex', Types::STRING, ['length' => 1, 'platformOptions' => $ascii_bin]); |
|
253
|
|
|
$table_individuals->addColumn('i_gedcom', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
254
|
|
|
$table_individuals->setPrimaryKey(['i_id', 'i_file']); |
|
255
|
|
|
$table_individuals->addUniqueIndex(['i_file', 'i_id']); |
|
256
|
|
|
|
|
257
|
|
|
$table_link = $schema->createTable('link'); |
|
258
|
|
|
$table_link->addColumn('l_file', Types::INTEGER); |
|
259
|
|
|
$table_link->addColumn('l_from', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
260
|
|
|
$table_link->addColumn('l_type', Types::STRING, ['length' => 15, 'platformOptions' => $ascii_bin]); |
|
261
|
|
|
$table_link->addColumn('l_to', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
262
|
|
|
$table_link->setPrimaryKey(['l_from', 'l_file', 'l_type', 'l_to']); |
|
263
|
|
|
$table_link->addUniqueIndex(['l_to', 'l_file', 'l_type', 'l_from']); |
|
264
|
|
|
|
|
265
|
|
|
$table_log = $schema->createTable('log'); |
|
266
|
|
|
$table_log->addColumn('log_id', Types::INTEGER, ['autoincrement' => true]); |
|
267
|
|
|
$table_log->addColumn('log_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'precision' => 0]); |
|
268
|
|
|
$table_log->addColumn('log_type', Types::STRING, ['length' => 6, 'platformOptions' => $ascii_bin]); |
|
269
|
|
|
$table_log->addColumn('log_message', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
270
|
|
|
$table_log->addColumn('ip_address', Types::STRING, ['length' => 45]); |
|
271
|
|
|
$table_log->addColumn('user_id', Types::INTEGER, ['notNull' => false]); |
|
272
|
|
|
$table_log->addColumn('gedcom_id', Types::INTEGER, ['notNull' => false]); |
|
273
|
|
|
$table_log->setPrimaryKey(['log_id']); |
|
274
|
|
|
$table_log->addIndex(['log_time']); |
|
275
|
|
|
$table_log->addIndex(['log_type']); |
|
276
|
|
|
$table_log->addIndex(['ip_address']); |
|
277
|
|
|
$table_log->addIndex(['user_id']); |
|
278
|
|
|
$table_log->addIndex(['gedcom_id']); |
|
279
|
|
|
$table_log->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
280
|
|
|
$table_log->addForeignKeyConstraint($user->getName(), ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
281
|
|
|
|
|
282
|
|
|
$table_media = $schema->createTable('media'); |
|
283
|
|
|
$table_media->addColumn('m_id', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
284
|
|
|
$table_media->addColumn('m_file', Types::INTEGER); |
|
285
|
|
|
$table_media->addColumn('m_gedcom', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
286
|
|
|
$table_media->setPrimaryKey(['m_file', 'm_id']); |
|
287
|
|
|
$table_media->addUniqueIndex(['m_id', 'm_file']); |
|
288
|
|
|
|
|
289
|
|
|
$table_media_file = $schema->createTable('media_file'); |
|
290
|
|
|
$table_media_file->addColumn('id', Types::INTEGER, ['autoincrement' => true]); |
|
291
|
|
|
$table_media_file->addColumn('m_id', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
292
|
|
|
$table_media_file->addColumn('m_file', Types::INTEGER); |
|
293
|
|
|
$table_media_file->addColumn('multimedia_file_refn', Types::STRING, ['length' => 246, 'platformOptions' => $utf8_bin]); |
|
294
|
|
|
$table_media_file->addColumn('multimedia_format', Types::STRING, ['length' => 4, 'platformOptions' => $utf8_bin]); |
|
295
|
|
|
$table_media_file->addColumn('source_media_type', Types::STRING, ['length' => 15, 'platformOptions' => $utf8_bin]); |
|
296
|
|
|
$table_media_file->addColumn('descriptive_title', Types::STRING, ['length' => 248, 'platformOptions' => $utf8_bin]); |
|
297
|
|
|
$table_media_file->setPrimaryKey(['id']); |
|
298
|
|
|
$table_media_file->addIndex(['m_id', 'm_file']); |
|
299
|
|
|
$table_media_file->addIndex(['m_file', 'm_id']); |
|
300
|
|
|
$table_media_file->addIndex(['m_file', 'multimedia_file_refn']); |
|
301
|
|
|
$table_media_file->addIndex(['m_file', 'multimedia_format']); |
|
302
|
|
|
$table_media_file->addIndex(['m_file', 'source_media_type']); |
|
303
|
|
|
$table_media_file->addIndex(['m_file', 'descriptive_title']); |
|
304
|
|
|
|
|
305
|
|
|
$table_message = $schema->createTable('message'); |
|
306
|
|
|
$table_message->addColumn('message_id', Types::INTEGER, ['autoincrement' => true]); |
|
307
|
|
|
$table_message->addColumn('sender', Types::STRING, ['length' => 64, 'platformOptions' => $utf8_bin]); |
|
308
|
|
|
$table_message->addColumn('ip_address', Types::STRING, ['length' => 45, 'platformOptions' => $ascii_bin]); |
|
309
|
|
|
$table_message->addColumn('user_id', Types::INTEGER); |
|
310
|
|
|
$table_message->addColumn('subject', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
311
|
|
|
$table_message->addColumn('body', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
312
|
|
|
$table_message->addColumn('created', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'precision' => 0]); |
|
313
|
|
|
$table_message->addIndex(['user_id']); |
|
314
|
|
|
$table_message->setPrimaryKey(['message_id']); |
|
315
|
|
|
$table_message->addForeignKeyConstraint($user->getName(), ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
316
|
|
|
|
|
317
|
|
|
$table_module_privacy = $schema->createTable('module_privacy'); |
|
318
|
|
|
$table_module_privacy->addColumn('id', Types::INTEGER, ['autoincrement' => true]); |
|
319
|
|
|
$table_module_privacy->addColumn('module_name', Types::STRING, ['length' => 32, 'platformOptions' => $utf8_bin]); |
|
320
|
|
|
$table_module_privacy->addColumn('gedcom_id', Types::INTEGER); |
|
321
|
|
|
$table_module_privacy->addColumn('interface', Types::STRING, ['length' => 255, 'platformOptions' => $ascii_bin]); |
|
322
|
|
|
$table_module_privacy->addColumn('access_level', Types::SMALLINT); |
|
323
|
|
|
$table_module_privacy->addUniqueIndex(['gedcom_id', 'module_name', 'interface']); |
|
324
|
|
|
$table_module_privacy->addUniqueIndex(['module_name', 'gedcom_id', 'interface']); |
|
325
|
|
|
$table_module_privacy->setPrimaryKey(['id']); |
|
326
|
|
|
$table_module_privacy->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
327
|
|
|
$table_module_privacy->addForeignKeyConstraint($module->getName(), ['module_name'], ['module_name'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
328
|
|
|
|
|
329
|
|
|
$table_module_setting = $schema->createTable('module_setting'); |
|
330
|
|
|
$table_module_setting->addColumn('module_name', Types::STRING, ['length' => 32, 'platformOptions' => $utf8_bin]); |
|
331
|
|
|
$table_module_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
332
|
|
|
$table_module_setting->addColumn('setting_value', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
333
|
|
|
$table_module_setting->setPrimaryKey(['module_name', 'setting_name']); |
|
334
|
|
|
$table_module_setting->addForeignKeyConstraint($module->getName(), ['module_name'], ['module_name'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
335
|
|
|
|
|
336
|
|
|
$table_name = $schema->createTable('name'); |
|
337
|
|
|
$table_name->addColumn('n_file', Types::INTEGER); |
|
338
|
|
|
$table_name->addColumn('n_id', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
339
|
|
|
$table_name->addColumn('n_num', Types::INTEGER); |
|
340
|
|
|
$table_name->addColumn('n_type', Types::STRING, ['length' => 15, 'platformOptions' => $ascii_bin]); |
|
341
|
|
|
$table_name->addColumn('n_sort', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
342
|
|
|
$table_name->addColumn('n_full', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
343
|
|
|
$table_name->addColumn('n_surname', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
344
|
|
|
$table_name->addColumn('n_surn', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
345
|
|
|
$table_name->addColumn('n_givn', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
346
|
|
|
$table_name->addColumn('n_soundex_givn_std', Types::STRING, ['length' => 255, 'notNull' => false, 'platformOptions' => $ascii_bin]); |
|
347
|
|
|
$table_name->addColumn('n_soundex_surn_std', Types::STRING, ['length' => 255, 'notNull' => false, 'platformOptions' => $ascii_bin]); |
|
348
|
|
|
$table_name->addColumn('n_soundex_givn_dm', Types::STRING, ['length' => 255, 'notNull' => false, 'platformOptions' => $ascii_bin]); |
|
349
|
|
|
$table_name->addColumn('n_soundex_surn_dm', Types::STRING, ['length' => 255, 'notNull' => false, 'platformOptions' => $ascii_bin]); |
|
350
|
|
|
$table_name->setPrimaryKey(['n_id', 'n_file', 'n_num']); |
|
351
|
|
|
$table_name->addIndex(['n_full', 'n_id', 'n_file']); |
|
352
|
|
|
$table_name->addIndex(['n_surn', 'n_file', 'n_type', 'n_id']); |
|
353
|
|
|
$table_name->addIndex(['n_givn', 'n_file', 'n_type', 'n_id']); |
|
354
|
|
|
|
|
355
|
|
|
$table_news = $schema->createTable('news'); |
|
356
|
|
|
$table_news->addColumn('news_id', Types::INTEGER, ['autoincrement' => true]); |
|
357
|
|
|
$table_news->addColumn('user_id', Types::INTEGER, ['notNull' => false]); |
|
358
|
|
|
$table_news->addColumn('gedcom_id', Types::INTEGER, ['notNull' => false]); |
|
359
|
|
|
$table_news->addColumn('subject', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
360
|
|
|
$table_news->addColumn('body', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
361
|
|
|
$table_news->addColumn('updated', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'precision' => 0]); |
|
362
|
|
|
$table_news->setPrimaryKey(['news_id']); |
|
363
|
|
|
$table_news->addIndex(['user_id', 'updated']); |
|
364
|
|
|
$table_news->addIndex(['gedcom_id', 'updated']); |
|
365
|
|
|
$table_news->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
366
|
|
|
$table_news->addForeignKeyConstraint($user->getName(), ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
367
|
|
|
|
|
368
|
|
|
$table_other = $schema->createTable('other'); |
|
369
|
|
|
$table_other->addColumn('o_id', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
370
|
|
|
$table_other->addColumn('o_file', Types::INTEGER); |
|
371
|
|
|
$table_other->addColumn('o_type', Types::STRING, ['length' => 15, 'platformOptions' => $ascii_bin]); |
|
372
|
|
|
$table_other->addColumn('o_gedcom', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
373
|
|
|
$table_other->setPrimaryKey(['o_id', 'o_file']); |
|
374
|
|
|
$table_other->addUniqueIndex(['o_file', 'o_id']); |
|
375
|
|
|
|
|
376
|
|
|
$table_places = $schema->createTable('places'); |
|
377
|
|
|
$table_places->addColumn('p_id', Types::INTEGER, ['autoincrement' => true]); |
|
378
|
|
|
$table_places->addColumn('p_place', Types::STRING, ['length' => 150, 'platformOptions' => $utf8_bin]); |
|
379
|
|
|
$table_places->addColumn('p_parent_id', Types::INTEGER, ['notNull' => false]); |
|
380
|
|
|
$table_places->addColumn('p_file', Types::INTEGER); |
|
381
|
|
|
$table_places->addColumn('p_std_soundex', Types::TEXT, ['platformOptions' => $ascii_bin]); |
|
382
|
|
|
$table_places->addColumn('p_dm_soundex', Types::TEXT, ['platformOptions' => $ascii_bin]); |
|
383
|
|
|
$table_places->setPrimaryKey(['p_id']); |
|
384
|
|
|
$table_places->addUniqueIndex(['p_parent_id', 'p_file', 'p_place']); |
|
385
|
|
|
$table_places->addIndex(['p_file', 'p_place']); |
|
386
|
|
|
|
|
387
|
|
|
$table_placelinks = $schema->createTable('placelinks'); |
|
388
|
|
|
$table_placelinks->addColumn('pl_p_id', Types::INTEGER); |
|
389
|
|
|
$table_placelinks->addColumn('pl_gid', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
390
|
|
|
$table_placelinks->addColumn('pl_file', Types::INTEGER); |
|
391
|
|
|
$table_placelinks->setPrimaryKey(['pl_p_id', 'pl_gid', 'pl_file']); |
|
392
|
|
|
$table_placelinks->addIndex(['pl_p_id']); |
|
393
|
|
|
$table_placelinks->addIndex(['pl_gid']); |
|
394
|
|
|
$table_placelinks->addIndex(['pl_file']); |
|
395
|
|
|
|
|
396
|
|
|
$table_place_location = $schema->createTable('place_location'); |
|
397
|
|
|
$table_place_location->addColumn('id', Types::INTEGER, ['autoincrement' => true]); |
|
398
|
|
|
$table_place_location->addColumn('parent_id', Types::INTEGER, ['notNull' => false]); |
|
399
|
|
|
$table_place_location->addColumn('place', Types::STRING, ['length' => 120, 'platformOptions' => $utf8_bin]); |
|
400
|
|
|
$table_place_location->addColumn('latitude', Types::FLOAT, ['notNull' => false]); |
|
401
|
|
|
$table_place_location->addColumn('longitude', Types::FLOAT, ['notNull' => false]); |
|
402
|
|
|
$table_place_location->setPrimaryKey(['id']); |
|
403
|
|
|
$table_place_location->addUniqueIndex(['parent_id', 'place']); |
|
404
|
|
|
$table_place_location->addUniqueIndex(['place', 'parent_id']); |
|
405
|
|
|
$table_place_location->addIndex(['latitude']); |
|
406
|
|
|
$table_place_location->addIndex(['longitude']); |
|
407
|
|
|
$table_place_location->addForeignKeyConstraint($table_place_location->getName(), ['parent_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
408
|
|
|
|
|
409
|
|
|
$table_sources = $schema->createTable('session'); |
|
410
|
|
|
$table_sources->addColumn('session_id', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
411
|
|
|
$table_sources->addColumn('session_time', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'precision' => 0]); |
|
412
|
|
|
$table_sources->addColumn('user_id', Types::INTEGER); |
|
413
|
|
|
$table_sources->addColumn('ip_address', Types::STRING, ['length' => 45, 'platformOptions' => $ascii_bin]); |
|
414
|
|
|
$table_sources->addColumn('session_data', Types::BLOB); |
|
415
|
|
|
$table_sources->setPrimaryKey(['session_id']); |
|
416
|
|
|
$table_sources->addIndex(['session_time']); |
|
417
|
|
|
$table_sources->addIndex(['user_id', 'ip_address']); |
|
418
|
|
|
|
|
419
|
|
|
$table_site_setting = $schema->createTable('site_setting'); |
|
420
|
|
|
$table_site_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
421
|
|
|
$table_site_setting->addColumn('setting_value', Types::STRING, ['length' => 2000, 'platformOptions' => $utf8_bin]); |
|
422
|
|
|
$table_site_setting->setPrimaryKey(['setting_name']); |
|
423
|
|
|
|
|
424
|
|
|
$table_sources = $schema->createTable('sources'); |
|
425
|
|
|
$table_sources->addColumn('s_id', Types::STRING, ['length' => 20, 'platformOptions' => $ascii_bin]); |
|
426
|
|
|
$table_sources->addColumn('s_file', Types::INTEGER); |
|
427
|
|
|
$table_sources->addColumn('s_name', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
428
|
|
|
$table_sources->addColumn('s_gedcom', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
429
|
|
|
$table_sources->setPrimaryKey(['s_id', 's_file']); |
|
430
|
|
|
$table_sources->addUniqueIndex(['s_file', 's_id']); |
|
431
|
|
|
$table_sources->addIndex(['s_name']); |
|
432
|
|
|
|
|
433
|
|
|
$table_user_gedcom_setting = $schema->createTable('user_gedcom_setting'); |
|
434
|
|
|
$table_user_gedcom_setting->addColumn('user_id', Types::INTEGER); |
|
435
|
|
|
$table_user_gedcom_setting->addColumn('gedcom_id', Types::INTEGER); |
|
436
|
|
|
$table_user_gedcom_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
437
|
|
|
$table_user_gedcom_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
438
|
|
|
$table_user_gedcom_setting->setPrimaryKey(['user_id', 'gedcom_id', 'setting_name']); |
|
439
|
|
|
$table_user_gedcom_setting->addIndex(['gedcom_id']); |
|
440
|
|
|
$table_user_gedcom_setting->addForeignKeyConstraint($gedcom->getName(), ['gedcom_id'], ['gedcom_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
441
|
|
|
$table_user_gedcom_setting->addForeignKeyConstraint($user->getName(), ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
442
|
|
|
|
|
443
|
|
|
$table_user_setting = $schema->createTable('user_setting'); |
|
444
|
|
|
$table_user_setting->addColumn('user_id', Types::INTEGER); |
|
445
|
|
|
$table_user_setting->addColumn('setting_name', Types::STRING, ['length' => 32, 'platformOptions' => $ascii_bin]); |
|
446
|
|
|
$table_user_setting->addColumn('setting_value', Types::STRING, ['length' => 255, 'platformOptions' => $utf8_bin]); |
|
447
|
|
|
$table_user_setting->setPrimaryKey(['user_id', 'setting_name']); |
|
448
|
|
|
$table_user_setting->addForeignKeyConstraint($user->getName(), ['user_id'], ['user_id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
449
|
|
|
|
|
450
|
|
|
/* |
|
451
|
|
|
$site = $schema->createTable('site'); |
|
452
|
|
|
$site->addColumn('uuid', Types::STRING, ['length' => 36, 'platformOptions' => $ascii]); |
|
453
|
|
|
$site->addColumn('db_schema', Types::STRING, ['length' => 20, 'platformOptions' => $ascii]); |
|
454
|
|
|
$site->addColumn('created_at', Types::TIME_MUTABLE); |
|
455
|
|
|
$site->addColumn('updated_at', Types::TIME_MUTABLE); |
|
456
|
|
|
$site->setPrimaryKey(['uuid']); |
|
457
|
|
|
|
|
458
|
|
|
$job = $schema->createTable('job'); |
|
459
|
|
|
$job->addColumn('uuid', Types::STRING, ['length' => 36, 'platformOptions' => $ascii]); |
|
460
|
|
|
$job->addColumn('failures', Types::INTEGER, ['default' => 0]); |
|
461
|
|
|
$job->addColumn('job', Types::STRING, ['length' => 255, 'platformOptions' => $ascii]); |
|
462
|
|
|
$job->addColumn('parameters', Types::TEXT, ['platformOptions' => $utf8_bin]); |
|
463
|
|
|
$job->addColumn('error', Types::TEXT, ['notnull' => false, 'platformOptions' => $utf8_bin]); |
|
464
|
|
|
$job->addColumn('created_at', Types::TIME_MUTABLE); |
|
465
|
|
|
$job->addColumn('updated_at', Types::TIME_MUTABLE); |
|
466
|
|
|
$job->setPrimaryKey(['uuid']); |
|
467
|
|
|
|
|
468
|
|
|
$job_dependency = $schema->createTable('job_dependency'); |
|
469
|
|
|
$job_dependency->addColumn('uuid1', Types::STRING, ['length' => 36, 'platformOptions' => $ascii]); |
|
470
|
|
|
$job_dependency->addColumn('uuid2', Types::STRING, ['length' => 36, 'platformOptions' => $ascii]); |
|
471
|
|
|
$job_dependency->addUniqueIndex(['uuid1', 'uuid2']); |
|
472
|
|
|
$job_dependency->addUniqueIndex(['uuid2', 'uuid1']); |
|
473
|
|
|
$job_dependency->addForeignKeyConstraint($job->getName(), ['uuid1'], ['uuid'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
474
|
|
|
$job_dependency->addForeignKeyConstraint($job->getName(), ['uuid2'], ['uuid'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); |
|
475
|
|
|
*/ |
|
476
|
|
|
|
|
477
|
|
|
$current_schema = $connection |
|
478
|
|
|
->createSchemaManager() |
|
479
|
|
|
->introspectSchema(); |
|
480
|
|
|
|
|
481
|
|
|
$schema_diff = $connection |
|
482
|
|
|
->createSchemaManager() |
|
483
|
|
|
->createComparator() |
|
484
|
|
|
->compareSchemas($current_schema, $schema); |
|
485
|
|
|
|
|
486
|
|
|
$queries = $connection |
|
487
|
|
|
->getDatabasePlatform() |
|
488
|
|
|
->getAlterSchemaSQL($schema_diff); |
|
489
|
|
|
|
|
490
|
|
|
foreach ($queries as $query) { |
|
491
|
|
|
echo '<p>', $query, '</p>'; |
|
492
|
|
|
try { |
|
493
|
|
|
$connection->executeStatement($query); |
|
494
|
|
|
} catch (Exception $ex) { |
|
495
|
|
|
echo '<p>', $ex->getMessage(), '</p>'; |
|
496
|
|
|
} |
|
497
|
|
|
} |
|
498
|
|
|
exit; |
|
|
|
|
|
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.