|
12 | 12 |
|
13 | 13 | class IndexOptionsTest extends TestCase
|
14 | 14 | {
|
| 15 | + public function testIfNotExistsFulltextByColumn(): void |
| 16 | + { |
| 17 | + if (Comparator::lessThan($this->app->version(), '8.74.0')) { |
| 18 | + $this->markTestSkipped('Fulltext indexes have been added in a later Laraverl version.'); |
| 19 | + } |
| 20 | + |
| 21 | + Schema::create('test_806712', function (Blueprint $table): void { |
| 22 | + $table->string('col_274742'); |
| 23 | + }); |
| 24 | + $queries = $this->withQueryLog(function (): void { |
| 25 | + Schema::table('test_806712', function (Blueprint $table): void { |
| 26 | + $table->fullText(['col_274742'])->ifNotExists(); |
| 27 | + }); |
| 28 | + }); |
| 29 | + $this->assertEquals(['create index if not exists "test_806712_col_274742_fulltext" on "test_806712" using gin ((to_tsvector(\'english\', "col_274742")))'], array_column($queries, 'query')); |
| 30 | + } |
| 31 | + |
| 32 | + public function testIfNotExistsFulltextByName(): void |
| 33 | + { |
| 34 | + if (Comparator::lessThan($this->app->version(), '8.74.0')) { |
| 35 | + $this->markTestSkipped('Fulltext indexes have been added in a later Laraverl version.'); |
| 36 | + } |
| 37 | + |
| 38 | + Schema::create('test_940928', function (Blueprint $table): void { |
| 39 | + $table->string('col_563370'); |
| 40 | + }); |
| 41 | + $queries = $this->withQueryLog(function (): void { |
| 42 | + Schema::table('test_940928', function (Blueprint $table): void { |
| 43 | + $table->fullText(['col_563370'], 'index_726055')->ifNotExists(); |
| 44 | + }); |
| 45 | + }); |
| 46 | + $this->assertEquals(['create index if not exists "index_726055" on "test_940928" using gin ((to_tsvector(\'english\', "col_563370")))'], array_column($queries, 'query')); |
| 47 | + } |
| 48 | + |
| 49 | + public function testIfNotExistsIndexByColumn(): void |
| 50 | + { |
| 51 | + Schema::create('test_233704', function (Blueprint $table): void { |
| 52 | + $table->string('col_484213'); |
| 53 | + }); |
| 54 | + $queries = $this->withQueryLog(function (): void { |
| 55 | + Schema::table('test_233704', function (Blueprint $table): void { |
| 56 | + $table->index(['col_484213'])->ifNotExists(); |
| 57 | + }); |
| 58 | + }); |
| 59 | + $this->assertEquals(['create index if not exists "test_233704_col_484213_index" on "test_233704" ("col_484213")'], array_column($queries, 'query')); |
| 60 | + } |
| 61 | + |
| 62 | + public function testIfNotExistsIndexByName(): void |
| 63 | + { |
| 64 | + Schema::create('test_101004', function (Blueprint $table): void { |
| 65 | + $table->string('col_749919'); |
| 66 | + }); |
| 67 | + $queries = $this->withQueryLog(function (): void { |
| 68 | + Schema::table('test_101004', function (Blueprint $table): void { |
| 69 | + $table->index(['col_749919'], 'index_605253')->ifNotExists(); |
| 70 | + }); |
| 71 | + }); |
| 72 | + $this->assertEquals(['create index if not exists "index_605253" on "test_101004" ("col_749919")'], array_column($queries, 'query')); |
| 73 | + } |
| 74 | + |
| 75 | + public function testIfNotExistsRawIndex(): void |
| 76 | + { |
| 77 | + if (Comparator::lessThan($this->app->version(), '7.7.0')) { |
| 78 | + $this->markTestSkipped('Raw indexes have been added in a later Laravel version.'); |
| 79 | + } |
| 80 | + |
| 81 | + Schema::create('test_302103', function (Blueprint $table): void { |
| 82 | + $table->string('col_650398'); |
| 83 | + }); |
| 84 | + $queries = $this->withQueryLog(function (): void { |
| 85 | + Schema::table('test_302103', function (Blueprint $table): void { |
| 86 | + $table->rawIndex('col_650398', 'idx_728687')->ifNotExists(); |
| 87 | + }); |
| 88 | + }); |
| 89 | + $this->assertEquals(['create index if not exists "idx_728687" on "test_302103" (col_650398)'], array_column($queries, 'query')); |
| 90 | + } |
| 91 | + |
| 92 | + public function testIfNotExistsSpatialIndexByColumn(): void |
| 93 | + { |
| 94 | + Schema::create('test_508190', function (Blueprint $table): void { |
| 95 | + $table->integerRange('col_402778'); |
| 96 | + }); |
| 97 | + $queries = $this->withQueryLog(function (): void { |
| 98 | + Schema::table('test_508190', function (Blueprint $table): void { |
| 99 | + $table->spatialIndex(['col_402778'])->ifNotExists(); |
| 100 | + }); |
| 101 | + }); |
| 102 | + $this->assertEquals(['create index if not exists "test_508190_col_402778_spatialindex" on "test_508190" using gist ("col_402778")'], array_column($queries, 'query')); |
| 103 | + } |
| 104 | + |
| 105 | + public function testIfNotExistsSpatialIndexByName(): void |
| 106 | + { |
| 107 | + Schema::create('test_521621', function (Blueprint $table): void { |
| 108 | + $table->integerRange('col_990392'); |
| 109 | + }); |
| 110 | + $queries = $this->withQueryLog(function (): void { |
| 111 | + Schema::table('test_521621', function (Blueprint $table): void { |
| 112 | + $table->spatialIndex(['col_990392'], 'index_124848')->ifNotExists(); |
| 113 | + }); |
| 114 | + }); |
| 115 | + $this->assertEquals(['create index if not exists "index_124848" on "test_521621" using gist ("col_990392")'], array_column($queries, 'query')); |
| 116 | + } |
| 117 | + |
| 118 | + public function testIfNotExistsUniqueIndexByColumn(): void |
| 119 | + { |
| 120 | + Schema::create('test_868599', function (Blueprint $table): void { |
| 121 | + $table->string('col_571721'); |
| 122 | + }); |
| 123 | + $queries = $this->withQueryLog(function (): void { |
| 124 | + Schema::table('test_868599', function (Blueprint $table): void { |
| 125 | + $table->uniqueIndex(['col_571721'])->ifNotExists(); |
| 126 | + }); |
| 127 | + }); |
| 128 | + $this->assertEquals(['create unique index if not exists "test_868599_col_571721_unique" on "test_868599" ("col_571721")'], array_column($queries, 'query')); |
| 129 | + } |
| 130 | + |
| 131 | + public function testIfNotExistsUniqueIndexByName(): void |
| 132 | + { |
| 133 | + Schema::create('test_324400', function (Blueprint $table): void { |
| 134 | + $table->string('col_208151'); |
| 135 | + }); |
| 136 | + $queries = $this->withQueryLog(function (): void { |
| 137 | + Schema::table('test_324400', function (Blueprint $table): void { |
| 138 | + $table->uniqueIndex(['col_208151'], 'index_810276')->ifNotExists(); |
| 139 | + }); |
| 140 | + }); |
| 141 | + $this->assertEquals(['create unique index if not exists "index_810276" on "test_324400" ("col_208151")'], array_column($queries, 'query')); |
| 142 | + } |
| 143 | + |
15 | 144 | public function testIncludeIndexByColumn(): void
|
16 | 145 | {
|
17 | 146 | Schema::create('test_130163', function (Blueprint $table): void {
|
|
0 commit comments