ICEHOUSE = 'icehouse'
+SUPPORTED_SCHEMA_VERSIONS = [ICEHOUSE]
+
+
+def check_db_schema_version(engine, metadata):
+ """Check that current version of the db schema is supported."""
+ version_table = sa.Table(
+ 'alembic_version', metadata, autoload=True, autoload_with=engine)
+ versions = [v[0] for v in engine.execute(version_table.select())]
+ if not versions:
+ raise ValueError(_("Missing version in alembic_versions table"))
+ elif len(versions) > 1:
+ raise ValueError(_("Multiple versions in alembic_versions table: %s")
+ % versions)
+ current_version = versions[0]
+ if current_version not in SUPPORTED_SCHEMA_VERSIONS:
+ raise SystemError(_("Unsupported database schema %(current)s. "
+ "Please migrate your database to one of following "
+ "versions: %(supported)s")
+ % {'current': current_version,
+ 'supported': ', '.join(SUPPORTED_SCHEMA_VERSIONS)}
+ )
+
+
# Duplicated from neutron.plugins.linuxbridge.common.constants to
# avoid having any dependency on the linuxbridge plugin being
# installed.
def __call__(self, connection_url, save_tables=False, tunnel_type=None,
vxlan_udp_port=None):
engine = sa.create_engine(connection_url)
- #TODO(marun) Check for the db version to ensure that it can be
- # safely migrated from.
metadata = sa.MetaData()
+ check_db_schema_version(engine, metadata)
+
self.define_ml2_tables(metadata)
# Autoload the ports table to ensure that foreign keys to it and