From 8e67aa887954d81e98d418e67e06650268fa88be Mon Sep 17 00:00:00 2001 From: tonytan4ever Date: Fri, 9 Oct 2015 15:11:39 -0400 Subject: [PATCH] feat: default automatic C* schema migration to false in request Change-Id: I62cb2103f3a3721bd3baf38f97ca25fa4d897904 --- README.rst | 1 + etc/poppy.conf | 1 + poppy/storage/cassandra/driver.py | 12 ++++++++---- tests/unit/storage/cassandra/test_driver.py | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index f891a1e6..c005382c 100644 --- a/README.rst +++ b/README.rst @@ -75,6 +75,7 @@ installed and running in a Docker Container. cluster = keyspace = poppy migrations_path = /home/poppy/poppy/storage/cassandra/migrations + automatic_schema_migration = True #True is recommended for local dev machine 5. For logging, find the ``[DEFAULT]`` section in diff --git a/etc/poppy.conf b/etc/poppy.conf index 4d0cbc23..ac3e9796 100644 --- a/etc/poppy.conf +++ b/etc/poppy.conf @@ -88,6 +88,7 @@ keyspace = poppy replication_strategy = class:SimpleStrategy, replication_factor:1 # Path to directory containing CQL migration scripts migrations_path = /poppy/storage/cassandra/migrations +automatic_schema_migration = False [drivers:distributed_task:taskflow] jobboard_backend_type = zookeeper diff --git a/poppy/storage/cassandra/driver.py b/poppy/storage/cassandra/driver.py index e046b2e8..6820f8ed 100644 --- a/poppy/storage/cassandra/driver.py +++ b/poppy/storage/cassandra/driver.py @@ -73,6 +73,8 @@ CASSANDRA_OPTIONS = [ ), cfg.BoolOpt('archive_on_delete', default=True, help='Archive services on delete?'), + cfg.BoolOpt('automatic_schema_migration', default=False, + help='Automatically migrate schema in request ?') ] CASSANDRA_GROUP = 'drivers:storage:cassandra' @@ -121,10 +123,12 @@ def _connection(conf, datacenter, keyspace=None): except cassandra.InvalidRequest: _create_keyspace(session, keyspace, conf.replication_strategy) - migration_session = copy.copy(session) - migration_session.default_consistency_level = \ - getattr(cassandra.ConsistencyLevel, conf.migrations_consistency_level) - _run_migrations(conf.migrations_path, migration_session) + if conf.automatic_schema_migration: + migration_session = copy.copy(session) + migration_session.default_consistency_level = \ + getattr(cassandra.ConsistencyLevel, + conf.migrations_consistency_level) + _run_migrations(conf.migrations_path, migration_session) session.row_factory = query.dict_factory diff --git a/tests/unit/storage/cassandra/test_driver.py b/tests/unit/storage/cassandra/test_driver.py index 5af8acac..fabd6ba5 100644 --- a/tests/unit/storage/cassandra/test_driver.py +++ b/tests/unit/storage/cassandra/test_driver.py @@ -63,6 +63,8 @@ CASSANDRA_OPTIONS = [ ), cfg.BoolOpt('archive_on_delete', default=True, help='Archive services on delete?'), + cfg.BoolOpt('automatic_schema_migration', default=False, + help='Automatically migrate schema in request ?') ]