diff --git a/src/Schema/Visitor/CreateSchemaSqlCollector.php b/src/Schema/Visitor/CreateSchemaSqlCollector.php index c08fb6fecd8..730dff77a6a 100644 --- a/src/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/src/Schema/Visitor/CreateSchemaSqlCollector.php @@ -91,8 +91,8 @@ public function getQueries() { return array_merge( $this->createNamespaceQueries, - $this->createTableQueries, $this->createSequenceQueries, + $this->createTableQueries, $this->createFkConstraintQueries ); } diff --git a/tests/Functional/Schema/PostgreSQL/SchemaTest.php b/tests/Functional/Schema/PostgreSQL/SchemaTest.php new file mode 100644 index 00000000000..8d5e16b883e --- /dev/null +++ b/tests/Functional/Schema/PostgreSQL/SchemaTest.php @@ -0,0 +1,42 @@ +connection->getDatabasePlatform(); + + if (! $platform instanceof PostgreSQLPlatform) { + self::markTestSkipped('Test is for PostgreSQL.'); + } + + $this->dropTableIfExists('my_table'); + + $options = ['default' => 'nextval(\'my_table_id_seq\'::regclass)']; + $table = new Table('my_table', [new Column('id', new IntegerType(), $options)]); + $sequence = new Sequence('my_table_id_seq'); + + $schema = new Schema([$table], [$sequence]); + foreach ($schema->toSql($platform) as $sql) { + $this->connection->executeStatement($sql); + } + + $result = $this->connection->fetchAssociative( + 'SELECT column_default FROM information_schema.columns WHERE table_name = ?', + ['my_table'] + ); + + $this->assertNotFalse($result); + $this->assertEquals('nextval(\'my_table_id_seq\'::regclass)', $result['column_default']); + } +} diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 84145c7dbea..adffb701034 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1257,6 +1257,8 @@ public function testCommentStringsAreQuoted(): void self::markTestSkipped('Database does not support column comments.'); } + $this->dropTableIfExists('my_table'); + $table = new Table('my_table'); $table->addColumn('id', 'integer', ['comment' => "It's a comment with a quote"]); $table->setPrimaryKey(['id']); @@ -1273,6 +1275,8 @@ public function testCommentNotDuplicated(): void self::markTestSkipped('Database does not support column comments.'); } + $this->dropTableIfExists('my_table'); + $options = [ 'type' => Type::getType('integer'), 'default' => 0, diff --git a/tests/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Schema/Visitor/SchemaSqlCollectorTest.php index 1e806f02840..3f83b5ad9af 100644 --- a/tests/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Schema/Visitor/SchemaSqlCollectorTest.php @@ -27,7 +27,7 @@ public function testCreateSchema(): void $sql = $schema->toSql($platformMock); - self::assertEquals(['foo', 'foo', 'bar', 'baz'], $sql); + self::assertEquals(['bar', 'foo', 'foo', 'baz'], $sql); } public function testDropSchema(): void