]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
make sure type gets the prefix in modify type
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Nov 2011 22:48:33 +0000 (17:48 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Nov 2011 22:48:33 +0000 (17:48 -0500)
alembic/autogenerate.py
tests/test_autogenerate.py

index 2eb6e71894376f3c4d1f2b8281aaa6affa567e7a..173b8730c0516195af6789f309bf8f6f6392fb01 100644 (file)
@@ -223,9 +223,12 @@ def _drop_column(tname, column):
     return "drop_column(%r, %r)" % (tname, column.name)
 
 def _modify_type(tname, cname, type_):
-    return "alter_column(%r, %r, type=%r)" % (
-        tname, cname, type_
-    )
+    return "alter_column(%(tname)r, %(cname)r, type=%(prefix)s%(type)r)" % {
+        'prefix':_autogenerate_prefix(),
+        'tname':tname, 
+        'cname':cname, 
+        'type':type_
+    }
 
 def _modify_nullable(tname, cname, nullable):
     return "alter_column(%r, %r, nullable=%r)" % (
index 475135617a0b67ed33fbd8aa3e7a6e74cac0b733..7b30a1117c2b4d5b8eb4640522e826afeaadf94c 100644 (file)
@@ -1,8 +1,8 @@
 from sqlalchemy import MetaData, Column, Table, Integer, String, Text, \
-    Numeric, CHAR, NUMERIC, ForeignKey, DATETIME
+    Numeric, CHAR, ForeignKey, DATETIME
 from alembic import autogenerate, context
 from unittest import TestCase
-from tests import staging_env, sqlite_db, clear_staging_env, eq_, eq_ignore_whitespace, capture_context_buffer, _no_sql_testing_config, _testing_config
+from tests import staging_env, sqlite_db, clear_staging_env, eq_, eq_ignore_whitespace
 
 def _model_one():
     m = MetaData()
@@ -59,7 +59,7 @@ def _model_two():
 class AutogenerateDiffTest(TestCase):
     @classmethod
     def setup_class(cls):
-        env = staging_env()
+        staging_env()
         cls.bind = sqlite_db()
         cls.m1 = _model_one()
         cls.m1.create_all(cls.bind)
@@ -69,6 +69,8 @@ class AutogenerateDiffTest(TestCase):
         clear_staging_env()
 
     def test_diffs(self):
+        """test generation of diff rules"""
+
         metadata = _model_two()
         connection = self.bind.connect()
         diffs = []
@@ -99,11 +101,13 @@ class AutogenerateDiffTest(TestCase):
         )
 
     def test_render_diffs(self):
+        """test a full render including indentation"""
+
         metadata = _model_two()
         connection = self.bind.connect()
         template_args = {}
         context.configure(
-            connection=self.bind.connect()
+            connection=connection
             autogenerate_metadata=metadata)
         autogenerate.produce_migration_diffs(template_args)
         eq_(template_args['upgrades'],
@@ -116,7 +120,7 @@ class AutogenerateDiffTest(TestCase):
     drop_table(u'extra')
     drop_column('user', u'pw')
     alter_column('user', 'name', nullable=False)
-    alter_column('order', u'amount', type=Numeric(precision=10, scale=2))
+    alter_column('order', u'amount', type=sa.Numeric(precision=10, scale=2))
     alter_column('order', u'amount', nullable=True)
     add_column('address', sa.Column('street', sa.String(length=50), nullable=True))
     ### end Alembic commands ###""")
@@ -129,12 +133,14 @@ class AutogenerateDiffTest(TestCase):
     )
     add_column('user', sa.Column(u'pw', sa.VARCHAR(length=50), nullable=True))
     alter_column('user', 'name', nullable=True)
-    alter_column('order', u'amount', type=NUMERIC(precision=8, scale=2))
+    alter_column('order', u'amount', type=sa.NUMERIC(precision=8, scale=2))
     alter_column('order', u'amount', nullable=False)
     drop_column('address', 'street')
     ### end Alembic commands ###""")
 
 class AutogenRenderTest(TestCase):
+    """test individual directives"""
+
     @classmethod
     def setup_class(cls):
         context._context_opts['autogenerate_sqlalchemy_prefix'] = 'sa.'
@@ -186,7 +192,7 @@ class AutogenRenderTest(TestCase):
         eq_(
             autogenerate._modify_type(
                         "sometable", "somecolumn", CHAR(10)),
-            "alter_column('sometable', 'somecolumn', type=CHAR(length=10))"
+            "alter_column('sometable', 'somecolumn', type=sa.CHAR(length=10))"
         )
 
     def test_render_modify_nullable(self):