From 34d9530e1bb6657cb12d945e1e21dc02f30412e8 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 01:44:39 +0300 Subject: [PATCH 01/15] Fixed bug with transferring UUID and ULID as primary key --- .github/workflows/phpunit.yml | 6 ++- src/Console/Migrate.php | 4 +- tests/Concerns/Database.php | 4 ++ tests/Concerns/Seeders.php | 19 ++++++++ tests/Unit/MysqlToMysqlTest.php | 48 +++++++++++++++++++ tests/Unit/MysqlToPostgresTest.php | 48 +++++++++++++++++++ tests/Unit/PostgresToMysqlTest.php | 48 +++++++++++++++++++ tests/Unit/PostgresToPostgresTest.php | 48 +++++++++++++++++++ ...3_12_15_014834_create_ulid_primary_key.php | 19 ++++++++ ...3_12_15_014834_create_uuid_primary_key.php | 19 ++++++++ 10 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php create mode 100644 tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 5c742d9..e820f11 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -9,10 +9,14 @@ jobs: strategy: fail-fast: true matrix: - php: [ "8.0", "8.1", "8.2" ] + php: [ "8.0", "8.1", "8.2", "8.3" ] laravel: [ "8.0", "9.0", "10.0" ] psql: [ "9", "10", "11", "12", "13", "14", "15" ] exclude: + - laravel: "8.0" + php: "8.3" + - laravel: "9.0" + php: "8.3" - laravel: "10.0" php: "8.0" diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index e7ce144..04af680 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -159,7 +159,9 @@ protected function isSkippable(string $table, string $column): bool protected function isNumericColumn(string $table, string $column): bool { - return $this->getPrimaryKeyType($this->source(), $table, $column) !== 'string'; + $type = $this->getPrimaryKeyType($this->source(), $table, $column); + + return ! in_array($type, ['string', 'char'], true); } protected function tables(): array diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 0276edf..3c66940 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -27,6 +27,10 @@ trait Database protected $table_baz = 'baz'; + protected $ulid_key = 'ulid_key'; + + protected $uuid_key = 'uuid_key'; + protected $choice_target = 'target'; protected $choice_source = 'source'; diff --git a/tests/Concerns/Seeders.php b/tests/Concerns/Seeders.php index 0339d3c..cf733f0 100644 --- a/tests/Concerns/Seeders.php +++ b/tests/Concerns/Seeders.php @@ -3,6 +3,7 @@ namespace Tests\Concerns; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; trait Seeders { @@ -21,4 +22,22 @@ protected function fillTable(string $table): void ['value' => $table . '_3'], ]); } + + protected function fillUuidTable(string $table): void + { + DB::connection($this->source_connection)->table($table)->insert([ + ['value' => $table . '_1', 'uuid' => Str::uuid()->toString()], + ['value' => $table . '_2', 'uuid' => Str::uuid()->toString()], + ['value' => $table . '_3', 'uuid' => Str::uuid()->toString()], + ]); + } + + protected function fillUlidTable(string $table): void + { + DB::connection($this->source_connection)->table($table)->insert([ + ['value' => $table . '_1', 'ulid' => (string) Str::ulid()], + ['value' => $table . '_2', 'ulid' => (string) Str::ulid()], + ['value' => $table . '_3', 'ulid' => (string) Str::ulid()], + ]); + } } diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index b1a2978..2900f18 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -5,6 +5,7 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -230,6 +231,53 @@ public function testSame() ); } + public function testUuidAndUlidKeysAsPrimaryKey() + { + if (!method_exists(Blueprint::class, 'ulid')) { + $this->assertTrue(true); + + return; + } + + $this->fillUuidTable($this->uuid_key); + $this->fillUlidTable($this->ulid_key); + + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => [ + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', + ] + ])->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + public function testFailed() { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index 24b8253..eab7216 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -5,6 +5,7 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -230,6 +231,53 @@ public function testSame() ); } + public function testUuidAndUlidKeysAsPrimaryKey() + { + if (!method_exists(Blueprint::class, 'ulid')) { + $this->assertTrue(true); + + return; + } + + $this->fillUuidTable($this->uuid_key); + $this->fillUlidTable($this->ulid_key); + + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => [ + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', + ] + ])->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + public function testFailed() { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index 0c020d7..5bd3b2c 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -5,6 +5,7 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -230,6 +231,53 @@ public function testSame() ); } + public function testUuidAndUlidKeysAsPrimaryKey() + { + if (!method_exists(Blueprint::class, 'ulid')) { + $this->assertTrue(true); + + return; + } + + $this->fillUuidTable($this->uuid_key); + $this->fillUlidTable($this->ulid_key); + + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => [ + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', + ] + ])->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + public function testFailed() { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index a756b27..2136302 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -5,6 +5,7 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -230,6 +231,53 @@ public function testSame() ); } + public function testUuidAndUlidKeysAsPrimaryKey() + { + if (!method_exists(Blueprint::class, 'ulid')) { + $this->assertTrue(true); + + return; + } + + $this->fillUuidTable($this->uuid_key); + $this->fillUlidTable($this->ulid_key); + + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => [ + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', + __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', + ] + ])->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + public function testFailed() { $this->expectException(InvalidArgumentException::class); diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php b/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php new file mode 100644 index 0000000..752b9d8 --- /dev/null +++ b/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php @@ -0,0 +1,19 @@ +<?php + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; +use Tests\Concerns\Migration; + +class CreateUlidPrimaryKey extends Migration +{ + protected $table = 'ulid_key'; + + public function up() + { + Schema::create($this->table, function (Blueprint $table) { + $table->ulid()->primary(); + + $table->string('value'); + }); + } +} diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php b/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php new file mode 100644 index 0000000..bde0aef --- /dev/null +++ b/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php @@ -0,0 +1,19 @@ +<?php + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; +use Tests\Concerns\Migration; + +class CreateUuidPrimaryKey extends Migration +{ + protected $table = 'uuid_key'; + + public function up() + { + Schema::create($this->table, function (Blueprint $table) { + $table->uuid()->primary(); + + $table->string('value'); + }); + } +} From b2901ddc4c0f2559d8732099b61f84834d6c9903 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 14:46:13 +0300 Subject: [PATCH 02/15] Fixed tests --- tests/Unit/MysqlToMysqlTest.php | 53 +++++++++++++++++++-------- tests/Unit/MysqlToPostgresTest.php | 53 +++++++++++++++++++-------- tests/Unit/PostgresToMysqlTest.php | 53 +++++++++++++++++++-------- tests/Unit/PostgresToPostgresTest.php | 53 +++++++++++++++++++-------- 4 files changed, 152 insertions(+), 60 deletions(-) diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index 2900f18..66dbd8a 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -231,33 +231,60 @@ public function testSame() ); } - public function testUuidAndUlidKeysAsPrimaryKey() + public function testUlidKeysAsPrimaryKey() { - if (!method_exists(Blueprint::class, 'ulid')) { + if (! method_exists(Blueprint::class, 'ulid')) { $this->assertTrue(true); return; } - $this->fillUuidTable($this->uuid_key); + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + ])->run(); + $this->fillUlidTable($this->ulid_key); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + + public function testUuidKeysAsPrimaryKey() + { + if (! method_exists(Blueprint::class, 'uuid')) { + $this->assertTrue(true); + + return; + } + $this->artisan('migrate', [ '--realpath' => true, - '--path' => [ - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ] + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' ])->run(); + $this->fillUuidTable($this->uuid_key); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); - $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, '--schema-to' => $this->target_connection, @@ -272,10 +299,6 @@ public function testUuidAndUlidKeysAsPrimaryKey() $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); - - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index eab7216..884ccc2 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -231,33 +231,60 @@ public function testSame() ); } - public function testUuidAndUlidKeysAsPrimaryKey() + public function testUlidKeysAsPrimaryKey() { - if (!method_exists(Blueprint::class, 'ulid')) { + if (! method_exists(Blueprint::class, 'ulid')) { $this->assertTrue(true); return; } - $this->fillUuidTable($this->uuid_key); + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + ])->run(); + $this->fillUlidTable($this->ulid_key); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + + public function testUuidKeysAsPrimaryKey() + { + if (! method_exists(Blueprint::class, 'uuid')) { + $this->assertTrue(true); + + return; + } + $this->artisan('migrate', [ '--realpath' => true, - '--path' => [ - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ] + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' ])->run(); + $this->fillUuidTable($this->uuid_key); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); - $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, '--schema-to' => $this->target_connection, @@ -272,10 +299,6 @@ public function testUuidAndUlidKeysAsPrimaryKey() $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); - - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index 5bd3b2c..c8e8ec6 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -231,33 +231,60 @@ public function testSame() ); } - public function testUuidAndUlidKeysAsPrimaryKey() + public function testUlidKeysAsPrimaryKey() { - if (!method_exists(Blueprint::class, 'ulid')) { + if (! method_exists(Blueprint::class, 'ulid')) { $this->assertTrue(true); return; } - $this->fillUuidTable($this->uuid_key); + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + ])->run(); + $this->fillUlidTable($this->ulid_key); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + + public function testUuidKeysAsPrimaryKey() + { + if (! method_exists(Blueprint::class, 'uuid')) { + $this->assertTrue(true); + + return; + } + $this->artisan('migrate', [ '--realpath' => true, - '--path' => [ - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ] + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' ])->run(); + $this->fillUuidTable($this->uuid_key); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); - $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, '--schema-to' => $this->target_connection, @@ -272,10 +299,6 @@ public function testUuidAndUlidKeysAsPrimaryKey() $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); - - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index 2136302..dcf027e 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -231,33 +231,60 @@ public function testSame() ); } - public function testUuidAndUlidKeysAsPrimaryKey() + public function testUlidKeysAsPrimaryKey() { - if (!method_exists(Blueprint::class, 'ulid')) { + if (! method_exists(Blueprint::class, 'ulid')) { $this->assertTrue(true); return; } - $this->fillUuidTable($this->uuid_key); + $this->artisan('migrate', [ + '--realpath' => true, + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + ])->run(); + $this->fillUlidTable($this->ulid_key); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + + $this->artisan('db:migrate', [ + '--schema-from' => $this->source_connection, + '--schema-to' => $this->target_connection, + ]) + ->expectsConfirmation('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', 'no') + ->expectsConfirmation('Please confirm whether to truncate target table before transfer?', 'yes') + ->expectsConfirmation('Please choose whether to drop target tables before migration?', 'no') + ->expectsChoice('Please choose option to run migration on which connection?', $this->choice_source, $this->choices) + ->assertExitCode(0) + ->run(); + + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + } + + public function testUuidKeysAsPrimaryKey() + { + if (! method_exists(Blueprint::class, 'uuid')) { + $this->assertTrue(true); + + return; + } + $this->artisan('migrate', [ '--realpath' => true, - '--path' => [ - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', - __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ] + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' ])->run(); + $this->fillUuidTable($this->uuid_key); + $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); - $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, '--schema-to' => $this->target_connection, @@ -272,10 +299,6 @@ public function testUuidAndUlidKeysAsPrimaryKey() $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); - - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); } public function testFailed() From 3a9ed1f5d84814b9ebca7ae05a5688ec180559e2 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 14:51:18 +0300 Subject: [PATCH 03/15] Fixed credentials --- tests/Configurations/MySQL.php | 2 +- tests/Configurations/Postgres.php | 4 ++-- tests/Configurations/SqlServer.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Configurations/MySQL.php b/tests/Configurations/MySQL.php index 2f640f5..bed8323 100644 --- a/tests/Configurations/MySQL.php +++ b/tests/Configurations/MySQL.php @@ -11,7 +11,7 @@ class MySQL extends BaseConfiguration 'url' => null, 'host' => '127.0.0.1', 'port' => '3306', - 'database' => 'forge', + 'database' => 'default', 'username' => 'root', 'password' => 'root', 'unix_socket' => '', diff --git a/tests/Configurations/Postgres.php b/tests/Configurations/Postgres.php index 8733fa8..9492a13 100644 --- a/tests/Configurations/Postgres.php +++ b/tests/Configurations/Postgres.php @@ -11,8 +11,8 @@ class Postgres extends BaseConfiguration 'url' => null, 'host' => '127.0.0.1', 'port' => '5432', - 'database' => 'forge', - 'username' => 'default', + 'database' => 'default', + 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'prefix' => '', diff --git a/tests/Configurations/SqlServer.php b/tests/Configurations/SqlServer.php index f931cf1..10ac82e 100644 --- a/tests/Configurations/SqlServer.php +++ b/tests/Configurations/SqlServer.php @@ -11,7 +11,7 @@ class SqlServer extends BaseConfiguration 'url' => null, 'host' => '127.0.0.1', 'port' => '1433', - 'database' => 'forge', + 'database' => 'default', 'username' => 'sa', 'password' => '', 'charset' => 'utf8', From 981b346260bce90c83db36bf90eeda0529637e2a Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 14:52:15 +0300 Subject: [PATCH 04/15] Fixed code-style --- src/Console/Migrate.php | 2 +- tests/Unit/MysqlToMysqlTest.php | 4 ++-- tests/Unit/MysqlToPostgresTest.php | 4 ++-- tests/Unit/PostgresToMysqlTest.php | 4 ++-- tests/Unit/PostgresToPostgresTest.php | 4 ++-- .../2023_12_15_014834_create_ulid_primary_key.php | 2 +- .../2023_12_15_014834_create_uuid_primary_key.php | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 04af680..fd1324c 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -160,7 +160,7 @@ protected function isSkippable(string $table, string $column): bool protected function isNumericColumn(string $table, string $column): bool { $type = $this->getPrimaryKeyType($this->source(), $table, $column); - + return ! in_array($type, ['string', 'char'], true); } diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index 66dbd8a..2cd693e 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -241,7 +241,7 @@ public function testUlidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); $this->fillUlidTable($this->ulid_key); @@ -276,7 +276,7 @@ public function testUuidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); $this->fillUuidTable($this->uuid_key); diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index 884ccc2..c226090 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -241,7 +241,7 @@ public function testUlidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); $this->fillUlidTable($this->ulid_key); @@ -276,7 +276,7 @@ public function testUuidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); $this->fillUuidTable($this->uuid_key); diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index c8e8ec6..4d025c0 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -241,7 +241,7 @@ public function testUlidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); $this->fillUlidTable($this->ulid_key); @@ -276,7 +276,7 @@ public function testUuidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); $this->fillUuidTable($this->uuid_key); diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index dcf027e..242e6f3 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -241,7 +241,7 @@ public function testUlidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); $this->fillUlidTable($this->ulid_key); @@ -276,7 +276,7 @@ public function testUuidKeysAsPrimaryKey() $this->artisan('migrate', [ '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php' + '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); $this->fillUuidTable($this->uuid_key); diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php b/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php index 752b9d8..f554d24 100644 --- a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php +++ b/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php @@ -12,7 +12,7 @@ public function up() { Schema::create($this->table, function (Blueprint $table) { $table->ulid()->primary(); - + $table->string('value'); }); } diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php b/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php index bde0aef..5436c9c 100644 --- a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php +++ b/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php @@ -12,7 +12,7 @@ public function up() { Schema::create($this->table, function (Blueprint $table) { $table->uuid()->primary(); - + $table->string('value'); }); } From db3582594ab96704fb4a4f9feee4a0d834910f31 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 15:04:20 +0300 Subject: [PATCH 05/15] Fixed databases --- tests/Unit/MysqlToMysqlTest.php | 2 ++ tests/Unit/MysqlToPostgresTest.php | 2 ++ tests/Unit/PostgresToMysqlTest.php | 2 ++ tests/Unit/PostgresToPostgresTest.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index 2cd693e..ab7c942 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -240,6 +240,7 @@ public function testUlidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); @@ -275,6 +276,7 @@ public function testUuidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index c226090..db1106d 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -240,6 +240,7 @@ public function testUlidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); @@ -275,6 +276,7 @@ public function testUuidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index 4d025c0..33e66ba 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -240,6 +240,7 @@ public function testUlidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); @@ -275,6 +276,7 @@ public function testUuidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index 242e6f3..4425dd8 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -240,6 +240,7 @@ public function testUlidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); @@ -275,6 +276,7 @@ public function testUuidKeysAsPrimaryKey() } $this->artisan('migrate', [ + '--database' => $this->source_connection, '--realpath' => true, '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', ])->run(); From ebef27392326165940cf14526208a924ae28732c Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 15:05:23 +0300 Subject: [PATCH 06/15] revert databases settings --- tests/Configurations/MySQL.php | 2 +- tests/Configurations/Postgres.php | 4 ++-- tests/Configurations/SqlServer.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Configurations/MySQL.php b/tests/Configurations/MySQL.php index bed8323..2f640f5 100644 --- a/tests/Configurations/MySQL.php +++ b/tests/Configurations/MySQL.php @@ -11,7 +11,7 @@ class MySQL extends BaseConfiguration 'url' => null, 'host' => '127.0.0.1', 'port' => '3306', - 'database' => 'default', + 'database' => 'forge', 'username' => 'root', 'password' => 'root', 'unix_socket' => '', diff --git a/tests/Configurations/Postgres.php b/tests/Configurations/Postgres.php index 9492a13..8733fa8 100644 --- a/tests/Configurations/Postgres.php +++ b/tests/Configurations/Postgres.php @@ -11,8 +11,8 @@ class Postgres extends BaseConfiguration 'url' => null, 'host' => '127.0.0.1', 'port' => '5432', - 'database' => 'default', - 'username' => 'root', + 'database' => 'forge', + 'username' => 'default', 'password' => 'root', 'charset' => 'utf8', 'prefix' => '', diff --git a/tests/Configurations/SqlServer.php b/tests/Configurations/SqlServer.php index 10ac82e..f931cf1 100644 --- a/tests/Configurations/SqlServer.php +++ b/tests/Configurations/SqlServer.php @@ -11,7 +11,7 @@ class SqlServer extends BaseConfiguration 'url' => null, 'host' => '127.0.0.1', 'port' => '1433', - 'database' => 'default', + 'database' => 'forge', 'username' => 'sa', 'password' => '', 'charset' => 'utf8', From 72334f59704c669b6a33d9d5f61805278de06ff0 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 15:19:31 +0300 Subject: [PATCH 07/15] Fix --- tests/Unit/MysqlToMysqlTest.php | 24 ++++++++++++------------ tests/Unit/MysqlToPostgresTest.php | 24 ++++++++++++------------ tests/Unit/PostgresToMysqlTest.php | 24 ++++++++++++------------ tests/Unit/PostgresToPostgresTest.php | 24 ++++++++++++------------ 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index ab7c942..b979934 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -247,9 +247,9 @@ public function testUlidKeysAsPrimaryKey() $this->fillUlidTable($this->ulid_key); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -283,9 +283,9 @@ public function testUuidKeysAsPrimaryKey() $this->fillUuidTable($this->uuid_key); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +298,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index db1106d..9177e2f 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -247,9 +247,9 @@ public function testUlidKeysAsPrimaryKey() $this->fillUlidTable($this->ulid_key); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -283,9 +283,9 @@ public function testUuidKeysAsPrimaryKey() $this->fillUuidTable($this->uuid_key); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +298,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index 33e66ba..1385c5e 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -247,9 +247,9 @@ public function testUlidKeysAsPrimaryKey() $this->fillUlidTable($this->ulid_key); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -283,9 +283,9 @@ public function testUuidKeysAsPrimaryKey() $this->fillUuidTable($this->uuid_key); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +298,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index 4425dd8..e1d4840 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -247,9 +247,9 @@ public function testUlidKeysAsPrimaryKey() $this->fillUlidTable($this->ulid_key); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => 'bar_3'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -283,9 +283,9 @@ public function testUuidKeysAsPrimaryKey() $this->fillUuidTable($this->uuid_key); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +298,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => 'foo_3'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); } public function testFailed() From d7fe5ab617f4abebd70f5227b8b9317d3bd70af3 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 15:23:01 +0300 Subject: [PATCH 08/15] Fixed argument count --- .../primary_keys/2023_12_15_014834_create_ulid_primary_key.php | 2 +- .../primary_keys/2023_12_15_014834_create_uuid_primary_key.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php b/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php index f554d24..a004fdc 100644 --- a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php +++ b/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php @@ -11,7 +11,7 @@ class CreateUlidPrimaryKey extends Migration public function up() { Schema::create($this->table, function (Blueprint $table) { - $table->ulid()->primary(); + $table->ulid('ulid')->primary(); $table->string('value'); }); diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php b/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php index 5436c9c..7f637ac 100644 --- a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php +++ b/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php @@ -11,7 +11,7 @@ class CreateUuidPrimaryKey extends Migration public function up() { Schema::create($this->table, function (Blueprint $table) { - $table->uuid()->primary(); + $table->uuid('uuid')->primary(); $table->string('value'); }); From eb31b69a8c82e15eeb9bd428d7177d0a42e50ac6 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 15:30:29 +0300 Subject: [PATCH 09/15] Fix --- tests/Concerns/Database.php | 4 +-- tests/Concerns/Seeders.php | 9 +++++ tests/Unit/MysqlToMysqlTest.php | 34 +++++++------------ tests/Unit/MysqlToPostgresTest.php | 34 +++++++------------ tests/Unit/PostgresToMysqlTest.php | 34 +++++++------------ tests/Unit/PostgresToPostgresTest.php | 34 +++++++------------ ...3_12_15_014834_create_ulid_primary_key.php | 6 ++-- ...3_12_15_014834_create_uuid_primary_key.php | 6 ++-- 8 files changed, 71 insertions(+), 90 deletions(-) rename tests/fixtures/{primary_keys => migrations}/2023_12_15_014834_create_ulid_primary_key.php (67%) rename tests/fixtures/{primary_keys => migrations}/2023_12_15_014834_create_uuid_primary_key.php (67%) diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 3c66940..7478fee 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -27,9 +27,9 @@ trait Database protected $table_baz = 'baz'; - protected $ulid_key = 'ulid_key'; + protected $table_ulid = 'ulid_table'; - protected $uuid_key = 'uuid_key'; + protected $table_uuid = 'uuid_table'; protected $choice_target = 'target'; diff --git a/tests/Concerns/Seeders.php b/tests/Concerns/Seeders.php index cf733f0..6b3a09f 100644 --- a/tests/Concerns/Seeders.php +++ b/tests/Concerns/Seeders.php @@ -2,6 +2,7 @@ namespace Tests\Concerns; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; @@ -12,6 +13,14 @@ protected function fillTables(): void $this->fillTable($this->table_foo); $this->fillTable($this->table_bar); $this->fillTable($this->table_baz); + + if (method_exists(Blueprint::class, 'ulid')) { + $this->fillUlidTable($this->table_ulid); + } + + if (method_exists(Blueprint::class, 'uuid')) { + $this->fillUlidTable($this->table_uuid); + } } protected function fillTable(string $table): void diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index b979934..183c7ce 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -245,11 +245,11 @@ public function testUlidKeysAsPrimaryKey() '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); - $this->fillUlidTable($this->ulid_key); + $this->fillUlidTable($this->table_ulid); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -275,17 +275,9 @@ public function testUuidKeysAsPrimaryKey() return; } - $this->artisan('migrate', [ - '--database' => $this->source_connection, - '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ])->run(); - - $this->fillUuidTable($this->uuid_key); - - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +290,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index 9177e2f..52a0e62 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -245,11 +245,11 @@ public function testUlidKeysAsPrimaryKey() '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); - $this->fillUlidTable($this->ulid_key); + $this->fillUlidTable($this->table_ulid); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -275,17 +275,9 @@ public function testUuidKeysAsPrimaryKey() return; } - $this->artisan('migrate', [ - '--database' => $this->source_connection, - '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ])->run(); - - $this->fillUuidTable($this->uuid_key); - - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +290,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index 1385c5e..a382169 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -245,11 +245,11 @@ public function testUlidKeysAsPrimaryKey() '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); - $this->fillUlidTable($this->ulid_key); + $this->fillUlidTable($this->table_ulid); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -275,17 +275,9 @@ public function testUuidKeysAsPrimaryKey() return; } - $this->artisan('migrate', [ - '--database' => $this->source_connection, - '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ])->run(); - - $this->fillUuidTable($this->uuid_key); - - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +290,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index e1d4840..0b94718 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -245,11 +245,11 @@ public function testUlidKeysAsPrimaryKey() '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php', ])->run(); - $this->fillUlidTable($this->ulid_key); + $this->fillUlidTable($this->table_ulid); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -262,9 +262,9 @@ public function testUlidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->ulid_key, ['value' => $this->ulid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_ulid, ['value' => $this->table_ulid . '_3'], $this->target_connection); } public function testUuidKeysAsPrimaryKey() @@ -275,17 +275,9 @@ public function testUuidKeysAsPrimaryKey() return; } - $this->artisan('migrate', [ - '--database' => $this->source_connection, - '--realpath' => true, - '--path' => __DIR__ . '/../fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php', - ])->run(); - - $this->fillUuidTable($this->uuid_key); - - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->source_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->source_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->source_connection); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -298,9 +290,9 @@ public function testUuidKeysAsPrimaryKey() ->assertExitCode(0) ->run(); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_1'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_2'], $this->target_connection); - $this->assertDatabaseHas($this->uuid_key, ['value' => $this->uuid_key . '_3'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_1'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_2'], $this->target_connection); + $this->assertDatabaseHas($this->table_uuid, ['value' => $this->table_uuid . '_3'], $this->target_connection); } public function testFailed() diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php b/tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php similarity index 67% rename from tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php rename to tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php index a004fdc..5f77205 100644 --- a/tests/fixtures/primary_keys/2023_12_15_014834_create_ulid_primary_key.php +++ b/tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php @@ -6,12 +6,14 @@ class CreateUlidPrimaryKey extends Migration { - protected $table = 'ulid_key'; + protected $table = 'ulid_table'; public function up() { Schema::create($this->table, function (Blueprint $table) { - $table->ulid('ulid')->primary(); + if (method_exists(Blueprint::class, 'ulid')) { + $table->ulid('ulid')->primary(); + } $table->string('value'); }); diff --git a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php b/tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php similarity index 67% rename from tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php rename to tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php index 7f637ac..1bb07ae 100644 --- a/tests/fixtures/primary_keys/2023_12_15_014834_create_uuid_primary_key.php +++ b/tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php @@ -6,12 +6,14 @@ class CreateUuidPrimaryKey extends Migration { - protected $table = 'uuid_key'; + protected $table = 'uuid_table'; public function up() { Schema::create($this->table, function (Blueprint $table) { - $table->uuid('uuid')->primary(); + if (method_exists(Blueprint::class, 'uuid')) { + $table->uuid('uuid')->primary(); + } $table->string('value'); }); From 0acbdb0dc6af88854ee78aee0cf3d78e4a6b0eb1 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 15:36:24 +0300 Subject: [PATCH 10/15] Fix --- tests/Concerns/Database.php | 1 + tests/Concerns/HasUuidAndUlid.php | 23 +++++++++++++++++++ tests/Concerns/Migration.php | 2 ++ tests/Concerns/Seeders.php | 5 ++-- tests/Unit/MysqlToMysqlTest.php | 5 ++-- tests/Unit/MysqlToPostgresTest.php | 5 ++-- tests/Unit/PostgresToMysqlTest.php | 5 ++-- tests/Unit/PostgresToPostgresTest.php | 5 ++-- ...3_12_15_014834_create_ulid_primary_key.php | 2 +- ...3_12_15_014834_create_uuid_primary_key.php | 2 +- 10 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 tests/Concerns/HasUuidAndUlid.php diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 7478fee..3966501 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -13,6 +13,7 @@ /** @mixin \Tests\Concerns\Connections */ trait Database { + use HasUuidAndUlid; use Seeders; protected $connectors = [ diff --git a/tests/Concerns/HasUuidAndUlid.php b/tests/Concerns/HasUuidAndUlid.php new file mode 100644 index 0000000..b9563c7 --- /dev/null +++ b/tests/Concerns/HasUuidAndUlid.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); + +namespace Tests\Concerns; + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Str; + +trait HasUuidAndUlid +{ + protected function hasUuid() + { + return method_exists(Blueprint::class, 'uuid') + && method_exists(Str::class, 'uuid'); + } + + protected function hasUlid() + { + return method_exists(Blueprint::class, 'ulid') + && method_exists(Str::class, 'ulid'); + } +} diff --git a/tests/Concerns/Migration.php b/tests/Concerns/Migration.php index bd0a81b..dd53faa 100644 --- a/tests/Concerns/Migration.php +++ b/tests/Concerns/Migration.php @@ -8,6 +8,8 @@ abstract class Migration extends BaseMigration { + use HasUuidAndUlid; + protected $table; public function up() diff --git a/tests/Concerns/Seeders.php b/tests/Concerns/Seeders.php index 6b3a09f..4734a64 100644 --- a/tests/Concerns/Seeders.php +++ b/tests/Concerns/Seeders.php @@ -2,7 +2,6 @@ namespace Tests\Concerns; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; @@ -14,11 +13,11 @@ protected function fillTables(): void $this->fillTable($this->table_bar); $this->fillTable($this->table_baz); - if (method_exists(Blueprint::class, 'ulid')) { + if ($this->hasUlid()) { $this->fillUlidTable($this->table_ulid); } - if (method_exists(Blueprint::class, 'uuid')) { + if ($this->hasUuid()) { $this->fillUlidTable($this->table_uuid); } } diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index 183c7ce..a750779 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -5,7 +5,6 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -233,7 +232,7 @@ public function testSame() public function testUlidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'ulid')) { + if (! $this->hasUlid()) { $this->assertTrue(true); return; @@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey() public function testUuidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'uuid')) { + if (! $this->hasUuid()) { $this->assertTrue(true); return; diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index 52a0e62..094ef7d 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -5,7 +5,6 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -233,7 +232,7 @@ public function testSame() public function testUlidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'ulid')) { + if (! $this->hasUlid()) { $this->assertTrue(true); return; @@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey() public function testUuidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'uuid')) { + if (! $this->hasUuid()) { $this->assertTrue(true); return; diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index a382169..e5809c9 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -5,7 +5,6 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -233,7 +232,7 @@ public function testSame() public function testUlidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'ulid')) { + if (! $this->hasUlid()) { $this->assertTrue(true); return; @@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey() public function testUuidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'uuid')) { + if (! $this->hasUuid()) { $this->assertTrue(true); return; diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index 0b94718..8ec81ba 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -5,7 +5,6 @@ use DragonCode\MigrateDB\Constants\Drivers; use DragonCode\MigrateDB\Exceptions\InvalidArgumentException; use DragonCode\Support\Facades\Helpers\Arr; -use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -233,7 +232,7 @@ public function testSame() public function testUlidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'ulid')) { + if (! $this->hasUlid()) { $this->assertTrue(true); return; @@ -269,7 +268,7 @@ public function testUlidKeysAsPrimaryKey() public function testUuidKeysAsPrimaryKey() { - if (! method_exists(Blueprint::class, 'uuid')) { + if (! $this->hasUuid()) { $this->assertTrue(true); return; diff --git a/tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php b/tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php index 5f77205..81beba5 100644 --- a/tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php +++ b/tests/fixtures/migrations/2023_12_15_014834_create_ulid_primary_key.php @@ -11,7 +11,7 @@ class CreateUlidPrimaryKey extends Migration public function up() { Schema::create($this->table, function (Blueprint $table) { - if (method_exists(Blueprint::class, 'ulid')) { + if ($this->hasUlid()) { $table->ulid('ulid')->primary(); } diff --git a/tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php b/tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php index 1bb07ae..4a783ab 100644 --- a/tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php +++ b/tests/fixtures/migrations/2023_12_15_014834_create_uuid_primary_key.php @@ -11,7 +11,7 @@ class CreateUuidPrimaryKey extends Migration public function up() { Schema::create($this->table, function (Blueprint $table) { - if (method_exists(Blueprint::class, 'uuid')) { + if ($this->hasUuid()) { $table->uuid('uuid')->primary(); } From 5fcff3f7746354c55dc790c76e4aaf5b9e5b032d Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 18:55:44 +0300 Subject: [PATCH 11/15] Fix --- tests/Concerns/Seeders.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Concerns/Seeders.php b/tests/Concerns/Seeders.php index 4734a64..435b637 100644 --- a/tests/Concerns/Seeders.php +++ b/tests/Concerns/Seeders.php @@ -18,7 +18,7 @@ protected function fillTables(): void } if ($this->hasUuid()) { - $this->fillUlidTable($this->table_uuid); + $this->fillUuidTable($this->table_uuid); } } @@ -31,21 +31,21 @@ protected function fillTable(string $table): void ]); } - protected function fillUuidTable(string $table): void + protected function fillUlidTable(string $table): void { DB::connection($this->source_connection)->table($table)->insert([ - ['value' => $table . '_1', 'uuid' => Str::uuid()->toString()], - ['value' => $table . '_2', 'uuid' => Str::uuid()->toString()], - ['value' => $table . '_3', 'uuid' => Str::uuid()->toString()], + ['value' => $table . '_1', 'ulid' => (string) Str::ulid()], + ['value' => $table . '_2', 'ulid' => (string) Str::ulid()], + ['value' => $table . '_3', 'ulid' => (string) Str::ulid()], ]); } - protected function fillUlidTable(string $table): void + protected function fillUuidTable(string $table): void { DB::connection($this->source_connection)->table($table)->insert([ - ['value' => $table . '_1', 'ulid' => (string) Str::ulid()], - ['value' => $table . '_2', 'ulid' => (string) Str::ulid()], - ['value' => $table . '_3', 'ulid' => (string) Str::ulid()], + ['value' => $table . '_1', 'uuid' => Str::uuid()->toString()], + ['value' => $table . '_2', 'uuid' => Str::uuid()->toString()], + ['value' => $table . '_3', 'uuid' => Str::uuid()->toString()], ]); } } From d686e559cfa1da31976d492a4c4713cf36507aeb Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 19:00:54 +0300 Subject: [PATCH 12/15] Fix --- src/Console/Migrate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index fd1324c..7bc36e1 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -161,7 +161,7 @@ protected function isNumericColumn(string $table, string $column): bool { $type = $this->getPrimaryKeyType($this->source(), $table, $column); - return ! in_array($type, ['string', 'char'], true); + return ! in_array($type, ['string', 'char', 'ulid', 'uuid'], true); } protected function tables(): array From 7ba786e25bf54b86286eb4c525486095fd215a52 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 19:04:00 +0300 Subject: [PATCH 13/15] Fix --- src/Console/Migrate.php | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 7bc36e1..c4127cd 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -114,7 +114,7 @@ protected function runTransfer(): void } $this->truncateTable($table); - $this->migrateTable($table, $this->source->getPrimaryKey($table)); + $this->migrateTable($table); }); $this->displayMessage(PHP_EOL); @@ -127,27 +127,15 @@ protected function truncateTable(string $table): void } } - protected function migrateTable(string $table, string $column): void + protected function migrateTable(string $table): void { Log::info('Transferring data from: ' . $table); - $this->builder($this->source(), $table) - ->when( - $this->isSkippable($table, $column), - function ($query) use ($table, $column) { - $lastRecord = $this->builder($this->target(), $table)->max($column) ?: 0; - - Log::info('last record: ' . $lastRecord); - - return $query->where($column, '>', $lastRecord); - } - ) - ->orderBy($column) - ->chunk(1000, function (Collection $items) use ($table) { - $items = Arr::resolve($items); - - $this->builder($this->target(), $table)->insert($items); - }); + $this->builder($this->source(), $table)->chunkById(1000, function (Collection $items) use ($table) { + $this->builder($this->target(), $table)->insert( + Arr::resolve($items) + ); + }); $this->migrated[] = $table; } From 7759ac330c35644a6d5a6525f8c334d6a0ac9427 Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 19:06:23 +0300 Subject: [PATCH 14/15] Fix --- src/Console/Migrate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index c4127cd..03098fd 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -131,7 +131,7 @@ protected function migrateTable(string $table): void { Log::info('Transferring data from: ' . $table); - $this->builder($this->source(), $table)->chunkById(1000, function (Collection $items) use ($table) { + $this->builder($this->source(), $table)->chunk(1000, function (Collection $items) use ($table) { $this->builder($this->target(), $table)->insert( Arr::resolve($items) ); From 379476b3e485f5bc513f35b4ab3d67a49eda234a Mon Sep 17 00:00:00 2001 From: Andrey Helldar <helldar@dragon-code.pro> Date: Fri, 15 Dec 2023 19:09:47 +0300 Subject: [PATCH 15/15] Fix --- src/Console/Migrate.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 03098fd..9d489f5 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -114,7 +114,7 @@ protected function runTransfer(): void } $this->truncateTable($table); - $this->migrateTable($table); + $this->migrateTable($table, $this->source->getPrimaryKey($table)); }); $this->displayMessage(PHP_EOL); @@ -127,15 +127,17 @@ protected function truncateTable(string $table): void } } - protected function migrateTable(string $table): void + protected function migrateTable(string $table, string $column): void { Log::info('Transferring data from: ' . $table); - $this->builder($this->source(), $table)->chunk(1000, function (Collection $items) use ($table) { - $this->builder($this->target(), $table)->insert( - Arr::resolve($items) - ); - }); + $this->builder($this->source(), $table) + ->orderBy($column) + ->chunk(1000, function (Collection $items) use ($table) { + $items = Arr::resolve($items); + + $this->builder($this->target(), $table)->insert($items); + }); $this->migrated[] = $table; }