From: Mike Bayer Date: Wed, 25 Apr 2012 15:10:42 +0000 (-0400) Subject: - [bug] Fixed support of schema-qualified X-Git-Tag: rel_0_3_2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2747894d2c5212e718a2631eb4984b55074f710a;p=thirdparty%2Fsqlalchemy%2Falembic.git - [bug] Fixed support of schema-qualified ForeignKey target in column alter operations, courtesy Alexander Kolov. --- diff --git a/CHANGES b/CHANGES index 23523a03..0f980847 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,10 @@ - [feature] Added support for UniqueConstraint in autogenerate, courtesy Atsushi Odagiri +- [bug] Fixed support of schema-qualified + ForeignKey target in column alter operations, + courtesy Alexander Kolov. + 0.3.1 ===== - [bug] bulk_insert() fixes: diff --git a/alembic/util.py b/alembic/util.py index d5fa5a45..fb0c51a5 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -18,7 +18,12 @@ class CommandError(Exception): pass from sqlalchemy import __version__ -_vers = tuple([int(x) for x in __version__.split(".")]) +def _safe_int(value): + try: + return int(value) + except: + return 0 +_vers = tuple([_safe_int(x) for x in __version__.split(".")]) sqla_06 = _vers > (0, 6) sqla_07 = _vers > (0, 7) if not sqla_06: diff --git a/tests/test_op.py b/tests/test_op.py index 2d6a29b1..71d78d95 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -62,6 +62,14 @@ def test_add_column_fk_self_referential(): "ALTER TABLE t1 ADD FOREIGN KEY(c1) REFERENCES t1 (c2)" ) +def test_add_column_fk_schema(): + context = op_fixture() + op.add_column('t1', Column('c1', Integer, ForeignKey('remote.t2.c2'), nullable=False)) + context.assert_( + 'ALTER TABLE t1 ADD COLUMN c1 INTEGER NOT NULL', + 'ALTER TABLE t1 ADD FOREIGN KEY(c1) REFERENCES remote.t2 (c2)' + ) + def test_drop_column(): context = op_fixture() op.drop_column('t1', 'c1')