diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 133a1e1..2550067 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -59,8 +59,8 @@ jobs: ACCEPT_EULA: "Y" ports: - 1433:1433 - options: >- - --health-cmd "echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P '!QAZ2wsx'" +# options: >- +# --health-cmd "echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P '!QAZ2wsx'" mariadb: image: mariadb:10 diff --git a/.phpmd.xml b/.phpmd.xml index 51b4b28..c1b641b 100644 --- a/.phpmd.xml +++ b/.phpmd.xml @@ -20,6 +20,7 @@ + @@ -47,6 +48,11 @@ + + + + + diff --git a/phpcs.xml b/phpcs.xml index 314de42..9494849 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -28,7 +28,7 @@ - + diff --git a/src/Database/Models/PgSQL/PgSQLColumn.php b/src/Database/Models/PgSQL/PgSQLColumn.php index 0cbcb79..f34a71d 100644 --- a/src/Database/Models/PgSQL/PgSQLColumn.php +++ b/src/Database/Models/PgSQL/PgSQLColumn.php @@ -154,6 +154,12 @@ private function setRealSpatialColumn(string $fullDefinitionType): void return; } + $dotPosition = Str::position($dataType, '.'); + + if ($dotPosition !== false) { + $dataType = Str::substr($dataType, $dotPosition + 1); + } + if ($dataType === 'geography' || $dataType === 'geometry') { return; } diff --git a/src/MigrateGenerateCommand.php b/src/MigrateGenerateCommand.php index 7e88d23..db3e9f4 100644 --- a/src/MigrateGenerateCommand.php +++ b/src/MigrateGenerateCommand.php @@ -64,25 +64,33 @@ class MigrateGenerateCommand extends Command protected bool $shouldLog = false; protected int $nextBatchNumber = 0; - - public function __construct( - protected MigrationRepositoryInterface $repository, - protected Squash $squash, - protected ForeignKeyMigration $foreignKeyMigration, - protected ProcedureMigration $procedureMigration, - protected TableMigration $tableMigration, - protected ViewMigration $viewMigration, - ) { - parent::__construct(); - } + protected MigrationRepositoryInterface $repository; + protected Squash $squash; + protected ForeignKeyMigration $foreignKeyMigration; + protected ProcedureMigration $procedureMigration; + protected ViewMigration $viewMigration; + protected TableMigration $tableMigration; /** * Execute the console command. * * @throws \Exception */ - public function handle(): void - { + public function handle( + MigrationRepositoryInterface $repository, + Squash $squash, + ForeignKeyMigration $foreignKeyMigration, + ProcedureMigration $procedureMigration, + TableMigration $tableMigration, + ViewMigration $viewMigration, + ): void { + $this->tableMigration = $tableMigration; + $this->viewMigration = $viewMigration; + $this->procedureMigration = $procedureMigration; + $this->foreignKeyMigration = $foreignKeyMigration; + $this->squash = $squash; + $this->repository = $repository; + $previousConnection = DB::getDefaultConnection(); try { diff --git a/src/Repositories/MySQLRepository.php b/src/Repositories/MySQLRepository.php index a05bec7..32796c2 100644 --- a/src/Repositories/MySQLRepository.php +++ b/src/Repositories/MySQLRepository.php @@ -110,6 +110,8 @@ public function getSrID(string $table, string $column): ?int ); } catch (QueryException $exception) { if ( + // `SRS_ID` available since MySQL 8.0.3. + // https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-3.html Str::contains( $exception->getMessage(), "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'SRS_ID'", diff --git a/src/Repositories/SQLSrvRepository.php b/src/Repositories/SQLSrvRepository.php index 591a0d4..957e7b9 100644 --- a/src/Repositories/SQLSrvRepository.php +++ b/src/Repositories/SQLSrvRepository.php @@ -135,7 +135,7 @@ public function getUserDefinedTypes(): Collection /** * Returns the where clause to filter schema and table name in a query. * - * @param string $table The full qualified name of the table. + * @param string $table The name of the table. * @param string $schemaColumn The name of the column to compare the schema to in the where clause. * @param string $tableColumn The name of the column to compare the table to in the where clause. */ @@ -143,11 +143,6 @@ private function getTableWhereClause(string $table, string $schemaColumn, string { $schema = 'SCHEMA_NAME()'; - if (str_contains($table, '.')) { - [$schema, $table] = explode('.', $table); - $schema = $this->quoteStringLiteral($schema); - } - $table = $this->quoteStringLiteral($table); return sprintf('(%s = %s AND %s = %s)', $tableColumn, $table, $schemaColumn, $schema); diff --git a/tests/Feature/MySQL57/CommandTest.php b/tests/Feature/MySQL57/CommandTest.php index ccfed9a..61487bd 100644 --- a/tests/Feature/MySQL57/CommandTest.php +++ b/tests/Feature/MySQL57/CommandTest.php @@ -425,6 +425,30 @@ public function testSkipLog(): void ); } + public function testSkipLogWithSquash(): void + { + $this->migrateGeneral(); + $this->truncateMigrationsTable(); + $this->dumpSchemaAs($this->getStorageSqlPath('expected.sql')); + + $this->artisan( + 'migrate:generate', + [ + '--path' => $this->getStorageMigrationsPath(), + '--skip-log' => true, + '--squash' => true, + ], + ); + + $this->assertSame(0, DB::table('migrations')->count()); + $this->dumpSchemaAs($this->getStorageSqlPath('actual.sql')); + + $this->assertFileEqualsIgnoringOrder( + $this->getStorageSqlPath('expected.sql'), + $this->getStorageSqlPath('actual.sql'), + ); + } + public function testLogWithBatch0(): void { $this->migrateGeneral(); diff --git a/tests/Feature/MySQL57/StackedCommandTest.php b/tests/Feature/MySQL57/StackedCommandTest.php index 8530f8e..9aa0df3 100644 --- a/tests/Feature/MySQL57/StackedCommandTest.php +++ b/tests/Feature/MySQL57/StackedCommandTest.php @@ -24,12 +24,19 @@ public function testRunAsCall(): void $this->assertTrue(Schema::hasTable('migration_table')); $this->assertTrue(Schema::connection('migration2')->hasTable('migration2_table')); - $this->generateMigrations(); + $this->generateMigrations([ + '--table-filename' => 'create_migration_tables.php', + '--squash' => true, + ]); // Setting should reset. $this->assertEquals(app(Setting::class), new Setting()); - $this->generateMigrations(['--connection' => 'migration2']); + $this->generateMigrations([ + '--connection' => 'migration2', + '--table-filename' => 'create_migration2_tables.php', + '--squash' => true, + ]); $files = File::files($this->getStorageMigrationsPath()); $this->assertCount(2, $files); diff --git a/tests/Unit/Database/Models/PgSQL/PgSQLColumnTest.php b/tests/Unit/Database/Models/PgSQL/PgSQLColumnTest.php new file mode 100644 index 0000000..029c9c9 --- /dev/null +++ b/tests/Unit/Database/Models/PgSQL/PgSQLColumnTest.php @@ -0,0 +1,55 @@ +mock(PgSQLRepository::class, static function (MockInterface $mock): void { + $mock->shouldReceive('getStoredDefinition'); + }); + + $column = new PgSQLColumn('table', [ + 'name' => 'column', + 'type_name' => 'geography', + 'type' => $type, + 'collation' => null, + 'nullable' => false, + 'default' => null, + 'auto_increment' => false, + 'comment' => null, + ]); + + if ($this->atLeastLaravel11()) { + $this->assertSame(ColumnType::GEOGRAPHY, $column->getType()); + $this->assertSame('point', $column->getSpatialSubType()); + $this->assertSame(4326, $column->getSpatialSrID()); + return; + } + + $this->assertSame(ColumnType::POINT, $column->getType()); + } + + /** + * @return array + */ + public static function spatialTypeNameProvider(): array + { + return [ + 'with dot' => ['extensions.geography(Point,4326)'], + 'without dot' => ['geography(Point,4326)'], + ]; + } +} diff --git a/tests/resources/database/migrations/collation/2020_03_21_000000_expected_create_collations_table.php b/tests/resources/database/migrations/collation/2020_03_21_000000_expected_create_collations_table.php index bd3530c..2a4ce1a 100644 --- a/tests/resources/database/migrations/collation/2020_03_21_000000_expected_create_collations_table.php +++ b/tests/resources/database/migrations/collation/2020_03_21_000000_expected_create_collations_table.php @@ -1,9 +1,5 @@