diff options
author | Federico Caselli <cfederico87@gmail.com> | 2022-09-24 15:50:26 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-10-17 15:36:25 -0400 |
commit | 974b1bd0fc40e11fc2886b5a9fc333feeeebf546 (patch) | |
tree | 421f0545c13a203f40435c4646a0de664e0e9756 /lib/sqlalchemy/testing/suite/test_sequence.py | |
parent | 665c94cc2f0340735515c4f4477e11b556d2bcd8 (diff) | |
download | sqlalchemy-974b1bd0fc40e11fc2886b5a9fc333feeeebf546.tar.gz |
Revert automatic set of sequence start to 1
The :class:`.Sequence` construct restores itself to the DDL behavior it
had prior to the 1.4 series, where creating a :class:`.Sequence` with
no additional arguments will emit a simple ``CREATE SEQUENCE`` instruction
**without** any additional parameters for "start value". For most backends,
this is how things worked previously in any case; **however**, for
MS SQL Server, the default value on this database is
``-2**63``; to prevent this generally impractical default
from taking effect on SQL Server, the :paramref:`.Sequence.start` parameter
should be provided. As usage of :class:`.Sequence` is unusual
for SQL Server which for many years has standardized on ``IDENTITY``,
it is hoped that this change has minimal impact.
Fixes: #7211
Change-Id: I1207ea10c8cb1528a1519a0fb3581d9621c27b31
Diffstat (limited to 'lib/sqlalchemy/testing/suite/test_sequence.py')
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_sequence.py | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_sequence.py b/lib/sqlalchemy/testing/suite/test_sequence.py index e15fad642..a605e4f42 100644 --- a/lib/sqlalchemy/testing/suite/test_sequence.py +++ b/lib/sqlalchemy/testing/suite/test_sequence.py @@ -5,6 +5,7 @@ from .. import fixtures from ..assertions import eq_ from ..assertions import is_true from ..config import requirements +from ..provision import normalize_sequence from ..schema import Column from ..schema import Table from ... import inspect @@ -29,7 +30,7 @@ class SequenceTest(fixtures.TablesTest): Column( "id", Integer, - Sequence("tab_id_seq"), + normalize_sequence(config, Sequence("tab_id_seq")), primary_key=True, ), Column("data", String(50)), @@ -41,7 +42,10 @@ class SequenceTest(fixtures.TablesTest): Column( "id", Integer, - Sequence("tab_id_seq", data_type=Integer, optional=True), + normalize_sequence( + config, + Sequence("tab_id_seq", data_type=Integer, optional=True), + ), primary_key=True, ), Column("data", String(50)), @@ -53,7 +57,7 @@ class SequenceTest(fixtures.TablesTest): Column( "id", Integer, - Sequence("noret_id_seq"), + normalize_sequence(config, Sequence("noret_id_seq")), primary_key=True, ), Column("data", String(50)), @@ -67,7 +71,12 @@ class SequenceTest(fixtures.TablesTest): Column( "id", Integer, - Sequence("noret_sch_id_seq", schema=config.test_schema), + normalize_sequence( + config, + Sequence( + "noret_sch_id_seq", schema=config.test_schema + ), + ), primary_key=True, ), Column("data", String(50)), @@ -118,7 +127,9 @@ class SequenceTest(fixtures.TablesTest): Column( "id", Integer, - Sequence("noret_sch_id_seq", schema="alt_schema"), + normalize_sequence( + config, Sequence("noret_sch_id_seq", schema="alt_schema") + ), primary_key=True, ), Column("data", String(50)), @@ -134,7 +145,9 @@ class SequenceTest(fixtures.TablesTest): @testing.requires.schemas def test_nextval_direct_schema_translate(self, connection): - seq = Sequence("noret_sch_id_seq", schema="alt_schema") + seq = normalize_sequence( + config, Sequence("noret_sch_id_seq", schema="alt_schema") + ) connection = connection.execution_options( schema_translate_map={"alt_schema": config.test_schema} ) @@ -151,7 +164,9 @@ class SequenceCompilerTest(testing.AssertsCompiledSQL, fixtures.TestBase): table = Table( "x", MetaData(), - Column("y", Integer, Sequence("y_seq")), + Column( + "y", Integer, normalize_sequence(config, Sequence("y_seq")) + ), Column("q", Integer), ) @@ -159,7 +174,7 @@ class SequenceCompilerTest(testing.AssertsCompiledSQL, fixtures.TestBase): seq_nextval = connection.dialect.statement_compiler( statement=None, dialect=connection.dialect - ).visit_sequence(Sequence("y_seq")) + ).visit_sequence(normalize_sequence(config, Sequence("y_seq"))) self.assert_compile( stmt, "INSERT INTO x (y, q) VALUES (%s, 5)" % (seq_nextval,), @@ -176,16 +191,28 @@ class HasSequenceTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): - Sequence("user_id_seq", metadata=metadata) - Sequence( - "other_seq", metadata=metadata, nomaxvalue=True, nominvalue=True + normalize_sequence(config, Sequence("user_id_seq", metadata=metadata)) + normalize_sequence( + config, + Sequence( + "other_seq", + metadata=metadata, + nomaxvalue=True, + nominvalue=True, + ), ) if testing.requires.schemas.enabled: - Sequence( - "user_id_seq", schema=config.test_schema, metadata=metadata + normalize_sequence( + config, + Sequence( + "user_id_seq", schema=config.test_schema, metadata=metadata + ), ) - Sequence( - "schema_seq", schema=config.test_schema, metadata=metadata + normalize_sequence( + config, + Sequence( + "schema_seq", schema=config.test_schema, metadata=metadata + ), ) Table( "user_id_table", @@ -199,7 +226,7 @@ class HasSequenceTest(fixtures.TablesTest): def test_has_sequence_cache(self, connection, metadata): insp = inspect(connection) eq_(insp.has_sequence("user_id_seq"), True) - ss = Sequence("new_seq", metadata=metadata) + ss = normalize_sequence(config, Sequence("new_seq", metadata=metadata)) eq_(insp.has_sequence("new_seq"), False) ss.create(connection) try: |