3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\DB;
6 use Illuminate\Support\Facades\Schema;
8 return new class extends Migration
13 public function up(): void
15 Schema::create('search_terms', function (Blueprint $table) {
16 $table->increments('id');
17 $table->string('term', 180);
18 $table->string('entity_type', 100);
19 $table->integer('entity_id');
20 $table->integer('score');
22 $table->index('term');
23 $table->index('entity_type');
24 $table->index(['entity_type', 'entity_id']);
25 $table->index('score');
28 $sm = Schema::getConnection()->getDoctrineSchemaManager();
29 $prefix = DB::getTablePrefix();
30 $pages = $sm->introspectTable($prefix . 'pages');
31 $books = $sm->introspectTable($prefix . 'books');
32 $chapters = $sm->introspectTable($prefix . 'chapters');
34 if ($pages->hasIndex('search')) {
35 Schema::table('pages', function (Blueprint $table) {
36 $table->dropIndex('search');
37 $table->dropIndex('name_search');
41 if ($books->hasIndex('search')) {
42 Schema::table('books', function (Blueprint $table) {
43 $table->dropIndex('search');
44 $table->dropIndex('name_search');
48 if ($chapters->hasIndex('search')) {
49 Schema::table('chapters', function (Blueprint $table) {
50 $table->dropIndex('search');
51 $table->dropIndex('name_search');
57 * Reverse the migrations.
59 public function down(): void
61 // This was removed for v0.24 since these indexes are removed anyway
62 // and will cause issues for db engines that don't support such indexes.
64 // $prefix = DB::getTablePrefix();
65 // DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
66 // DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
67 // DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
68 // DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT name_search(name)");
69 // DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT name_search(name)");
70 // DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT name_search(name)");
72 Schema::dropIfExists('search_terms');