Issue one SQL statement per execute() call

Some sqlalchemy drivers only support a single SQL statement per
execute() call.  It isn't 100% clear from the sqlalchemy docs, but the
sqlalchemy author confirmed that this is the intention.

Change-Id: I2f696a5894ce7722114a2da054b42d9ffac56b83
This commit is contained in:
Angus Lees 2014-08-13 11:32:38 +10:00
parent c66a0f33a7
commit 676f9cba78

View File

@ -18,14 +18,15 @@ def upgrade(migrate_engine):
if migrate_engine.name == "mysql":
tables = ['meter', 'user', 'resource', 'project', 'source',
'sourceassoc']
sql = "SET foreign_key_checks = 0;"
migrate_engine.execute("SET foreign_key_checks = 0")
for table in tables:
sql += "ALTER TABLE %s CONVERT TO CHARACTER SET utf8;" % table
sql += "SET foreign_key_checks = 1;"
sql += ("ALTER DATABASE %s DEFAULT CHARACTER SET utf8;" %
migrate_engine.execute(
"ALTER TABLE %s CONVERT TO CHARACTER SET utf8" % table)
migrate_engine.execute("SET foreign_key_checks = 1")
migrate_engine.execute(
"ALTER DATABASE %s DEFAULT CHARACTER SET utf8" %
migrate_engine.url.database)
migrate_engine.execute(sql)
def downgrade(migrate_engine):
@ -33,11 +34,12 @@ def downgrade(migrate_engine):
if migrate_engine.name == "mysql":
tables = ['meter', 'user', 'resource', 'project', 'source',
'sourceassoc']
sql = "SET foreign_key_checks = 0;"
migrate_engine.execute("SET foreign_key_checks = 0")
for table in tables:
sql += "ALTER TABLE %s CONVERT TO CHARACTER SET latin1;" % table
sql += "SET foreign_key_checks = 1;"
sql += ("ALTER DATABASE %s DEFAULT CHARACTER SET latin1;" %
migrate_engine.execute(
"ALTER TABLE %s CONVERT TO CHARACTER SET latin1" % table)
migrate_engine.execute("SET foreign_key_checks = 1")
migrate_engine.execute(
"ALTER DATABASE %s DEFAULT CHARACTER SET latin1" %
migrate_engine.url.database)
migrate_engine.execute(sql)