diff --git a/psalm.xml.dist b/psalm.xml.dist index 567ecc381ae..8b16d961b51 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -326,6 +326,7 @@ + diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index eba3aefc890..f773aa97973 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -2477,6 +2477,11 @@ public function getCreateIndexSQL(Index $index, $table) $name = $index->getQuotedName($this); $columns = $index->getColumns(); + if ($this instanceof SqlitePlatform && strpos($table, '.') !== false) { + [$schema, $table] = explode('.', $table); + $name = $schema . '.' . $name; + } + if (count($columns) === 0) { throw new InvalidArgumentException(sprintf( 'Incomplete or invalid index definition %s on table %s', diff --git a/tests/Functional/Platform/OtherSchemaTest.php b/tests/Functional/Platform/OtherSchemaTest.php new file mode 100644 index 00000000000..e2147316feb --- /dev/null +++ b/tests/Functional/Platform/OtherSchemaTest.php @@ -0,0 +1,31 @@ +connection->getDatabasePlatform(); + if (! ($databasePlatform instanceof SqlitePlatform)) { + self::markTestSkipped('This test requires SQLite'); + } + + $this->connection->executeStatement("ATTACH DATABASE '/tmp/test_other_schema.sqlite' AS other"); + $databasePlatform->disableSchemaEmulation(); + + $table = new Table('other.test_other_schema'); + $table->addColumn('id', Types::INTEGER); + $table->addIndex(['id']); + + $this->dropAndCreateTable($table); + $this->connection->insert('other.test_other_schema', ['id' => 1]); + + self::assertEquals(1, $this->connection->fetchOne('SELECT COUNT(*) FROM other.test_other_schema')); + } +} diff --git a/tests/Platforms/SqlitePlatformTest.php b/tests/Platforms/SqlitePlatformTest.php index 94de2f0db73..4ff9008b28c 100644 --- a/tests/Platforms/SqlitePlatformTest.php +++ b/tests/Platforms/SqlitePlatformTest.php @@ -17,7 +17,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase { public function createPlatform(): AbstractPlatform { - return new SqlitePlatform(); + $platform = new SqlitePlatform(); + $platform->disableSchemaEmulation(); + + return $platform; } public function getGenerateTableSql(): string @@ -768,4 +771,19 @@ public function testGetCreateTableSQLWithColumnCollation(): void $this->platform->getCreateTableSQL($table), ); } + + public function testCreateTableInOtherSchema(): void + { + $table = new Table('other_schema.foo'); + $table->addColumn('id', Types::INTEGER); + $table->addIndex(['id']); + + self::assertSame( + [ + 'CREATE TABLE other_schema.foo (id INTEGER NOT NULL)', + 'CREATE INDEX other_schema.IDX_D9A8AD0DBF396750 ON foo (id)', + ], + $this->platform->getCreateTableSQL($table), + ); + } }