format_table_name, format_column_name, ColumnNullable, alter_column,\
format_server_default, ColumnDefault, format_type, ColumnType
from sqlalchemy.sql.expression import ClauseElement, Executable
+from sqlalchemy.schema import CreateIndex, Column
+from sqlalchemy import types as sqltypes
class MSSQLImpl(DefaultImpl):
schema=schema,
name=name)
+ def create_index(self, index):
+ mssql_include = index.kwargs.get('mssql_include', ())
+ for col in mssql_include:
+ if col not in index.table.c:
+ index.table.append_column(Column(col, sqltypes.NullType))
+ self._exec(CreateIndex(index))
+
def bulk_insert(self, table, rows, **kw):
if self.as_sql:
self._exec(
format_table_name(compiler, element.table_name, element.schema),
format_table_name(compiler, element.new_table_name, None)
)
+
--- /dev/null
+.. change::
+ :tags: bug, mssql
+ :tickets: 513
+
+ Fixed issue where usage of the SQL Server ``mssql_include`` option within a
+ :meth:`.Operations.create_index` would raise a KeyError, as the additional
+ column(s) need to be added to the table object used by the construct
+ internally.
context.assert_(
"EXEC sp_rename 'y.t.c', x, 'COLUMN'"
)
+
+ def test_create_index_mssql_include(self):
+ context = op_fixture('mssql')
+ op.create_index(
+ op.f('ix_mytable_a_b'), 'mytable', ['col_a', 'col_b'],
+ unique=False, mssql_include=['col_c'])
+ context.assert_contains(
+ "CREATE INDEX ix_mytable_a_b ON mytable "
+ "(col_a, col_b) INCLUDE (col_c)")