]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
add engine parameter for offline migrations
authorJakub Libosvar <libosvar@redhat.com>
Tue, 8 Apr 2014 10:41:11 +0000 (12:41 +0200)
committerJakub Libosvar <libosvar@redhat.com>
Tue, 3 Jun 2014 12:19:09 +0000 (14:19 +0200)
Offline migration required config file containing connection string.
In that case only engine from URL was used. With this patch engine can be
passed from command line (or config file) along with plugins which sql
script will be generated accordingly.

DocImpact

Change-Id: Ib667a71960b833fd981f97fe7d6b1856084ef5c8
Closes-Bug: #1304326

etc/neutron.conf
neutron/db/migration/alembic_migrations/env.py
neutron/db/migration/cli.py

index 8da95c97028733831b774d80d83aa6d1b6958522..2455f2fd75d1f51ac624791765c7891696b6f26b 100644 (file)
@@ -414,6 +414,10 @@ admin_password = %SERVICE_PASSWORD%
 # main neutron server. (Leave it as is if the database runs on this host.)
 # connection = sqlite://
 
+# Database engine for which script will be generated when using offline
+# migration
+# engine =
+
 # The SQLAlchemy connection string used to connect to the slave database
 # slave_connection =
 
index 98352ffb75a865ee0cb4f193d7cf7341b4c7349e..88502779282b779411bda11e10f56f6a090b6d2f 100644 (file)
@@ -48,16 +48,19 @@ target_metadata = model_base.BASEV2.metadata
 def run_migrations_offline():
     """Run migrations in 'offline' mode.
 
-    This configures the context with just a URL
-    and not an Engine, though an Engine is acceptable
-    here as well.  By skipping the Engine creation
-    we don't even need a DBAPI to be available.
+    This configures the context with either a URL
+    or an Engine.
 
     Calls to context.execute() here emit the given string to the
     script output.
 
     """
-    context.configure(url=neutron_config.database.connection)
+    kwargs = dict()
+    if neutron_config.database.connection:
+        kwargs['url'] = neutron_config.database.connection
+    else:
+        kwargs['dialect_name'] = neutron_config.database.engine
+    context.configure(**kwargs)
 
     with context.begin_transaction():
         context.run_migrations(active_plugins=active_plugins,
index 850806e898b5de5188ea67c3451be2226e75e7ad..6a5da8baeb15c06a23030e8c85e9cacf7c88c821 100644 (file)
@@ -46,11 +46,14 @@ _db_opts = [
                deprecated_name='sql_connection',
                default='',
                help=_('URL to database')),
+    cfg.StrOpt('engine',
+               default='',
+               help=_('Database engine')),
 ]
 
 CONF = cfg.ConfigOpts()
-CONF.register_opts(_core_opts)
-CONF.register_opts(_db_opts, 'database')
+CONF.register_cli_opts(_core_opts)
+CONF.register_cli_opts(_db_opts, 'database')
 CONF.register_opts(_quota_opts, 'QUOTAS')