1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Schema; 19 20use Illuminate\Database\Capsule\Manager as DB; 21use Illuminate\Database\Query\Builder; 22use Illuminate\Database\Schema\Blueprint; 23 24/** 25 * Upgrade the database schema from version 37 to version 38. 26 */ 27class Migration37 implements MigrationInterface 28{ 29 /** 30 * Upgrade to to the next version 31 * 32 * @return void 33 */ 34 public function upgrade(): void 35 { 36 // These tables were created by webtrees 1.x, and may not exist if we first installed webtrees 2.x 37 DB::schema()->dropIfExists('site_access_rule'); 38 DB::schema()->dropIfExists('next_id'); 39 40 // Split the media table into media/media_file so that we can store multiple media 41 // files in each media object. 42 DB::schema()->create('media_file', function (Blueprint $table): void { 43 $table->integer('id', true); 44 $table->string('m_id', 20); 45 $table->integer('m_file'); 46 $table->string('multimedia_file_refn', 512); // GEDCOM only allows 30 characters 47 $table->string('multimedia_format', 4); 48 $table->string('source_media_type', 15); 49 $table->string('descriptive_title', 248); 50 51 $table->index(['m_id', 'm_file']); 52 $table->index(['m_file', 'm_id']); 53 $table->index(['m_file', 'multimedia_file_refn']); 54 $table->index(['m_file', 'multimedia_format']); 55 $table->index(['m_file', 'source_media_type']); 56 $table->index(['m_file', 'descriptive_title']); 57 58 // Need to set row format so that we can index fields longer than 255 characters. 59 $table->engine = 'InnoDB ROW_FORMAT=COMPRESSED'; 60 }); 61 62 if (DB::schema()->hasColumn('media', 'm_filename')) { 63 (new Builder(DB::connection()))->from('media_file')->insertUsing([ 64 'm_id', 65 'm_file', 66 'multimedia_file_refn', 67 'multimedia_format', 68 'source_media_type', 69 'descriptive_title', 70 ], function (Builder $query): void { 71 $query->select([ 72 'm_id', 73 'm_file', 74 'm_filename', 75 'm_ext', 76 'm_type', 77 'm_titl', 78 ])->from('media'); 79 }); 80 81 // SQLite can only drop one column at a time. 82 DB::schema()->table('media', function (Blueprint $table): void { 83 $table->dropColumn('m_filename'); 84 }); 85 DB::schema()->table('media', function (Blueprint $table): void { 86 $table->dropColumn('m_ext'); 87 }); 88 DB::schema()->table('media', function (Blueprint $table): void { 89 $table->dropColumn('m_type'); 90 }); 91 DB::schema()->table('media', function (Blueprint $table): void { 92 $table->dropColumn('m_titl'); 93 }); 94 } 95 } 96} 97