xref: /webtrees/app/Schema/Migration0.php (revision 736b8b72ed0af202b700901a7965eb77c180581f)
13bfb94b0SGreg Roach<?php
23976b470SGreg Roach
33bfb94b0SGreg Roach/**
43bfb94b0SGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team
63bfb94b0SGreg Roach * This program is free software: you can redistribute it and/or modify
73bfb94b0SGreg Roach * it under the terms of the GNU General Public License as published by
83bfb94b0SGreg Roach * the Free Software Foundation, either version 3 of the License, or
93bfb94b0SGreg Roach * (at your option) any later version.
103bfb94b0SGreg Roach * This program is distributed in the hope that it will be useful,
113bfb94b0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
123bfb94b0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
133bfb94b0SGreg Roach * GNU General Public License for more details.
143bfb94b0SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
163bfb94b0SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Schema;
2176692c8bSGreg Roach
22c9beb871SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
23c9beb871SGreg Roachuse Illuminate\Database\Schema\Blueprint;
243bfb94b0SGreg Roach
253bfb94b0SGreg Roach/**
2676692c8bSGreg Roach * Upgrade the database schema from version 0 (empty database) to version 1.
273bfb94b0SGreg Roach */
28c1010edaSGreg Roachclass Migration0 implements MigrationInterface
29c1010edaSGreg Roach{
3076692c8bSGreg Roach    /**
31d9efec4aSGreg Roach     * Upgrade to the next version.
3219d91378SGreg Roach     *
3319d91378SGreg Roach     * @return void
3476692c8bSGreg Roach     */
35362be83aSGreg Roach    public function upgrade(): void
36c1010edaSGreg Roach    {
370b5fd0a6SGreg Roach        DB::schema()->create('gedcom', static function (Blueprint $table): void {
38c9beb871SGreg Roach            $table->integer('gedcom_id', true);
39c9beb871SGreg Roach            $table->string('gedcom_name', 255);
40c9beb871SGreg Roach            $table->integer('sort_order')->default(0);
413bfb94b0SGreg Roach
42c9beb871SGreg Roach            $table->unique('gedcom_name');
43c9beb871SGreg Roach            $table->index('sort_order');
44c9beb871SGreg Roach        });
453bfb94b0SGreg Roach
460b5fd0a6SGreg Roach        DB::schema()->create('site_setting', static function (Blueprint $table): void {
47c9beb871SGreg Roach            $table->string('setting_name', 32);
48c9beb871SGreg Roach            $table->string('setting_value', 2000);
49c9beb871SGreg Roach
50c9beb871SGreg Roach            $table->primary('setting_name');
51c9beb871SGreg Roach        });
52c9beb871SGreg Roach
530b5fd0a6SGreg Roach        DB::schema()->create('gedcom_setting', static function (Blueprint $table): void {
54c9beb871SGreg Roach            $table->integer('gedcom_id');
55c9beb871SGreg Roach            $table->string('setting_name', 32);
56c9beb871SGreg Roach            $table->string('setting_value', 255);
57c9beb871SGreg Roach
58c9beb871SGreg Roach            $table->primary(['gedcom_id', 'setting_name']);
59c9beb871SGreg Roach
60c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
61c9beb871SGreg Roach        });
62c9beb871SGreg Roach
630b5fd0a6SGreg Roach        DB::schema()->create('user', static function (Blueprint $table): void {
64c9beb871SGreg Roach            $table->integer('user_id', true);
65c9beb871SGreg Roach            $table->string('user_name', 32);
66c9beb871SGreg Roach            $table->string('real_name', 64);
67c9beb871SGreg Roach            $table->string('email', 64);
68c9beb871SGreg Roach            $table->string('password', 128);
69c9beb871SGreg Roach
70c9beb871SGreg Roach            $table->unique('user_name');
71c9beb871SGreg Roach            $table->unique('email');
72c9beb871SGreg Roach        });
73c9beb871SGreg Roach
740b5fd0a6SGreg Roach        DB::schema()->create('user_setting', static function (Blueprint $table): void {
75c9beb871SGreg Roach            $table->integer('user_id');
76c9beb871SGreg Roach            $table->string('setting_name', 32);
77c9beb871SGreg Roach            $table->string('setting_value', 255);
78c9beb871SGreg Roach
79c9beb871SGreg Roach            $table->primary(['user_id', 'setting_name']);
80c9beb871SGreg Roach
81c9beb871SGreg Roach            $table->foreign('user_id')->references('user_id')->on('user');
82c9beb871SGreg Roach        });
83c9beb871SGreg Roach
840b5fd0a6SGreg Roach        DB::schema()->create('user_gedcom_setting', static function (Blueprint $table): void {
85c9beb871SGreg Roach            $table->integer('user_id');
86c9beb871SGreg Roach            $table->integer('gedcom_id');
87c9beb871SGreg Roach            $table->string('setting_name', 32);
88c9beb871SGreg Roach            $table->string('setting_value', 255);
89c9beb871SGreg Roach
9009331e47SGreg Roach            // Default constraint names are too long for MySQL.
9109331e47SGreg Roach            $key = DB::connection()->getTablePrefix() . $table->getTable() . '_primary';
9209331e47SGreg Roach
9309331e47SGreg Roach            $table->primary(['user_id', 'gedcom_id', 'setting_name'], $key);
94c9beb871SGreg Roach            $table->index('gedcom_id');
95c9beb871SGreg Roach
96c9beb871SGreg Roach            $table->foreign('user_id')->references('user_id')->on('user');
97c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
98c9beb871SGreg Roach        });
99c9beb871SGreg Roach
1000b5fd0a6SGreg Roach        DB::schema()->create('log', static function (Blueprint $table): void {
101c9beb871SGreg Roach            $table->integer('log_id', true);
102c9beb871SGreg Roach            $table->timestamp('log_time')->useCurrent();
103c9beb871SGreg Roach            $table->enum('log_type', ['auth', 'config', 'debug', 'edit', 'error', 'media', 'search']);
104c9beb871SGreg Roach            $table->longText('log_message');
105c9beb871SGreg Roach            $table->ipAddress('ip_address');
106c9beb871SGreg Roach            $table->integer('user_id')->nullable();
107c9beb871SGreg Roach            $table->integer('gedcom_id')->nullable();
108c9beb871SGreg Roach
109c9beb871SGreg Roach            $table->index('log_time');
110c9beb871SGreg Roach            $table->index('log_type');
111c9beb871SGreg Roach            $table->index('ip_address');
112c9beb871SGreg Roach            $table->index('user_id');
113c9beb871SGreg Roach            $table->index('gedcom_id');
114c9beb871SGreg Roach
115c9beb871SGreg Roach            $table->foreign('user_id')->references('user_id')->on('user');
116c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
117c9beb871SGreg Roach        });
118c9beb871SGreg Roach
1190b5fd0a6SGreg Roach        DB::schema()->create('change', static function (Blueprint $table): void {
120c9beb871SGreg Roach            $table->integer('change_id', true);
121c9beb871SGreg Roach            $table->timestamp('change_time')->useCurrent();
122c9beb871SGreg Roach            $table->enum('status', ['accepted', 'pending', 'rejected'])->default('pending');
123c9beb871SGreg Roach            $table->integer('gedcom_id');
124c9beb871SGreg Roach            $table->string('xref', 20);
125c9beb871SGreg Roach            $table->longText('old_gedcom');
126c9beb871SGreg Roach            $table->longText('new_gedcom');
127c9beb871SGreg Roach            $table->integer('user_id');
128c9beb871SGreg Roach
129c9beb871SGreg Roach            $table->index(['gedcom_id', 'status', 'xref']);
130c9beb871SGreg Roach            $table->index('user_id');
131c9beb871SGreg Roach
132c9beb871SGreg Roach            $table->foreign('user_id')->references('user_id')->on('user');
133c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
134c9beb871SGreg Roach        });
135c9beb871SGreg Roach
1360b5fd0a6SGreg Roach        DB::schema()->create('message', static function (Blueprint $table): void {
137c9beb871SGreg Roach            $table->integer('message_id', true);
138c9beb871SGreg Roach            $table->string('sender', 64);
139c9beb871SGreg Roach            $table->ipAddress('ip_address');
140c9beb871SGreg Roach            $table->integer('user_id');
141c9beb871SGreg Roach            $table->string('subject', 255);
142c9beb871SGreg Roach            $table->longText('body');
143c9beb871SGreg Roach            $table->timestamp('created')->useCurrent();
144c9beb871SGreg Roach
145c9beb871SGreg Roach            $table->index('user_id');
146c9beb871SGreg Roach
147c9beb871SGreg Roach            $table->foreign('user_id')->references('user_id')->on('user');
148c9beb871SGreg Roach        });
149c9beb871SGreg Roach
1500b5fd0a6SGreg Roach        DB::schema()->create('default_resn', static function (Blueprint $table): void {
151c9beb871SGreg Roach            $table->integer('default_resn_id', true);
152c9beb871SGreg Roach            $table->integer('gedcom_id');
153c9beb871SGreg Roach            $table->string('xref', 20)->nullable();
154c9beb871SGreg Roach            $table->string('tag_type', 15)->nullable();
155c9beb871SGreg Roach            $table->enum('resn', ['none', 'privacy', 'confidential', 'hidden']);
156c9beb871SGreg Roach            $table->string('comment', 255)->nullable();
157c9beb871SGreg Roach            $table->timestamp('updated')->useCurrent();
158c9beb871SGreg Roach
159c9beb871SGreg Roach            $table->unique(['gedcom_id', 'xref', 'tag_type']);
160c9beb871SGreg Roach
161c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
162c9beb871SGreg Roach        });
163c9beb871SGreg Roach
1640b5fd0a6SGreg Roach        DB::schema()->create('individuals', static function (Blueprint $table): void {
165c9beb871SGreg Roach            $table->string('i_id', 20);
166c9beb871SGreg Roach            $table->integer('i_file');
167c9beb871SGreg Roach            $table->string('i_rin', 20);
168c9beb871SGreg Roach            $table->enum('i_sex', ['U', 'M', 'F']);
169c9beb871SGreg Roach            $table->longText('i_gedcom');
170c9beb871SGreg Roach
171c9beb871SGreg Roach            $table->primary(['i_id', 'i_file']);
172c9beb871SGreg Roach            $table->unique(['i_file', 'i_id']);
173c9beb871SGreg Roach        });
174c9beb871SGreg Roach
1750b5fd0a6SGreg Roach        DB::schema()->create('families', static function (Blueprint $table): void {
176c9beb871SGreg Roach            $table->string('f_id', 20);
177c9beb871SGreg Roach            $table->integer('f_file');
178c9beb871SGreg Roach            $table->string('f_husb', 20)->nullable();
179c9beb871SGreg Roach            $table->string('f_wife', 20)->nullable();
180c9beb871SGreg Roach            $table->longText('f_gedcom');
181c9beb871SGreg Roach            $table->integer('f_numchil');
182c9beb871SGreg Roach
183c9beb871SGreg Roach            $table->primary(['f_id', 'f_file']);
184c9beb871SGreg Roach            $table->unique(['f_file', 'f_id']);
185c9beb871SGreg Roach            $table->index('f_husb');
186c9beb871SGreg Roach            $table->index('f_wife');
187c9beb871SGreg Roach        });
188c9beb871SGreg Roach
1890b5fd0a6SGreg Roach        DB::schema()->create('places', static function (Blueprint $table): void {
190c9beb871SGreg Roach            $table->integer('p_id', true);
191c9beb871SGreg Roach            $table->string('p_place', 150);
192c9beb871SGreg Roach            $table->integer('p_parent_id')->nullable();
193c9beb871SGreg Roach            $table->integer('p_file');
194c9beb871SGreg Roach            $table->longText('p_std_soundex')->nullable();
195c9beb871SGreg Roach            $table->longText('p_dm_soundex')->nullable();
196c9beb871SGreg Roach
197c9beb871SGreg Roach            $table->index(['p_file', 'p_place']);
198c9beb871SGreg Roach            $table->unique(['p_parent_id', 'p_file', 'p_place']);
199c9beb871SGreg Roach        });
200c9beb871SGreg Roach
2010b5fd0a6SGreg Roach        DB::schema()->create('placelinks', static function (Blueprint $table): void {
202c9beb871SGreg Roach            $table->integer('pl_p_id');
203c9beb871SGreg Roach            $table->string('pl_gid', 20);
204c9beb871SGreg Roach            $table->integer('pl_file');
205c9beb871SGreg Roach
206c9beb871SGreg Roach            $table->primary(['pl_p_id', 'pl_gid', 'pl_file']);
207c9beb871SGreg Roach            $table->index('pl_p_id');
208c9beb871SGreg Roach            $table->index('pl_gid');
209c9beb871SGreg Roach            $table->index('pl_file');
210c9beb871SGreg Roach        });
211c9beb871SGreg Roach
2120b5fd0a6SGreg Roach        DB::schema()->create('dates', static function (Blueprint $table): void {
213c9beb871SGreg Roach            $table->tinyInteger('d_day');
214c9beb871SGreg Roach            $table->char('d_month', 5)->nullable();
215c9beb871SGreg Roach            $table->tinyInteger('d_mon');
216c9beb871SGreg Roach            $table->smallInteger('d_year');
217c9beb871SGreg Roach            $table->mediumInteger('d_julianday1');
218c9beb871SGreg Roach            $table->mediumInteger('d_julianday2');
219c9beb871SGreg Roach            $table->string('d_fact', 15);
220c9beb871SGreg Roach            $table->string('d_gid', 20);
221c9beb871SGreg Roach            $table->integer('d_file');
222c9beb871SGreg Roach            $table->enum('d_type', ['@#DGREGORIAN@', '@#DJULIAN@', '@#DHEBREW@', '@#DFRENCH R@', '@#DHIJRI@', '@#DROMAN@', '@#DJALALI@']);
223c9beb871SGreg Roach
224c9beb871SGreg Roach            $table->index('d_day');
225c9beb871SGreg Roach            $table->index('d_month');
226c9beb871SGreg Roach            $table->index('d_mon');
227c9beb871SGreg Roach            $table->index('d_year');
228c9beb871SGreg Roach            $table->index('d_julianday1');
229c9beb871SGreg Roach            $table->index('d_julianday2');
230c9beb871SGreg Roach            $table->index('d_gid');
231c9beb871SGreg Roach            $table->index('d_file');
232c9beb871SGreg Roach            $table->index('d_type');
233c9beb871SGreg Roach            $table->index(['d_fact', 'd_gid']);
234c9beb871SGreg Roach        });
235c9beb871SGreg Roach
2360b5fd0a6SGreg Roach        DB::schema()->create('media', static function (Blueprint $table): void {
237c9beb871SGreg Roach            $table->string('m_id', 20);
238c9beb871SGreg Roach            $table->string('m_ext', 6)->nullable();
239c9beb871SGreg Roach            $table->string('m_type', 20)->nullable();
240bb308685SGreg Roach            $table->string('m_titl', 248)->nullable();
241bb308685SGreg Roach            $table->string('m_filename', 248)->nullable();
242c9beb871SGreg Roach            $table->integer('m_file');
243c9beb871SGreg Roach            $table->longText('m_gedcom')->nullable();
244c9beb871SGreg Roach
245c9beb871SGreg Roach            $table->primary(['m_file', 'm_id']);
246c9beb871SGreg Roach            $table->unique(['m_id', 'm_file']);
247115a8bddSGreg Roach            // Originally, this migration created an index on m_ext and m_type,
248115a8bddSGreg Roach            // but we drop those columns in migration 37.
249c9beb871SGreg Roach        });
250c9beb871SGreg Roach
2510b5fd0a6SGreg Roach        DB::schema()->create('next_id', static function (Blueprint $table): void {
252c9beb871SGreg Roach            $table->integer('gedcom_id');
253c9beb871SGreg Roach            $table->string('record_type', 15);
254c9beb871SGreg Roach            $table->decimal('next_id', 20, 0);
255c9beb871SGreg Roach
256c9beb871SGreg Roach            $table->primary(['gedcom_id', 'record_type']);
257c9beb871SGreg Roach
258c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
259c9beb871SGreg Roach        });
260c9beb871SGreg Roach
2610b5fd0a6SGreg Roach        DB::schema()->create('other', static function (Blueprint $table): void {
262c9beb871SGreg Roach            $table->string('o_id', 20);
263c9beb871SGreg Roach            $table->integer('o_file');
264c9beb871SGreg Roach            $table->string('o_type', 15);
265c9beb871SGreg Roach            $table->longText('o_gedcom');
266c9beb871SGreg Roach
267c9beb871SGreg Roach            $table->primary(['o_id', 'o_file']);
268c9beb871SGreg Roach            $table->unique(['o_file', 'o_id']);
269c9beb871SGreg Roach        });
270c9beb871SGreg Roach
2710b5fd0a6SGreg Roach        DB::schema()->create('sources', static function (Blueprint $table): void {
272c9beb871SGreg Roach            $table->string('s_id', 20);
273c9beb871SGreg Roach            $table->integer('s_file');
274c9beb871SGreg Roach            $table->string('s_name', 255);
275c9beb871SGreg Roach            $table->longText('s_gedcom');
276c9beb871SGreg Roach
277c9beb871SGreg Roach            $table->primary(['s_id', 's_file']);
278c9beb871SGreg Roach            $table->unique(['s_file', 's_id']);
279c9beb871SGreg Roach            $table->index('s_name');
280c9beb871SGreg Roach        });
281c9beb871SGreg Roach
2820b5fd0a6SGreg Roach        DB::schema()->create('link', static function (Blueprint $table): void {
283c9beb871SGreg Roach            $table->integer('l_file');
284c9beb871SGreg Roach            $table->string('l_from', 20);
285c9beb871SGreg Roach            $table->string('l_type', 15);
286c9beb871SGreg Roach            $table->string('l_to', 20);
287c9beb871SGreg Roach
288c9beb871SGreg Roach            $table->primary(['l_from', 'l_file', 'l_type', 'l_to']);
289c9beb871SGreg Roach            $table->unique(['l_to', 'l_file', 'l_type', 'l_from']);
290c9beb871SGreg Roach        });
291c9beb871SGreg Roach
2920b5fd0a6SGreg Roach        DB::schema()->create('name', static function (Blueprint $table): void {
293c9beb871SGreg Roach            $table->integer('n_file');
294c9beb871SGreg Roach            $table->string('n_id', 20);
295c9beb871SGreg Roach            $table->integer('n_num');
296c9beb871SGreg Roach            $table->string('n_type', 15);
297c9beb871SGreg Roach            $table->string('n_sort', 255);
298c9beb871SGreg Roach            $table->string('n_full', 255);
299c9beb871SGreg Roach            $table->string('n_surname', 255)->nullable();
300c9beb871SGreg Roach            $table->string('n_surn', 255)->nullable();
301c9beb871SGreg Roach            $table->string('n_givn', 255)->nullable();
302c9beb871SGreg Roach            $table->string('n_soundex_givn_std', 255)->nullable();
303c9beb871SGreg Roach            $table->string('n_soundex_surn_std', 255)->nullable();
304c9beb871SGreg Roach            $table->string('n_soundex_givn_dm', 255)->nullable();
305c9beb871SGreg Roach            $table->string('n_soundex_surn_dm', 255)->nullable();
306c9beb871SGreg Roach
307c9beb871SGreg Roach            $table->primary(['n_id', 'n_file', 'n_num']);
308c9beb871SGreg Roach            $table->index(['n_full', 'n_id', 'n_file']);
309c9beb871SGreg Roach            $table->index(['n_surn', 'n_file', 'n_type', 'n_id']);
310c9beb871SGreg Roach            $table->index(['n_givn', 'n_file', 'n_type', 'n_id']);
311c9beb871SGreg Roach        });
312c9beb871SGreg Roach
3130b5fd0a6SGreg Roach        DB::schema()->create('module', static function (Blueprint $table): void {
314c9beb871SGreg Roach            $table->string('module_name', 32);
315c9beb871SGreg Roach            $table->enum('status', ['enabled', 'disabled'])->default('enabled');
316c9beb871SGreg Roach            $table->integer('tab_order')->nullable();
317c9beb871SGreg Roach            $table->integer('menu_order')->nullable();
318c9beb871SGreg Roach            $table->integer('sidebar_order')->nullable();
319c9beb871SGreg Roach
320c9beb871SGreg Roach            $table->primary('module_name');
321c9beb871SGreg Roach        });
322c9beb871SGreg Roach
3230b5fd0a6SGreg Roach        DB::schema()->create('module_setting', static function (Blueprint $table): void {
324c9beb871SGreg Roach            $table->string('module_name', 32);
325c9beb871SGreg Roach            $table->string('setting_name', 32);
326c9beb871SGreg Roach            $table->longText('setting_value');
327c9beb871SGreg Roach
328c9beb871SGreg Roach            $table->primary(['module_name', 'setting_name']);
329c9beb871SGreg Roach
330c9beb871SGreg Roach            $table->foreign('module_name')->references('module_name')->on('module');
331c9beb871SGreg Roach        });
332c9beb871SGreg Roach
3330b5fd0a6SGreg Roach        DB::schema()->create('module_privacy', static function (Blueprint $table): void {
334c9beb871SGreg Roach            $table->string('module_name', 32);
335c9beb871SGreg Roach            $table->integer('gedcom_id');
336c9beb871SGreg Roach            $table->enum('component', ['block', 'chart', 'menu', 'report', 'sidebar', 'tab', 'theme']);
337c9beb871SGreg Roach            $table->tinyInteger('access_level');
338c9beb871SGreg Roach
33909331e47SGreg Roach            // Default constraint names are too long for MySQL.
34009331e47SGreg Roach            $key0 = DB::connection()->getTablePrefix() . $table->getTable() . '_primary';
34109331e47SGreg Roach            $key1 = DB::connection()->getTablePrefix() . $table->getTable() . '_ix1';
34209331e47SGreg Roach
34309331e47SGreg Roach            $table->primary(['module_name', 'gedcom_id', 'component'], $key0);
34409331e47SGreg Roach            $table->unique(['gedcom_id', 'module_name', 'component'], $key1);
345c9beb871SGreg Roach
346c9beb871SGreg Roach            $table->foreign('module_name')->references('module_name')->on('module');
347c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
348c9beb871SGreg Roach        });
349c9beb871SGreg Roach
3500b5fd0a6SGreg Roach        DB::schema()->create('block', static function (Blueprint $table): void {
351c9beb871SGreg Roach            $table->integer('block_id', true);
352c9beb871SGreg Roach            $table->integer('gedcom_id')->nullable();
353c9beb871SGreg Roach            $table->integer('user_id')->nullable();
354c9beb871SGreg Roach            $table->string('xref', 20)->nullable();
355c9beb871SGreg Roach            $table->enum('location', ['main', 'side'])->nullable();
356c9beb871SGreg Roach            $table->integer('block_order');
357c9beb871SGreg Roach            $table->string('module_name', 32);
358c9beb871SGreg Roach
359c9beb871SGreg Roach            $table->index('module_name');
360c9beb871SGreg Roach            $table->index('gedcom_id');
361c9beb871SGreg Roach            $table->index('user_id');
362c9beb871SGreg Roach
363c9beb871SGreg Roach            $table->foreign('module_name')->references('module_name')->on('module');
364c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
365c9beb871SGreg Roach            $table->foreign('user_id')->references('user_id')->on('user');
366c9beb871SGreg Roach        });
367c9beb871SGreg Roach
3680b5fd0a6SGreg Roach        DB::schema()->create('block_setting', static function (Blueprint $table): void {
369c9beb871SGreg Roach            $table->integer('block_id');
370c9beb871SGreg Roach            $table->string('setting_name', 32);
371c9beb871SGreg Roach            $table->longText('setting_value');
372c9beb871SGreg Roach
373c9beb871SGreg Roach            $table->primary(['block_id', 'setting_name']);
374c9beb871SGreg Roach
375c9beb871SGreg Roach            $table->foreign('block_id')->references('block_id')->on('block');
376c9beb871SGreg Roach        });
377c9beb871SGreg Roach
3780b5fd0a6SGreg Roach        DB::schema()->create('hit_counter', static function (Blueprint $table): void {
379c9beb871SGreg Roach            $table->integer('gedcom_id');
380c9beb871SGreg Roach            $table->string('page_name', 32);
381c9beb871SGreg Roach            $table->string('page_parameter', 32);
382c9beb871SGreg Roach            $table->integer('page_count');
383c9beb871SGreg Roach
38409331e47SGreg Roach            // Default constraint names are too long for MySQL.
38509331e47SGreg Roach            $key = DB::connection()->getTablePrefix() . $table->getTable() . '_primary';
38609331e47SGreg Roach
38709331e47SGreg Roach            $table->primary(['gedcom_id', 'page_name', 'page_parameter'], $key);
388c9beb871SGreg Roach
389c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
390c9beb871SGreg Roach        });
391c9beb871SGreg Roach
3920b5fd0a6SGreg Roach        DB::schema()->create('session', static function (Blueprint $table): void {
393c9beb871SGreg Roach            $table->string('session_id', 32);
394c9beb871SGreg Roach            $table->timestamp('session_time')->useCurrent();
395c9beb871SGreg Roach            $table->integer('user_id');
396c9beb871SGreg Roach            $table->ipAddress('ip_address');
397*736b8b72SGreg Roach            $table->longText('session_data');
398c9beb871SGreg Roach
399c9beb871SGreg Roach            $table->primary('session_id');
400c9beb871SGreg Roach            $table->index('session_time');
401c9beb871SGreg Roach            $table->index(['user_id', 'ip_address']);
402c9beb871SGreg Roach        });
403c9beb871SGreg Roach
4040b5fd0a6SGreg Roach        DB::schema()->create('gedcom_chunk', static function (Blueprint $table): void {
405c9beb871SGreg Roach            $table->integer('gedcom_chunk_id', true);
406c9beb871SGreg Roach            $table->integer('gedcom_id');
407*736b8b72SGreg Roach            $table->longText('chunk_data');
408c9beb871SGreg Roach            $table->boolean('imported')->default(0);
409c9beb871SGreg Roach
410c9beb871SGreg Roach            $table->index(['gedcom_id', 'imported']);
411c9beb871SGreg Roach
412c9beb871SGreg Roach            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom');
413c9beb871SGreg Roach        });
4143bfb94b0SGreg Roach    }
4153bfb94b0SGreg Roach}
416