Skip to content

Commit c1caceb

Browse files
committed
Cover migration connection behavior
1 parent e9caffe commit c1caceb

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

database/migrations/2019_15_12_112000_create_opensearch_migrations_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create(config('opensearch-migrations.table'), function (Blueprint $table) {
14+
Schema::connection(config('opensearch-migrations.connection'))->create(config('opensearch-migrations.table'), function (Blueprint $table) {
1515
$table->increments('id');
1616
$table->string('migration');
1717
$table->integer('batch');
@@ -23,6 +23,6 @@ public function up(): void
2323
*/
2424
public function down(): void
2525
{
26-
Schema::dropIfExists(config('opensearch-migrations.table'));
26+
Schema::connection(config('opensearch-migrations.connection'))->dropIfExists(config('opensearch-migrations.table'));
2727
}
2828
};

tests/Integration/Adapters/IndexManagerAdapterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public function test_index_can_be_dropped_only_if_exists(string $indexPrefix): v
207207
#[DataProvider('prefixProvider')]
208208
public function test_alias_can_be_created(string $aliasNamePrefix): void
209209
{
210+
$this->app['config']->set('opensearch-migrations.index_name_prefix', $aliasNamePrefix);
210211
$this->app['config']->set('opensearch-migrations.alias_name_prefix', $aliasNamePrefix);
211212

212213
$index = 'foo';
@@ -215,14 +216,15 @@ public function test_alias_can_be_created(string $aliasNamePrefix): void
215216
$this->indexManagerMock
216217
->expects($this->once())
217218
->method('putAlias')
218-
->with($index, new Alias($aliasNamePrefix.$aliasName));
219+
->with($aliasNamePrefix.$index, new Alias($aliasNamePrefix.$aliasName));
219220

220221
$this->indexManagerAdapter->putAlias($index, $aliasName);
221222
}
222223

223224
#[DataProvider('prefixProvider')]
224225
public function test_alias_can_be_deleted(string $aliasNamePrefix): void
225226
{
227+
$this->app['config']->set('opensearch-migrations.index_name_prefix', $aliasNamePrefix);
226228
$this->app['config']->set('opensearch-migrations.alias_name_prefix', $aliasNamePrefix);
227229

228230
$index = 'foo';
@@ -231,7 +233,7 @@ public function test_alias_can_be_deleted(string $aliasNamePrefix): void
231233
$this->indexManagerMock
232234
->expects($this->once())
233235
->method('deleteAlias')
234-
->with($index, $aliasNamePrefix.$aliasName);
236+
->with($aliasNamePrefix.$index, $aliasNamePrefix.$aliasName);
235237

236238
$this->indexManagerAdapter->deleteAlias($index, $aliasName);
237239
}

tests/Integration/Repositories/MigrationRepositoryTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ public function test_repository_table_matches_laravel_migration_table_structure(
6060
$this->assertSame(3, DB::table($this->table)->max('id'));
6161
}
6262

63+
public function test_repository_table_migration_uses_configured_database_connection(): void
64+
{
65+
$this->app['config']->set('database.connections.opensearch_migrations', [
66+
'driver' => 'sqlite',
67+
'database' => ':memory:',
68+
]);
69+
70+
$this->app['config']->set('opensearch-migrations.connection', 'opensearch_migrations');
71+
$this->app['config']->set('opensearch-migrations.table', 'custom_opensearch_migrations');
72+
73+
$migration = require dirname(__DIR__, 3).'/database/migrations/2019_15_12_112000_create_opensearch_migrations_table.php';
74+
75+
$migration->up();
76+
77+
$this->assertFalse(Schema::hasTable('custom_opensearch_migrations'));
78+
$this->assertTrue(Schema::connection('opensearch_migrations')->hasTable('custom_opensearch_migrations'));
79+
80+
$migration->down();
81+
82+
$this->assertFalse(Schema::connection('opensearch_migrations')->hasTable('custom_opensearch_migrations'));
83+
}
84+
6385
public function test_record_passes_existence_check(): void
6486
{
6587
$this->assertTrue($this->migrationRepository->exists('2018_12_01_081000_create_test_index'));

tests/Integration/Support/PrefixTest.php renamed to tests/Integration/Support/MigrationPrefixTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use DirectoryTree\OpenSearchMigrations\Support\MigrationPrefix;
66
use DirectoryTree\OpenSearchMigrations\Tests\Integration\TestCase;
77

8-
class PrefixTest extends TestCase
8+
class MigrationPrefixTest extends TestCase
99
{
1010
public function test_index_names_can_be_prefixed(): void
1111
{

0 commit comments

Comments
 (0)