]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Set InnoDB engine for all existing tables
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Thu, 24 Jul 2014 10:33:02 +0000 (14:33 +0400)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Tue, 19 Aug 2014 07:44:54 +0000 (11:44 +0400)
Added the method in heal script that checks if mysql_engine
parameter is needed to be changed and if it is neseccary do this.
Also this change adds migation that set 'mysql_engine' to InnoDB
for all tables that were added into the database after healing.

Closes-bug: #1346966

Change-Id: Ia4d9038b99b2559d37272a17f5819a9dedd53f72

neutron/db/migration/alembic_migrations/heal_script.py
neutron/db/migration/alembic_migrations/versions/327ee5fde2c7_set_innodb_engine.py [new file with mode: 0644]
neutron/db/migration/alembic_migrations/versions/HEAD

index 276008171f74164bded158fd9ed912592cb1ba48..dacb87474203bc1e310e2a3b361eb421dbffaac8 100644 (file)
@@ -69,7 +69,7 @@ def heal():
         'compare_server_default': _compare_server_default,
     }
     mc = alembic.migration.MigrationContext.configure(op.get_bind(), opts=opts)
-
+    set_storage_engine(op.get_bind(), "InnoDB")
     diff1 = autogen.compare_metadata(mc, models_metadata)
     # Alembic does not contain checks for foreign keys. Because of that it
     # checks separately.
@@ -320,3 +320,11 @@ def _compare_server_default(ctxt, ins_col, meta_col, insp_def, meta_def,
         )
 
     return None  # tells alembic to use the default comparison method
+
+
+def set_storage_engine(bind, engine):
+    insp = sqlalchemy.engine.reflection.Inspector.from_engine(bind)
+    if bind.dialect.name == 'mysql':
+        for table in insp.get_table_names():
+            if insp.get_table_options(table)['mysql_engine'] != engine:
+                op.execute("ALTER TABLE %s ENGINE=%s" % (table, engine))
diff --git a/neutron/db/migration/alembic_migrations/versions/327ee5fde2c7_set_innodb_engine.py b/neutron/db/migration/alembic_migrations/versions/327ee5fde2c7_set_innodb_engine.py
new file mode 100644 (file)
index 0000000..8b34c51
--- /dev/null
@@ -0,0 +1,46 @@
+# Copyright 2014 OpenStack Foundation
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+#
+
+"""set_innodb_engine
+
+Revision ID: 327ee5fde2c7
+Revises: 2026156eab2f
+Create Date: 2014-07-24 12:00:38.791287
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '327ee5fde2c7'
+down_revision = '4eba2f05c2f4'
+
+
+from alembic import op
+
+# This list contain tables that could be deployed before change that converts
+# all tables to InnoDB appeared
+TABLES = ['router_extra_attributes', 'dvr_host_macs', 'ml2_dvr_port_bindings',
+          'csnat_l3_agent_bindings']
+
+
+def upgrade(active_plugins=None, options=None):
+
+    if op.get_bind().dialect.name == 'mysql':
+        for table in TABLES:
+            op.execute("ALTER TABLE %s ENGINE=InnoDB" % table)
+
+
+def downgrade(active_plugins=None, options=None):
+
+    pass
index 6ea58e91e7d6cf2972de27f760f1d0a1a0cf9b2b..86f1f1dcbee6bafa761cc0792c31d17c594f7c3c 100644 (file)
@@ -1 +1 @@
-4eba2f05c2f4
+327ee5fde2c7