diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-22 12:51:53 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-22 16:09:44 -0500 |
commit | f99eb38ceb200b5d03776ab15d1d0473d7db83ea (patch) | |
tree | 5195b3cfa1f5b6ec397cfae39566d5b232de1bd0 /tests/test_autogen_render.py | |
parent | 62f2739e828a8fa31cfa955003acc44c9d042712 (diff) | |
download | alembic-f99eb38ceb200b5d03776ab15d1d0473d7db83ea.tar.gz |
Detect and render autoincrement for alter_column()
The ``autoincrement=True`` flag is now rendered within the
:meth:`.Operations.alter_column` operation if the source column indicates
that this flag should be set to True. The behavior is sensitive to
the SQLAlchemy version in place, as the "auto" default option is new
in SQLAlchemy 1.1. When the source column indicates autoincrement
as True or "auto", the flag will render as True if the original column
contextually indicates that it should have "autoincrement" keywords,
and when the source column explcitly sets it to False, this is also
rendered. The behavior is intended to preserve the AUTO_INCREMENT flag
on MySQL as the column is fully recreated on this backend. Note that this
flag does **not** support alteration of a column's "autoincrement" status,
as this is not portable across backends.
Change-Id: I746c4841752adf9342bfdca7c9255aae5110b2ef
Fixes: #413
Diffstat (limited to 'tests/test_autogen_render.py')
-rw-r--r-- | tests/test_autogen_render.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py index 7689d36..03d8d04 100644 --- a/tests/test_autogen_render.py +++ b/tests/test_autogen_render.py @@ -4,7 +4,7 @@ from alembic.testing import TestBase, exclusions, assert_raises from alembic.operations import ops from sqlalchemy import MetaData, Column, Table, String, \ - Numeric, CHAR, ForeignKey, DATETIME, Integer, \ + Numeric, CHAR, ForeignKey, DATETIME, Integer, BigInteger, \ CheckConstraint, Unicode, Enum, cast,\ UniqueConstraint, Boolean, ForeignKeyConstraint,\ PrimaryKeyConstraint, Index, func, text, DefaultClause @@ -1074,6 +1074,19 @@ class AutogenRenderTest(TestBase): "existing_type=sa.Integer(), nullable=True, schema='foo')" ) + def test_render_modify_type_w_autoincrement(self): + op_obj = ops.AlterColumnOp( + "sometable", "somecolumn", + modify_type=Integer(), existing_type=BigInteger(), + autoincrement=True + ) + eq_ignore_whitespace( + autogenerate.render_op_text(self.autogen_context, op_obj), + "op.alter_column('sometable', 'somecolumn', " + "existing_type=sa.BigInteger(), type_=sa.Integer(), " + "autoincrement=True)" + ) + def test_render_fk_constraint_kwarg(self): m = MetaData() t1 = Table('t', m, Column('c', Integer)) |