Browse Source

Changed the mongodb migration handler name to a more generic one

Roland Haroutiounian 8 years ago
parent
commit
2e13ab78bc

+ 2
- 0
plugins/dummy_datasource/migration_handler.py View File

@@ -11,3 +11,5 @@ class DummyMigrationHandler(object):
11 11
     def register_model_state(self, em, state_hash):
12 12
         pass
13 13
 
14
+    def init_db(self):
15
+        pass

+ 8
- 10
plugins/mongodb_datasource/migration_handler.py View File

@@ -19,15 +19,14 @@ class MigrationHandlerError(Exception):
19 19
 @LodelHook('mongodb_mh_init_db')
20 20
 def mongodb_mh_init_db(conn_args=None):
21 21
     connection_args = get_connection_args('default') if conn_args is None else get_connection_args(conn_args['name'])
22
-    migration_handler = MongoDbMigrationHandler(conn_args=connection_args)
23
-    migration_handler._install_collections()
22
+    migration_handler = MigrationHandler(conn_args=connection_args)
23
+    migration_handler.init_db()
24 24
     migration_handler.database.close()
25 25
 
26
-class MongoDbMigrationHandler(object):
26
+class MigrationHandler(object):
27 27
 
28 28
     COMMANDS_IFEXISTS_DROP = 'drop'
29 29
     COMMANDS_IFEXISTS_NOTHING = 'nothing'
30
-    #INIT_COLLECTIONS_NAMES = ['object', 'relation', 'entitie', 'person', 'text', 'entry']
31 30
     MIGRATION_HANDLER_DEFAULT_SETTINGS = {'dry_run': False, 'foreign_keys': True, 'drop_if_exists': False}
32 31
 
33 32
     ## @brief Constructs a MongoDbMigrationHandler
@@ -50,16 +49,15 @@ class MongoDbMigrationHandler(object):
50 49
                                 username=conn_args['username'], password=conn_args['password'])
51 50
 
52 51
         self.dry_run = kwargs['dry_run'] if 'dry_run' in kwargs else \
53
-            MongoDbMigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['dry_run']
52
+            MigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['dry_run']
54 53
 
55 54
         self.foreign_keys = kwargs['foreign_keys'] if 'foreign_keys' in kwargs else \
56
-            MongoDbMigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['foreign_keys']
55
+            MigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['foreign_keys']
57 56
 
58 57
         self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_is_exists' in kwargs else \
59
-            MongoDbMigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['drop_if_exists']
58
+            MigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['drop_if_exists']
60 59
 
61 60
         self.init_collections_names = self._set_init_collection_names()
62
-        #self._install_collections()
63 61
 
64 62
     def _set_init_collection_names(self):
65 63
         collection_names = ['relation']
@@ -71,7 +69,7 @@ class MongoDbMigrationHandler(object):
71 69
         return collection_names
72 70
 
73 71
     ## @brief Installs the basis collections of the database
74
-    def _install_collections(self):
72
+    def init_db(self):
75 73
         init_collection_names = self.init_collections_names
76 74
         for collection_name in init_collection_names:
77 75
             prefix = collection_prefix['object'] if collection_name != 'relation' else collection_prefix['relation']
@@ -84,7 +82,7 @@ class MongoDbMigrationHandler(object):
84 82
     # @param if_exists str : defines the behavior to have if the collection to create already exists (default value : "nothing")
85 83
     def _create_collection(self, collection_name, charset='utf8', if_exists=COMMANDS_IFEXISTS_NOTHING):
86 84
         if collection_name in self.database.collection_names(include_system_collections=False):
87
-            if if_exists == MongoDbMigrationHandler.COMMANDS_IFEXISTS_DROP:
85
+            if if_exists == MigrationHandler.COMMANDS_IFEXISTS_DROP:
88 86
                 self._delete_collection(collection_name)
89 87
                 self.database.create_collection(name=collection_name)
90 88
         else:

+ 1
- 1
scripts/admin.py View File

@@ -25,5 +25,5 @@ def refresh_dyncode(model_file, translator, output_filename):
25 25
 
26 26
 def init_db(conn_args, editorial_model):
27 27
     migration_handler = MongoDbMigrationHandler(editorial_model, conn_args)
28
-    migration_handler._install_collections()
28
+    migration_handler.init_db()
29 29
     migration_handler.database.close()

+ 4
- 4
tests/migration_handler/test_db_init.py View File

@@ -7,7 +7,7 @@ class MongoDbMigrationHandlerTestCase(unittest.TestCase):
7 7
     def test_check_connection_args(self):
8 8
         empty_connection_args = {}
9 9
         with self.assertRaises(MigrationHandlerError):
10
-            MongoDbMigrationHandler(empty_connection_args)
10
+            MigrationHandler(empty_connection_args)
11 11
 
12 12
         bad_connection_args_dicts = [
13 13
             {'host': 'localhost', 'port': 20030},
@@ -16,11 +16,11 @@ class MongoDbMigrationHandlerTestCase(unittest.TestCase):
16 16
         ]
17 17
         for bad_connection_args_dict in bad_connection_args_dicts:
18 18
             with self.assertRaises(MigrationHandlerError):
19
-                MongoDbMigrationHandler(bad_connection_args_dict)
19
+                MigrationHandler(bad_connection_args_dict)
20 20
 
21 21
     ## @todo pass the connection arguments in the settings
22 22
     @unittest.skip
23 23
     def test_init_db(self):
24 24
         correct_connection_args = {'host': 'localhost', 'port': 28015, 'username': 'lodel_admin', 'password': 'lapwd', 'db_name': 'lodel'}
25
-        migration_handler = MongoDbMigrationHandler(correct_connection_args)
26
-        migration_handler._install_collections()
25
+        migration_handler = MigrationHandler(correct_connection_args)
26
+        migration_handler.init_db()

Loading…
Cancel
Save