1: | <?php |
2: | |
3: | use Illuminate\Database\Migrations\Migration; |
4: | use Illuminate\Database\Schema\Blueprint; |
5: | use Illuminate\Database\Capsule\Manager as Capsule; |
6: | |
7: | class CreateCoreFulltextIndexes extends Migration |
8: | { |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | public function up() |
15: | { |
16: | $prefix = Capsule::connection()->getTablePrefix(); |
17: | $sm = Capsule::connection()->getDoctrineSchemaManager(); |
18: | |
19: | Capsule::schema()->table('core_groups', function (Blueprint $table) use ($prefix, $sm) { |
20: | $doctrineTable = $sm->listTableDetails($prefix . 'core_groups'); |
21: | if (!$doctrineTable->hasIndex('core_groups_tenantid_index')) { |
22: | $table->index(['TenantId']); |
23: | } |
24: | if (!$doctrineTable->hasIndex('ccore_groups_name_index')) { |
25: | Capsule::statement("CREATE FULLTEXT INDEX ccore_groups_name_index ON {$prefix}core_groups (Name)"); |
26: | } |
27: | }); |
28: | Capsule::schema()->table('core_auth_tokens', function (Blueprint $table) use ($prefix, $sm) { |
29: | $doctrineTable = $sm->listTableDetails($prefix . 'core_auth_tokens'); |
30: | if (!$doctrineTable->hasIndex('core_auth_tokens_userid_index')) { |
31: | $table->index(['UserId']); |
32: | } |
33: | }); |
34: | Capsule::schema()->table('core_min_hashes', function (Blueprint $table) use ($prefix, $sm) { |
35: | $doctrineTable = $sm->listTableDetails($prefix . 'core_min_hashes'); |
36: | if (!$doctrineTable->hasIndex('core_min_hashes_userid_index')) { |
37: | $table->index(['UserId']); |
38: | } |
39: | }); |
40: | $doctrineTable = $sm->listTableDetails($prefix . 'core_tenants'); |
41: | if (!$doctrineTable->hasIndex('ccore_tenants_name_index')) { |
42: | Capsule::statement("CREATE FULLTEXT INDEX ccore_tenants_name_index ON {$prefix}core_tenants (Name)"); |
43: | } |
44: | } |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | public function down() |
52: | { |
53: | Capsule::schema()->table('core_tenants', function (Blueprint $table) { |
54: | $table->dropIndex('ccore_tenants_name_index'); |
55: | }); |
56: | Capsule::schema()->table('core_groups', function (Blueprint $table) { |
57: | $table->dropIndex(['TenantId']); |
58: | $table->dropIndex('ccore_groups_name_index'); |
59: | }); |
60: | Capsule::schema()->table('core_auth_tokens', function (Blueprint $table) { |
61: | $table->dropIndex(['UserId']); |
62: | }); |
63: | Capsule::schema()->table('core_min_hashes', function (Blueprint $table) { |
64: | $table->dropIndex(['UserId']); |
65: | }); |
66: | } |
67: | } |
68: | |