diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-03-25 15:28:32 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-03-25 15:28:32 +0000 |
| commit | 320cbdf26f892ea6376150ba0defa7f3c530e9cc (patch) | |
| tree | f0592e7887c0c89e6e7c54cc964fd09edc1b5783 /test/sql | |
| parent | 96dffd0ae9d19050f1d6000c35c4347bcb2dc6fe (diff) | |
| parent | 1984b6d3c7fd95dd22203cb75fb3fb65348c4158 (diff) | |
| download | sqlalchemy-320cbdf26f892ea6376150ba0defa7f3c530e9cc.tar.gz | |
Merge "Allow dropping a schema with a sequence shared by more than one table."
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_sequences.py | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/test/sql/test_sequences.py b/test/sql/test_sequences.py index 5cfc2663f..dd8491d31 100644 --- a/test/sql/test_sequences.py +++ b/test/sql/test_sequences.py @@ -13,6 +13,8 @@ from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import engines from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures +from sqlalchemy.testing import is_false +from sqlalchemy.testing import is_true from sqlalchemy.testing.assertsql import AllOf from sqlalchemy.testing.assertsql import CompiledSQL from sqlalchemy.testing.assertsql import EachOf @@ -348,6 +350,43 @@ class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL): result = connection.execute(t.insert()) eq_(result.inserted_primary_key, (1,)) + @testing.requires.sequences_as_server_defaults + @testing.provide_metadata + def test_shared_sequence(self, connection): + # test case for #6071 + common_seq = Sequence("common_sequence", metadata=self.metadata) + Table( + "table_1", + self.metadata, + Column( + "id", + Integer, + common_seq, + server_default=common_seq.next_value(), + primary_key=True, + ), + ) + Table( + "table_2", + self.metadata, + Column( + "id", + Integer, + common_seq, + server_default=common_seq.next_value(), + primary_key=True, + ), + ) + + self.metadata.create_all(connection) + is_true(self._has_sequence(connection, "common_sequence")) + is_true(testing.db.dialect.has_table(connection, "table_1")) + is_true(testing.db.dialect.has_table(connection, "table_2")) + self.metadata.drop_all(connection) + is_false(self._has_sequence(connection, "common_sequence")) + is_false(testing.db.dialect.has_table(connection, "table_1")) + is_false(testing.db.dialect.has_table(connection, "table_2")) + class FutureSequenceTest(fixtures.FutureEngineMixin, SequenceTest): __requires__ = ("sequences",) @@ -525,16 +564,26 @@ class SequenceAsServerDefaultTest( asserter.assert_( AllOf( CompiledSQL("DROP TABLE t_seq_test_2", {}), + CompiledSQL("DROP TABLE t_seq_test", {}), + ), + AllOf( + # dropped as part of metadata level + CompiledSQL("DROP SEQUENCE t_seq", {}), + CompiledSQL("DROP SEQUENCE t_seq_2", {}), + ), + ) + + def test_drop_ordering_single_table(self): + with self.sql_execution_asserter(testing.db) as asserter: + for table in self.tables_test_metadata.tables.values(): + table.drop(testing.db, checkfirst=False) + + asserter.assert_( + AllOf( + CompiledSQL("DROP TABLE t_seq_test_2", {}), EachOf( CompiledSQL("DROP TABLE t_seq_test", {}), - CompiledSQL( - "DROP SEQUENCE t_seq", # dropped as part of t_seq_test - {}, - ), + CompiledSQL("DROP SEQUENCE t_seq", {}), ), - ), - CompiledSQL( - "DROP SEQUENCE t_seq_2", # dropped as part of metadata level - {}, - ), + ) ) |
