From 603efb3381dc9d10210ad509b4e3b7d67cd88715 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 9 Feb 2018 09:00:41 +0100 Subject: [PATCH] Update migrations to properly create fulltext indexes --- Changelog | 1 + ...018_01_20_195703_create_bookinfo_table.php | 2 +- ..._01_20_195716_create_consoleinfo_table.php | 2 +- ...18_01_20_195832_create_musicinfo_table.php | 1 + .../2018_01_20_195934_create_predb_table.php | 3 ++- ...00113_create_release_search_data_table.php | 6 ++--- .../2018_01_22_215526_add_triggers.php | 23 +------------------ 7 files changed, 10 insertions(+), 28 deletions(-) diff --git a/Changelog b/Changelog index 92a6c4bfa2..daa897a4fb 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-02-09 DariusIII + * Chg: Update migrations to properly create fulltext indexes * Mrg: Merge PR #380 by nightah - Properly escape release_naming_regexes 33-35 2018-02-08 DariusIII * Chg: Remove unused parameter from NameFixer class diff --git a/database/migrations/2018_01_20_195703_create_bookinfo_table.php b/database/migrations/2018_01_20_195703_create_bookinfo_table.php index de50ce66a0..34d9a3b7f7 100644 --- a/database/migrations/2018_01_20_195703_create_bookinfo_table.php +++ b/database/migrations/2018_01_20_195703_create_bookinfo_table.php @@ -29,8 +29,8 @@ public function up() $table->string('genre'); $table->boolean('cover')->default(0); $table->timestamps(); - $table->index(['author','title'], 'ix_bookinfo_author_title_ft'); }); + DB::statement('ALTER TABLE bookinfo ADD FULLTEXT ix_bookinfo_author_title_ft (author, title)'); } diff --git a/database/migrations/2018_01_20_195716_create_consoleinfo_table.php b/database/migrations/2018_01_20_195716_create_consoleinfo_table.php index 1a4eb2e432..ae7347776c 100644 --- a/database/migrations/2018_01_20_195716_create_consoleinfo_table.php +++ b/database/migrations/2018_01_20_195716_create_consoleinfo_table.php @@ -27,8 +27,8 @@ public function up() $table->string('review', 3000)->nullable(); $table->boolean('cover')->default(0); $table->timestamps(); - $table->index(['title','platform'], 'ix_consoleinfo_title_platform_ft'); }); + DB::statement('ALTER TABLE consoleinfo ADD FULLTEXT ix_consoleinfo_title_platform_ft (title, platform)'); } diff --git a/database/migrations/2018_01_20_195832_create_musicinfo_table.php b/database/migrations/2018_01_20_195832_create_musicinfo_table.php index f1dd5196c9..da0685be60 100644 --- a/database/migrations/2018_01_20_195832_create_musicinfo_table.php +++ b/database/migrations/2018_01_20_195832_create_musicinfo_table.php @@ -30,6 +30,7 @@ public function up() $table->timestamps(); $table->index(['artist','title'], 'ix_musicinfo_artist_title_ft'); }); + DB::statement('ALTER TABLE musicinfo ADD FULLTEXT ix_musicinfo_artist_title_ft (artist, title)'); } diff --git a/database/migrations/2018_01_20_195934_create_predb_table.php b/database/migrations/2018_01_20_195934_create_predb_table.php index b2bf7d2b2c..4109c4cc08 100644 --- a/database/migrations/2018_01_20_195934_create_predb_table.php +++ b/database/migrations/2018_01_20_195934_create_predb_table.php @@ -26,10 +26,11 @@ public function up() $table->boolean('nuked')->default(0)->comment('Is this pre nuked? 0 no 2 yes 1 un nuked 3 mod nuked'); $table->string('nukereason')->nullable()->comment('If this pre is nuked, what is the reason?'); $table->string('files', 50)->nullable()->comment('How many files does this pre have ?'); - $table->string('filename')->default('')->index('ft_predb_filename'); + $table->string('filename')->default(''); $table->boolean('searched')->default(0)->index('ix_predb_searched'); $table->index(['requestid','groups_id'], 'ix_predb_requestid'); }); + DB::statement('ALTER TABLE predb ADD FULLTEXT ft_predb_filename (filename)'); } diff --git a/database/migrations/2018_01_20_200113_create_release_search_data_table.php b/database/migrations/2018_01_20_200113_create_release_search_data_table.php index 20760e1c11..b4a556e3b0 100644 --- a/database/migrations/2018_01_20_200113_create_release_search_data_table.php +++ b/database/migrations/2018_01_20_200113_create_release_search_data_table.php @@ -17,9 +17,9 @@ public function up() $table->increments('id'); $table->integer('releases_id')->unsigned()->index('ix_releasesearch_releases_id')->comment('FK to releases.id'); $table->string('guid', 50)->index('ix_releasesearch_guid'); - $table->string('name')->default('')->index('ix_releasesearch_name_ft'); - $table->string('searchname')->default('')->index('ix_releasesearch_searchname_ft'); - $table->string('fromname')->nullable()->index('ix_releasesearch_fromname_ft'); + $table->string('name')->default(''); + $table->string('searchname')->default(''); + $table->string('fromname')->nullable(); $table->foreign('releases_id', 'FK_rsd_releases')->references('id')->on('releases')->onUpdate('CASCADE')->onDelete('CASCADE'); }); } diff --git a/database/migrations/2018_01_22_215526_add_triggers.php b/database/migrations/2018_01_22_215526_add_triggers.php index 5d84394d0b..84f74a958b 100644 --- a/database/migrations/2018_01_22_215526_add_triggers.php +++ b/database/migrations/2018_01_22_215526_add_triggers.php @@ -39,27 +39,6 @@ public function up() END IF; END; -CREATE TRIGGER insert_search AFTER INSERT ON releases FOR EACH ROW - BEGIN - INSERT INTO release_search_data (releases_id, guid, name, searchname, fromname) VALUES (NEW.id, NEW.guid, NEW.name, NEW.searchname, NEW.fromname); - END; - -CREATE TRIGGER update_search AFTER UPDATE ON releases FOR EACH ROW - BEGIN - IF NEW.guid != OLD.guid - THEN UPDATE release_search_data SET guid = NEW.guid WHERE releases_id = OLD.id; - END IF; - IF NEW.name != OLD.name - THEN UPDATE release_search_data SET name = NEW.name WHERE releases_id = OLD.id; - END IF; - IF NEW.searchname != OLD.searchname - THEN UPDATE release_search_data SET searchname = NEW.searchname WHERE releases_id = OLD.id; - END IF; - IF NEW.fromname != OLD.fromname - THEN UPDATE release_search_data SET fromname = NEW.fromname WHERE releases_id = OLD.id; - END IF; - END; - CREATE TRIGGER insert_hashes AFTER INSERT ON predb FOR EACH ROW BEGIN INSERT INTO predb_hashes (hash, predb_id) VALUES (UNHEX(MD5(NEW.title)), NEW.id), (UNHEX(MD5(MD5(NEW.title))), NEW.id), (UNHEX(SHA1(NEW.title)), NEW.id), (UNHEX(SHA2(NEW.title, 256)), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid))), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid, NEW.requestid))), NEW.id);END; CREATE TRIGGER update_hashes AFTER UPDATE ON predb FOR EACH ROW BEGIN IF NEW.title != OLD.title THEN DELETE FROM predb_hashes WHERE hash IN ( UNHEX(md5(OLD.title)), UNHEX(md5(md5(OLD.title))), UNHEX(sha1(OLD.title)), UNHEX(sha2(OLD.title, 256)), UNHEX(MD5(CONCAT(OLD.title, OLD.requestid)))) AND predb_id = OLD.id; INSERT INTO predb_hashes (hash, predb_id) VALUES (UNHEX(MD5(NEW.title)), NEW.id), (UNHEX(MD5(MD5(NEW.title))), NEW.id), (UNHEX(SHA1(NEW.title)), NEW.id), (UNHEX(SHA2(NEW.title, 256)), NEW.id), (UNHEX(MD5(CONCAT((NEW.title, NEW.requestid)))), NEW.id), (UNHEX(MD5(CONCAT(NEW.title, NEW.requestid, NEW.requestid))), NEW.id);END IF;END; @@ -79,6 +58,6 @@ public function up() */ public function down() { - DB::unprepared('DROP TRIGGER check_insert; DROP TRIGGER check_update; DROP TRIGGER check_rfinsert; DROP TRIGGER check_rfupdate; DROP TRIGGER insert_search; DROP TRIGGER update_search; DROP TRIGGER insert_hashes; DROP TRIGGER update_hashes; DROP TRIGGER delete_hashes; DROP TRIGGER insert_MD5;'); + DB::unprepared('DROP TRIGGER check_insert; DROP TRIGGER check_update; DROP TRIGGER check_rfinsert; DROP TRIGGER check_rfupdate; DROP TRIGGER insert_hashes; DROP TRIGGER update_hashes; DROP TRIGGER delete_hashes; DROP TRIGGER insert_MD5;'); } }