mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-06 10:44:33 +08:00
Removed old fulltext indexes from migrations
Prevents forcing of MyISAM for some databases Removed old code to add indexes and added checks for existing indexes before removal. Should still allow upgrades, rollbacks to old bookstack versions may be funky but should not be high use-case.
This commit is contained in:
@ -12,13 +12,7 @@ class CreateBooksTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$pdo = \DB::connection()->getPdo();
|
||||
$mysqlVersion = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
$requiresISAM = strpos($mysqlVersion, '5.5') === 0;
|
||||
|
||||
Schema::create('books', function (Blueprint $table) use ($requiresISAM) {
|
||||
if($requiresISAM) $table->engine = 'MyISAM';
|
||||
|
||||
Schema::create('books', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->string('slug')->indexed();
|
||||
|
@ -12,13 +12,9 @@ class CreatePagesTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$pdo = \DB::connection()->getPdo();
|
||||
$mysqlVersion = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
$requiresISAM = strpos($mysqlVersion, '5.5') === 0;
|
||||
|
||||
Schema::create('pages', function (Blueprint $table) use ($requiresISAM) {
|
||||
if($requiresISAM) $table->engine = 'MyISAM';
|
||||
|
||||
|
||||
Schema::create('pages', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('book_id');
|
||||
$table->integer('chapter_id');
|
||||
|
@ -12,12 +12,7 @@ class CreateChaptersTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$pdo = \DB::connection()->getPdo();
|
||||
$mysqlVersion = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
$requiresISAM = strpos($mysqlVersion, '5.5') === 0;
|
||||
|
||||
Schema::create('chapters', function (Blueprint $table) use ($requiresISAM) {
|
||||
if($requiresISAM) $table->engine = 'MyISAM';
|
||||
Schema::create('chapters', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('book_id');
|
||||
$table->string('slug')->indexed();
|
||||
|
@ -12,10 +12,13 @@ class AddSearchIndexes extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$prefix = DB::getTablePrefix();
|
||||
DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
|
||||
DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
|
||||
DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
|
||||
// This was removed for v0.24 since these indexes are removed anyway
|
||||
// and will cause issues for db engines that don't support such indexes.
|
||||
|
||||
// $prefix = DB::getTablePrefix();
|
||||
// DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
|
||||
// DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
|
||||
// DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,14 +28,28 @@ class AddSearchIndexes extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('pages', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
});
|
||||
Schema::table('books', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
});
|
||||
Schema::table('chapters', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
});
|
||||
$sm = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$pages = $sm->listTableDetails('pages');
|
||||
$books = $sm->listTableDetails('books');
|
||||
$chapters = $sm->listTableDetails('chapters');
|
||||
|
||||
if ($pages->hasIndex('search')) {
|
||||
Schema::table('pages', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
});
|
||||
}
|
||||
|
||||
if ($books->hasIndex('search')) {
|
||||
Schema::table('books', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
});
|
||||
}
|
||||
|
||||
if ($chapters->hasIndex('search')) {
|
||||
Schema::table('chapters', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,13 @@ class FulltextWeighting extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$prefix = DB::getTablePrefix();
|
||||
DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT name_search(name)");
|
||||
DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT name_search(name)");
|
||||
DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT name_search(name)");
|
||||
// This was removed for v0.24 since these indexes are removed anyway
|
||||
// and will cause issues for db engines that don't support such indexes.
|
||||
|
||||
// $prefix = DB::getTablePrefix();
|
||||
// DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT name_search(name)");
|
||||
// DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT name_search(name)");
|
||||
// DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT name_search(name)");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,14 +28,27 @@ class FulltextWeighting extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('pages', function(Blueprint $table) {
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
Schema::table('books', function(Blueprint $table) {
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
Schema::table('chapters', function(Blueprint $table) {
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
$sm = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$pages = $sm->listTableDetails('pages');
|
||||
$books = $sm->listTableDetails('books');
|
||||
$chapters = $sm->listTableDetails('chapters');
|
||||
|
||||
if ($pages->hasIndex('name_search')) {
|
||||
Schema::table('pages', function(Blueprint $table) {
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
}
|
||||
|
||||
if ($books->hasIndex('name_search')) {
|
||||
Schema::table('books', function(Blueprint $table) {
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
}
|
||||
|
||||
if ($chapters->hasIndex('name_search')) {
|
||||
Schema::table('chapters', function(Blueprint $table) {
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,19 +26,31 @@ class CreateSearchIndexTable extends Migration
|
||||
$table->index('score');
|
||||
});
|
||||
|
||||
// Drop search indexes
|
||||
Schema::table('pages', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
Schema::table('books', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
Schema::table('chapters', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
$sm = Schema::getConnection()->getDoctrineSchemaManager();
|
||||
$pages = $sm->listTableDetails('pages');
|
||||
$books = $sm->listTableDetails('books');
|
||||
$chapters = $sm->listTableDetails('chapters');
|
||||
|
||||
if ($pages->hasIndex('search')) {
|
||||
Schema::table('pages', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
}
|
||||
|
||||
if ($books->hasIndex('search')) {
|
||||
Schema::table('books', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
}
|
||||
|
||||
if ($chapters->hasIndex('search')) {
|
||||
Schema::table('chapters', function(Blueprint $table) {
|
||||
$table->dropIndex('search');
|
||||
$table->dropIndex('name_search');
|
||||
});
|
||||
}
|
||||
|
||||
app(\BookStack\Services\SearchService::class)->indexAllEntities();
|
||||
}
|
||||
@ -50,14 +62,17 @@ class CreateSearchIndexTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$prefix = DB::getTablePrefix();
|
||||
DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
|
||||
DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
|
||||
DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
|
||||
DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT name_search(name)");
|
||||
DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT name_search(name)");
|
||||
DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT name_search(name)");
|
||||
// This was removed for v0.24 since these indexes are removed anyway
|
||||
// and will cause issues for db engines that don't support such indexes.
|
||||
|
||||
// $prefix = DB::getTablePrefix();
|
||||
// DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
|
||||
// DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
|
||||
// DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
|
||||
// DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT name_search(name)");
|
||||
// DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT name_search(name)");
|
||||
// DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT name_search(name)");
|
||||
|
||||
Schema::dropIfExists('search_terms');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user