summaryrefslogtreecommitdiff
path: root/migrate/changeset
diff options
context:
space:
mode:
Diffstat (limited to 'migrate/changeset')
-rw-r--r--migrate/changeset/__init__.py1
-rw-r--r--migrate/changeset/ansisql.py106
-rw-r--r--migrate/changeset/constraint.py3
-rw-r--r--migrate/changeset/databases/firebird.py12
-rw-r--r--migrate/changeset/databases/mysql.py43
-rw-r--r--migrate/changeset/databases/oracle.py7
-rw-r--r--migrate/changeset/databases/postgres.py12
-rw-r--r--migrate/changeset/databases/sqlite.py8
-rw-r--r--migrate/changeset/schema.py10
9 files changed, 41 insertions, 161 deletions
diff --git a/migrate/changeset/__init__.py b/migrate/changeset/__init__.py
index fa3387d..80ea152 100644
--- a/migrate/changeset/__init__.py
+++ b/migrate/changeset/__init__.py
@@ -13,7 +13,6 @@ from sqlalchemy import __version__ as _sa_version
warnings.simplefilter('always', DeprecationWarning)
_sa_version = tuple(int(re.match("\d+", x).group(0)) for x in _sa_version.split("."))
-SQLA_06 = _sa_version >= (0, 6)
SQLA_07 = _sa_version >= (0, 7)
del re
diff --git a/migrate/changeset/ansisql.py b/migrate/changeset/ansisql.py
index 67d0b0e..9ded560 100644
--- a/migrate/changeset/ansisql.py
+++ b/migrate/changeset/ansisql.py
@@ -17,23 +17,19 @@ from sqlalchemy.schema import (ForeignKeyConstraint,
Index)
from migrate import exceptions
-from migrate.changeset import constraint, SQLA_06
+from migrate.changeset import constraint
-if not SQLA_06:
- from sqlalchemy.sql.compiler import SchemaGenerator, SchemaDropper
-else:
- from sqlalchemy.schema import AddConstraint, DropConstraint
- from sqlalchemy.sql.compiler import DDLCompiler
- SchemaGenerator = SchemaDropper = DDLCompiler
+from sqlalchemy.schema import AddConstraint, DropConstraint
+from sqlalchemy.sql.compiler import DDLCompiler
+SchemaGenerator = SchemaDropper = DDLCompiler
class AlterTableVisitor(SchemaVisitor):
"""Common operations for ``ALTER TABLE`` statements."""
- if SQLA_06:
- # engine.Compiler looks for .statement
- # when it spawns off a new compiler
- statement = ClauseElement()
+ # engine.Compiler looks for .statement
+ # when it spawns off a new compiler
+ statement = ClauseElement()
def append(self, s):
"""Append content to the SchemaIterator's query buffer."""
@@ -123,9 +119,8 @@ class ANSIColumnGenerator(AlterTableVisitor, SchemaGenerator):
name=column.primary_key_name)
cons.create()
- if SQLA_06:
- def add_foreignkey(self, fk):
- self.connection.execute(AddConstraint(fk))
+ def add_foreignkey(self, fk):
+ self.connection.execute(AddConstraint(fk))
class ANSIColumnDropper(AlterTableVisitor, SchemaDropper):
"""Extends ANSI SQL dropper for column dropping (``ALTER TABLE
@@ -232,10 +227,7 @@ class ANSISchemaChanger(AlterTableVisitor, SchemaGenerator):
def _visit_column_type(self, table, column, delta):
type_ = delta['type']
- if SQLA_06:
- type_text = str(type_.compile(dialect=self.dialect))
- else:
- type_text = type_.dialect_impl(self.dialect).get_col_spec()
+ type_text = str(type_.compile(dialect=self.dialect))
self.append("TYPE %s" % type_text)
def _visit_column_name(self, table, column, delta):
@@ -279,75 +271,17 @@ class ANSIConstraintCommon(AlterTableVisitor):
def visit_migrate_unique_constraint(self, *p, **k):
self._visit_constraint(*p, **k)
-if SQLA_06:
- class ANSIConstraintGenerator(ANSIConstraintCommon, SchemaGenerator):
- def _visit_constraint(self, constraint):
- constraint.name = self.get_constraint_name(constraint)
- self.append(self.process(AddConstraint(constraint)))
- self.execute()
-
- class ANSIConstraintDropper(ANSIConstraintCommon, SchemaDropper):
- def _visit_constraint(self, constraint):
- constraint.name = self.get_constraint_name(constraint)
- self.append(self.process(DropConstraint(constraint, cascade=constraint.cascade)))
- self.execute()
-
-else:
- class ANSIConstraintGenerator(ANSIConstraintCommon, SchemaGenerator):
+class ANSIConstraintGenerator(ANSIConstraintCommon, SchemaGenerator):
+ def _visit_constraint(self, constraint):
+ constraint.name = self.get_constraint_name(constraint)
+ self.append(self.process(AddConstraint(constraint)))
+ self.execute()
- def get_constraint_specification(self, cons, **kwargs):
- """Constaint SQL generators.
-
- We cannot use SA visitors because they append comma.
- """
-
- if isinstance(cons, PrimaryKeyConstraint):
- if cons.name is not None:
- self.append("CONSTRAINT %s " % self.preparer.format_constraint(cons))
- self.append("PRIMARY KEY ")
- self.append("(%s)" % ', '.join(self.preparer.quote(c.name, c.quote)
- for c in cons))
- self.define_constraint_deferrability(cons)
- elif isinstance(cons, ForeignKeyConstraint):
- self.define_foreign_key(cons)
- elif isinstance(cons, CheckConstraint):
- if cons.name is not None:
- self.append("CONSTRAINT %s " %
- self.preparer.format_constraint(cons))
- self.append("CHECK (%s)" % cons.sqltext)
- self.define_constraint_deferrability(cons)
- elif isinstance(cons, UniqueConstraint):
- if cons.name is not None:
- self.append("CONSTRAINT %s " %
- self.preparer.format_constraint(cons))
- self.append("UNIQUE (%s)" % \
- (', '.join(self.preparer.quote(c.name, c.quote) for c in cons)))
- self.define_constraint_deferrability(cons)
- else:
- raise exceptions.InvalidConstraintError(cons)
-
- def _visit_constraint(self, constraint):
-
- table = self.start_alter_table(constraint)
- constraint.name = self.get_constraint_name(constraint)
- self.append("ADD ")
- self.get_constraint_specification(constraint)
- self.execute()
-
-
- class ANSIConstraintDropper(ANSIConstraintCommon, SchemaDropper):
-
- def _visit_constraint(self, constraint):
- self.start_alter_table(constraint)
- self.append("DROP CONSTRAINT ")
- constraint.name = self.get_constraint_name(constraint)
- self.append(self.preparer.format_constraint(constraint))
- if constraint.cascade:
- self.cascade_constraint(constraint)
- self.execute()
-
- def cascade_constraint(self, constraint):
- self.append(" CASCADE")
+class ANSIConstraintDropper(ANSIConstraintCommon, SchemaDropper):
+ def _visit_constraint(self, constraint):
+ constraint.name = self.get_constraint_name(constraint)
+ self.append(self.process(DropConstraint(constraint, cascade=constraint.cascade)))
+ self.execute()
class ANSIDialect(DefaultDialect):
diff --git a/migrate/changeset/constraint.py b/migrate/changeset/constraint.py
index 476a456..96407bd 100644
--- a/migrate/changeset/constraint.py
+++ b/migrate/changeset/constraint.py
@@ -4,7 +4,6 @@
from sqlalchemy import schema
from migrate.exceptions import *
-from migrate.changeset import SQLA_06
class ConstraintChangeset(object):
"""Base class for Constraint classes."""
@@ -165,8 +164,6 @@ class CheckConstraint(ConstraintChangeset, schema.CheckConstraint):
table = kwargs.pop('table', table)
schema.CheckConstraint.__init__(self, sqltext, *args, **kwargs)
if table is not None:
- if not SQLA_06:
- self.table = table
self._set_parent(table)
self.colnames = colnames
diff --git a/migrate/changeset/databases/firebird.py b/migrate/changeset/databases/firebird.py
index 675666c..226728b 100644
--- a/migrate/changeset/databases/firebird.py
+++ b/migrate/changeset/databases/firebird.py
@@ -4,13 +4,10 @@
from sqlalchemy.databases import firebird as sa_base
from sqlalchemy.schema import PrimaryKeyConstraint
from migrate import exceptions
-from migrate.changeset import ansisql, SQLA_06
+from migrate.changeset import ansisql
-if SQLA_06:
- FBSchemaGenerator = sa_base.FBDDLCompiler
-else:
- FBSchemaGenerator = sa_base.FBSchemaGenerator
+FBSchemaGenerator = sa_base.FBDDLCompiler
class FBColumnGenerator(FBSchemaGenerator, ansisql.ANSIColumnGenerator):
"""Firebird column generator implementation."""
@@ -41,10 +38,7 @@ class FBColumnDropper(ansisql.ANSIColumnDropper):
# is deleted!
continue
- if SQLA_06:
- should_drop = column.name in cons.columns
- else:
- should_drop = cons.contains_column(column) and cons.name
+ should_drop = column.name in cons.columns
if should_drop:
self.start_alter_table(column)
self.append("DROP CONSTRAINT ")
diff --git a/migrate/changeset/databases/mysql.py b/migrate/changeset/databases/mysql.py
index badd9fe..6987b4b 100644
--- a/migrate/changeset/databases/mysql.py
+++ b/migrate/changeset/databases/mysql.py
@@ -6,13 +6,10 @@ from sqlalchemy.databases import mysql as sa_base
from sqlalchemy import types as sqltypes
from migrate import exceptions
-from migrate.changeset import ansisql, SQLA_06
+from migrate.changeset import ansisql
-if not SQLA_06:
- MySQLSchemaGenerator = sa_base.MySQLSchemaGenerator
-else:
- MySQLSchemaGenerator = sa_base.MySQLDDLCompiler
+MySQLSchemaGenerator = sa_base.MySQLDDLCompiler
class MySQLColumnGenerator(MySQLSchemaGenerator, ansisql.ANSIColumnGenerator):
pass
@@ -53,37 +50,11 @@ class MySQLSchemaChanger(MySQLSchemaGenerator, ansisql.ANSISchemaChanger):
class MySQLConstraintGenerator(ansisql.ANSIConstraintGenerator):
pass
-if SQLA_06:
- class MySQLConstraintDropper(MySQLSchemaGenerator, ansisql.ANSIConstraintDropper):
- def visit_migrate_check_constraint(self, *p, **k):
- raise exceptions.NotSupportedError("MySQL does not support CHECK"
- " constraints, use triggers instead.")
-
-else:
- class MySQLConstraintDropper(ansisql.ANSIConstraintDropper):
-
- def visit_migrate_primary_key_constraint(self, constraint):
- self.start_alter_table(constraint)
- self.append("DROP PRIMARY KEY")
- self.execute()
-
- def visit_migrate_foreign_key_constraint(self, constraint):
- self.start_alter_table(constraint)
- self.append("DROP FOREIGN KEY ")
- constraint.name = self.get_constraint_name(constraint)
- self.append(self.preparer.format_constraint(constraint))
- self.execute()
-
- def visit_migrate_check_constraint(self, *p, **k):
- raise exceptions.NotSupportedError("MySQL does not support CHECK"
- " constraints, use triggers instead.")
-
- def visit_migrate_unique_constraint(self, constraint, *p, **k):
- self.start_alter_table(constraint)
- self.append('DROP INDEX ')
- constraint.name = self.get_constraint_name(constraint)
- self.append(self.preparer.format_constraint(constraint))
- self.execute()
+
+class MySQLConstraintDropper(MySQLSchemaGenerator, ansisql.ANSIConstraintDropper):
+ def visit_migrate_check_constraint(self, *p, **k):
+ raise exceptions.NotSupportedError("MySQL does not support CHECK"
+ " constraints, use triggers instead.")
class MySQLDialect(ansisql.ANSIDialect):
diff --git a/migrate/changeset/databases/oracle.py b/migrate/changeset/databases/oracle.py
index bd761bc..2f16b5b 100644
--- a/migrate/changeset/databases/oracle.py
+++ b/migrate/changeset/databases/oracle.py
@@ -5,13 +5,10 @@ import sqlalchemy as sa
from sqlalchemy.databases import oracle as sa_base
from migrate import exceptions
-from migrate.changeset import ansisql, SQLA_06
+from migrate.changeset import ansisql
-if not SQLA_06:
- OracleSchemaGenerator = sa_base.OracleSchemaGenerator
-else:
- OracleSchemaGenerator = sa_base.OracleDDLCompiler
+OracleSchemaGenerator = sa_base.OracleDDLCompiler
class OracleColumnGenerator(OracleSchemaGenerator, ansisql.ANSIColumnGenerator):
diff --git a/migrate/changeset/databases/postgres.py b/migrate/changeset/databases/postgres.py
index 015ad65..10ea094 100644
--- a/migrate/changeset/databases/postgres.py
+++ b/migrate/changeset/databases/postgres.py
@@ -3,14 +3,10 @@
.. _`PostgreSQL`: http://www.postgresql.org/
"""
-from migrate.changeset import ansisql, SQLA_06
-
-if not SQLA_06:
- from sqlalchemy.databases import postgres as sa_base
- PGSchemaGenerator = sa_base.PGSchemaGenerator
-else:
- from sqlalchemy.databases import postgresql as sa_base
- PGSchemaGenerator = sa_base.PGDDLCompiler
+from migrate.changeset import ansisql
+
+from sqlalchemy.databases import postgresql as sa_base
+PGSchemaGenerator = sa_base.PGDDLCompiler
class PGColumnGenerator(PGSchemaGenerator, ansisql.ANSIColumnGenerator):
diff --git a/migrate/changeset/databases/sqlite.py b/migrate/changeset/databases/sqlite.py
index 447412d..5a13780 100644
--- a/migrate/changeset/databases/sqlite.py
+++ b/migrate/changeset/databases/sqlite.py
@@ -9,13 +9,11 @@ from copy import copy
from sqlalchemy.databases import sqlite as sa_base
from migrate import exceptions
-from migrate.changeset import ansisql, SQLA_06
+from migrate.changeset import ansisql
-if not SQLA_06:
- SQLiteSchemaGenerator = sa_base.SQLiteSchemaGenerator
-else:
- SQLiteSchemaGenerator = sa_base.SQLiteDDLCompiler
+SQLiteSchemaGenerator = sa_base.SQLiteDDLCompiler
+
class SQLiteCommon(object):
diff --git a/migrate/changeset/schema.py b/migrate/changeset/schema.py
index b61ff5b..c467cc5 100644
--- a/migrate/changeset/schema.py
+++ b/migrate/changeset/schema.py
@@ -11,7 +11,7 @@ from sqlalchemy.schema import ForeignKeyConstraint
from sqlalchemy.schema import UniqueConstraint
from migrate.exceptions import *
-from migrate.changeset import SQLA_06, SQLA_07
+from migrate.changeset import SQLA_07
from migrate.changeset.databases.visitor import (get_engine_visitor,
run_single_visitor)
@@ -349,10 +349,7 @@ class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem):
def process_column(self, column):
"""Processes default values for column"""
# XXX: this is a snippet from SA processing of positional parameters
- if not SQLA_06 and column.args:
- toinit = list(column.args)
- else:
- toinit = list()
+ toinit = list()
if column.server_default is not None:
if isinstance(column.server_default, sqlalchemy.FetchedValue):
@@ -367,9 +364,6 @@ class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem):
for_update=True))
if toinit:
column._init_items(*toinit)
-
- if not SQLA_06:
- column.args = []
def _get_table(self):
return getattr(self, '_table', None)