summaryrefslogtreecommitdiff
path: root/alembic/ddl
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <mozo@mozo.jp>2012-07-25 01:42:15 +0900
committerMoriyoshi Koizumi <mozo@mozo.jp>2012-07-25 01:42:15 +0900
commitb71bb01e7c4b0a10db039d43803a34fe90ddc7d8 (patch)
tree5003310a0232a50c6da5bd62505d1f7aa2d1e255 /alembic/ddl
parent74112002c1148473824cea8a6458020e819e1934 (diff)
downloadalembic-b71bb01e7c4b0a10db039d43803a34fe90ddc7d8.tar.gz
Support autoincrement and existing_autoincrement in alter_column for MySQL dialect.
It'd be impossible to alter an autoincremented column without this extension.
Diffstat (limited to 'alembic/ddl')
-rw-r--r--alembic/ddl/impl.py7
-rw-r--r--alembic/ddl/mssql.py8
-rw-r--r--alembic/ddl/mysql.py16
3 files changed, 23 insertions, 8 deletions
diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py
index 95ead4c..32e15e6 100644
--- a/alembic/ddl/impl.py
+++ b/alembic/ddl/impl.py
@@ -83,11 +83,14 @@ class DefaultImpl(object):
name=None,
type_=None,
schema=None,
+ autoincrement=None,
existing_type=None,
existing_server_default=None,
- existing_nullable=None
+ existing_nullable=None,
+ existing_autoincrement=None
):
-
+ if autoincrement is not None or existing_autoincrement is not None:
+ util.warn("nautoincrement and existing_autoincrement only make sense for MySQL")
if nullable is not None:
self._exec(base.ColumnNullable(table_name, column_name,
nullable, schema=schema,
diff --git a/alembic/ddl/mssql.py b/alembic/ddl/mssql.py
index 42e8447..d7eaba6 100644
--- a/alembic/ddl/mssql.py
+++ b/alembic/ddl/mssql.py
@@ -30,9 +30,11 @@ class MSSQLImpl(DefaultImpl):
name=None,
type_=None,
schema=None,
+ autoincrement=None,
existing_type=None,
existing_server_default=None,
- existing_nullable=None
+ existing_nullable=None,
+ existing_autoincrement=None
):
if nullable is not None and existing_type is None:
@@ -52,8 +54,10 @@ class MSSQLImpl(DefaultImpl):
nullable=nullable,
type_=type_,
schema=schema,
+ autoincrement=autoincrement,
existing_type=existing_type,
- existing_nullable=existing_nullable
+ existing_nullable=existing_nullable,
+ existing_autoincrement=existing_autoincrement
)
if server_default is not False:
diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py
index 17920b4..4d23c17 100644
--- a/alembic/ddl/mysql.py
+++ b/alembic/ddl/mysql.py
@@ -15,9 +15,11 @@ class MySQLImpl(DefaultImpl):
name=None,
type_=None,
schema=None,
+ autoincrement=None,
existing_type=None,
existing_server_default=None,
- existing_nullable=None
+ existing_nullable=None,
+ existing_autoincrement=None
):
self._exec(
MySQLAlterColumn(
@@ -29,6 +31,7 @@ class MySQLImpl(DefaultImpl):
else True,
type_=type_ if type_ is not None else existing_type,
default=server_default if server_default is not False else existing_server_default,
+ autoincrement=autoincrement if autoincrement is not None else existing_autoincrement
)
)
@@ -37,12 +40,14 @@ class MySQLAlterColumn(AlterColumn):
newname=None,
type_=None,
nullable=None,
- default=False):
+ default=False,
+ autoincrement=None):
super(AlterColumn, self).__init__(name, schema=schema)
self.column_name = column_name
self.nullable = nullable
self.newname = newname
self.default = default
+ self.autoincrement = autoincrement
if type_ is None:
raise util.CommandError(
"All MySQL ALTER COLUMN operations "
@@ -71,7 +76,8 @@ def _mysql_alter_column(element, compiler, **kw):
name=element.newname,
nullable=element.nullable,
server_default=element.default,
- type_=element.type_
+ type_=element.type_,
+ autoincrement=element.autoincrement
),
)
@@ -81,12 +87,14 @@ def render_value(compiler, expr):
else:
return compiler.sql_compiler.process(expr)
-def _mysql_colspec(compiler, name, nullable, server_default, type_):
+def _mysql_colspec(compiler, name, nullable, server_default, type_, autoincrement):
spec = "%s %s %s" % (
name,
compiler.dialect.type_compiler.process(type_),
"NULL" if nullable else "NOT NULL"
)
+ if autoincrement is not None:
+ spec += " AUTO_INCREMENT"
if server_default != False:
spec += " DEFAULT %s" % render_value(compiler, server_default)