Skip to content

Commit

Permalink
Update migrations to properly create fulltext indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Feb 9, 2018
1 parent a401d5e commit 603efb3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 28 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
}


Expand Down
3 changes: 2 additions & 1 deletion database/migrations/2018_01_20_195934_create_predb_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
Expand Down
23 changes: 1 addition & 22 deletions database/migrations/2018_01_22_215526_add_triggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;');
}
}

0 comments on commit 603efb3

Please sign in to comment.