return "%s %s %s" % (
alter_table(compiler, element.table_name, element.schema),
alter_column(compiler, element.column_name),
- "NULL" if element.nullable else "SET NOT NULL"
+ "DROP NOT NULL" if element.nullable else "SET NOT NULL"
)
@compiles(ColumnType)
from alembic.ddl.impl import DefaultImpl
-from alembic.ddl.base import alter_table, AddColumn, ColumnName, format_table_name, format_column_name
+from alembic.ddl.base import alter_table, AddColumn, ColumnName, format_table_name, format_column_name, ColumnNullable, alter_column
from sqlalchemy.ext.compiler import compiles
class MSSQLImpl(DefaultImpl):
def mssql_add_column(compiler, column, **kw):
return "ADD %s" % compiler.get_column_specification(column, **kw)
+@compiles(ColumnNullable, 'mssql')
+def visit_column_nullable(element, compiler, **kw):
+ return "%s %s %s" % (
+ alter_table(compiler, element.table_name, element.schema),
+ alter_column(compiler, element.column_name),
+ "NULL" if element.nullable else "SET NOT NULL"
+ )
+
@compiles(ColumnName, 'mssql')
def visit_rename_column(element, compiler, **kw):
context.assert_contains("exec('alter table t1 drop constraint ' + @const_name)")
context.assert_contains("ALTER TABLE t1 DROP COLUMN c1")
+def test_alter_column_nullable():
+ context = _op_fixture('mssql')
+ op.alter_column("t", "c", nullable=True)
+ context.assert_(
+ "ALTER TABLE t ALTER COLUMN c NULL"
+ )
+
+def test_alter_column_not_nullable():
+ context = _op_fixture('mssql')
+ op.alter_column("t", "c", nullable=False)
+ context.assert_(
+ "ALTER TABLE t ALTER COLUMN c SET NOT NULL"
+ )
+
# TODO: when we add schema support
#def test_alter_column_rename_mssql_schema():
# context = _op_fixture('mssql')
context = _op_fixture()
op.alter_column("t", "c", nullable=True)
context.assert_(
- # TODO: not sure if this is supposed to be SET NULL
- "ALTER TABLE t ALTER COLUMN c NULL"
+ # TODO: not sure if this is PG only or standard
+ # SQL
+ "ALTER TABLE t ALTER COLUMN c DROP NOT NULL"
)
def test_alter_column_not_nullable():