diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-11-02 12:35:47 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-11-02 12:35:47 -0500 |
commit | 92184a55cac2c0fa04396df4b2d4d9694e97f43f (patch) | |
tree | fa0f5a7404baa447236b6c74e98272b9bfc861c2 /tests | |
parent | b16bdf8789cc3f16fd6a5a94288ba204646bbc23 (diff) | |
download | alembic-92184a55cac2c0fa04396df4b2d4d9694e97f43f.tar.gz |
- Added a workaround for SQLAlchemy issue #3023 (fixed in 0.9.5) where
a column that's part of an explicit PrimaryKeyConstraint would not
have its "nullable" flag set to False, thus producing a false
autogenerate. Also added a related correction to MySQL which will
correct for MySQL's implicit server default of '0' when a NULL integer
column is turned into a primary key column. fixes #199
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_autogenerate.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/tests/test_autogenerate.py b/tests/test_autogenerate.py index ce239ed..1f25101 100644 --- a/tests/test_autogenerate.py +++ b/tests/test_autogenerate.py @@ -3,7 +3,7 @@ import sys from sqlalchemy import MetaData, Column, Table, Integer, String, Text, \ Numeric, CHAR, ForeignKey, INTEGER, \ - TypeDecorator, CheckConstraint, text + TypeDecorator, CheckConstraint, text, PrimaryKeyConstraint from sqlalchemy.types import NULLTYPE from sqlalchemy.engine.reflection import Inspector @@ -38,7 +38,6 @@ def new_table(table, parent): class AutogenTest(object): - __only_on__ = 'sqlite' @classmethod def _get_bind(cls): @@ -370,6 +369,7 @@ class ModelOne(object): class AutogenerateDiffTest(ModelOne, AutogenTest, TestBase): + __only_on__ = 'sqlite' def test_diffs(self): """test generation of diff rules""" @@ -791,6 +791,7 @@ name='extra_uid_fkey'), class AutogenerateCustomCompareTypeTest(AutogenTest, TestBase): + __only_on__ = 'sqlite' @classmethod def _get_db_schema(cls): @@ -857,7 +858,40 @@ class AutogenerateCustomCompareTypeTest(AutogenTest, TestBase): eq_(diffs[1][0][0], 'modify_type') +class PKConstraintUpgradesIgnoresNullableTest(AutogenTest, TestBase): + __backend__ = True + + # test workaround for SQLAlchemy issue #3023, alembic issue #199 + @classmethod + def _get_db_schema(cls): + m = MetaData() + + Table( + 'person_to_role', m, + Column('person_id', Integer, autoincrement=False), + Column('role_id', Integer, autoincrement=False), + PrimaryKeyConstraint('person_id', 'role_id') + ) + return m + + @classmethod + def _get_model_schema(cls): + return cls._get_db_schema() + + def test_no_change(self): + metadata = self.m2 + connection = self.context.bind + + diffs = [] + + autogenerate._produce_net_changes(connection, metadata, diffs, + self.autogen_context + ) + eq_(diffs, []) + + class AutogenKeyTest(AutogenTest, TestBase): + __only_on__ = 'sqlite' @classmethod def _get_db_schema(cls): @@ -903,6 +937,7 @@ class AutogenKeyTest(AutogenTest, TestBase): class AutogenVersionTableTest(AutogenTest, TestBase): + __only_on__ = 'sqlite' version_table_name = 'alembic_version' version_table_schema = None @@ -957,6 +992,7 @@ class AutogenCustomVersionTableAndSchemaTest(AutogenVersionTableTest): class AutogenerateDiffOrderTest(AutogenTest, TestBase): + __only_on__ = 'sqlite' @classmethod def _get_db_schema(cls): @@ -996,6 +1032,7 @@ class AutogenerateDiffOrderTest(AutogenTest, TestBase): class CompareMetadataTest(ModelOne, AutogenTest, TestBase): + __only_on__ = 'sqlite' def test_compare_metadata(self): metadata = self.m2 |