From cd8fa2b0e7ca002b7621fe0e35b921154946e12b Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Fri, 14 Jun 2013 13:03:41 -0500 Subject: Use InnoDB for MySQL This change adds a migration to convert any non-InnoDB tables to InnoDB. On some systems, the default engine is MyISAM, which doesn't support features used by Keystone (foreign keys). The approach is the same as what's used in Nova. A test is added to ensure that all tables use InnoDB after migration. The test passes when all the tables are mysql_engine='InnoDB'. This is accomplished by adding a new migration that migrates all the tables that aren't InnoDB to InnoDB. Fixes bug 1191110. Change-Id: I220f7642f5468c5cf4194f248210f90ff983b6e5 --- tests/test_sql_upgrade.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/test_sql_upgrade.py') diff --git a/tests/test_sql_upgrade.py b/tests/test_sql_upgrade.py index 21db6ade..e7e34b4b 100644 --- a/tests/test_sql_upgrade.py +++ b/tests/test_sql_upgrade.py @@ -506,6 +506,10 @@ class SqlUpgradeTests(test.TestCase): def test_downgrade_to_0(self): self.upgrade(self.max_version) + + if self.engine.name == 'mysql': + self._mysql_check_all_tables_innodb() + self.downgrade(0) for table_name in ["user", "token", "role", "user_tenant_membership", "metadata"]: @@ -961,3 +965,26 @@ class SqlUpgradeTests(test.TestCase): for ver, change in changeset: self.schema.runchange(ver, change, changeset.step) self.assertEqual(self.schema.version, version) + + def _mysql_check_all_tables_innodb(self): + database = self.engine.url.database + + connection = self.engine.connect() + # sanity check + total = connection.execute("SELECT count(*) " + "from information_schema.TABLES " + "where TABLE_SCHEMA='%(database)s'" % + locals()) + self.assertTrue(total.scalar() > 0, "No tables found. Wrong schema?") + + noninnodb = connection.execute("SELECT table_name " + "from information_schema.TABLES " + "where TABLE_SCHEMA='%(database)s' " + "and ENGINE!='InnoDB' " + "and TABLE_NAME!='migrate_version'" % + locals()) + names = [x[0] for x in noninnodb] + self.assertEqual(names, [], + "Non-InnoDB tables exist") + + connection.close() -- cgit