diff options
Diffstat (limited to 'migrate/changeset/databases/mysql.py')
-rw-r--r-- | migrate/changeset/databases/mysql.py | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/migrate/changeset/databases/mysql.py b/migrate/changeset/databases/mysql.py index 5b5a16e..6655a42 100644 --- a/migrate/changeset/databases/mysql.py +++ b/migrate/changeset/databases/mysql.py @@ -2,13 +2,13 @@ MySQL database specific implementations of changeset classes. """ +from migrate.changeset import ansisql, exceptions, SQLA_06 from sqlalchemy.databases import mysql as sa_base -from migrate.changeset import ansisql, exceptions - - -MySQLSchemaGenerator = sa_base.MySQLSchemaGenerator - +if not SQLA_06: + MySQLSchemaGenerator = sa_base.MySQLSchemaGenerator +else: + MySQLSchemaGenerator = sa_base.MySQLDDLCompiler class MySQLColumnGenerator(MySQLSchemaGenerator, ansisql.ANSIColumnGenerator): pass @@ -39,31 +39,37 @@ class MySQLSchemaChanger(MySQLSchemaGenerator, ansisql.ANSISchemaChanger): class MySQLConstraintGenerator(ansisql.ANSIConstraintGenerator): pass - -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() +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 MySQLDialect(ansisql.ANSIDialect): |