3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
7 return new class extends Migration
16 Schema::create('search_terms', function (Blueprint $table) {
17 $table->increments('id');
18 $table->string('term', 180);
19 $table->string('entity_type', 100);
20 $table->integer('entity_id');
21 $table->integer('score');
23 $table->index('term');
24 $table->index('entity_type');
25 $table->index(['entity_type', 'entity_id']);
26 $table->index('score');
29 $sm = Schema::getConnection()->getDoctrineSchemaManager();
30 $pages = $sm->listTableDetails('pages');
31 $books = $sm->listTableDetails('books');
32 $chapters = $sm->listTableDetails('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.
61 public function down()
63 // This was removed for v0.24 since these indexes are removed anyway
64 // and will cause issues for db engines that don't support such indexes.
66 // $prefix = DB::getTablePrefix();
67 // DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
68 // DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
69 // DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
70 // DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT name_search(name)");
71 // DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT name_search(name)");
72 // DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT name_search(name)");
74 Schema::dropIfExists('search_terms');