From: David Szotten Date: Thu, 16 Oct 2014 16:25:34 +0000 (+0100) Subject: Create index in add_column if requested X-Git-Tag: rel_0_7_0~35^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d9ea4bb754f8792a897b2092b6b9e469197610c;p=thirdparty%2Fsqlalchemy%2Falembic.git Create index in add_column if requested Fixes #174 --- diff --git a/alembic/operations.py b/alembic/operations.py index 11319f73..d3cc1b08 100644 --- a/alembic/operations.py +++ b/alembic/operations.py @@ -468,6 +468,8 @@ class Operations(object): for constraint in t.constraints: if not isinstance(constraint, sa_schema.PrimaryKeyConstraint): self.impl.add_constraint(constraint) + for index in t.indexes: + self.impl._exec(sa_schema.CreateIndex(index)) def drop_column(self, table_name, column_name, **kw): """Issue a "drop column" instruction using the current diff --git a/tests/test_op.py b/tests/test_op.py index 835183eb..c157030a 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -147,6 +147,15 @@ class OpTest(TestBase): context.assert_( "ALTER TABLE t1 ADD COLUMN c1 INTEGER DEFAULT '12' NOT NULL") + def test_add_column_with_index(self): + context = op_fixture() + op.add_column( + 't1', Column('c1', Integer, nullable=False, index=True)) + context.assert_( + "ALTER TABLE t1 ADD COLUMN c1 INTEGER NOT NULL", + "CREATE INDEX ix_t1_c1 ON t1 (c1)", + ) + def test_add_column_schema_with_default(self): context = op_fixture() op.add_column('t1',