]> BookStack Code Mirror - bookstack/blob - database/migrations/2015_08_31_175240_add_search_indexes.php
Migrations: Updated with type hints instead of php doc
[bookstack] / database / migrations / 2015_08_31_175240_add_search_indexes.php
1 <?php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
6
7 return new class extends Migration
8 {
9     /**
10      * Run the migrations.
11      */
12     public function up()
13     {
14         // This was removed for v0.24 since these indexes are removed anyway
15         // and will cause issues for db engines that don't support such indexes.
16
17 //        $prefix = DB::getTablePrefix();
18 //        DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)");
19 //        DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)");
20 //        DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)");
21     }
22
23     /**
24      * Reverse the migrations.
25      */
26     public function down(): void
27     {
28         $sm = Schema::getConnection()->getDoctrineSchemaManager();
29         $pages = $sm->listTableDetails('pages');
30         $books = $sm->listTableDetails('books');
31         $chapters = $sm->listTableDetails('chapters');
32
33         if ($pages->hasIndex('search')) {
34             Schema::table('pages', function (Blueprint $table) {
35                 $table->dropIndex('search');
36             });
37         }
38
39         if ($books->hasIndex('search')) {
40             Schema::table('books', function (Blueprint $table) {
41                 $table->dropIndex('search');
42             });
43         }
44
45         if ($chapters->hasIndex('search')) {
46             Schema::table('chapters', function (Blueprint $table) {
47                 $table->dropIndex('search');
48             });
49         }
50     }
51 };