Browse Source

Init collection names are dynamically defined in the migration handler

Roland Haroutiounian 8 years ago
parent
commit
9ee52042bd
1 changed files with 14 additions and 7 deletions
  1. 14
    7
      plugins/mongodb_datasource/migration_handler.py

+ 14
- 7
plugins/mongodb_datasource/migration_handler.py View File

@@ -57,17 +57,24 @@ class MongoDbMigrationHandler(object):
57 57
         self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_is_exists' in kwargs else \
58 58
             MongoDbMigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['drop_if_exists']
59 59
 
60
+        self.init_collections_names = self._set_init_collection_names()
60 61
         #self._install_collections()
61 62
 
62
-    ## @brief Installs the basis collections of the database
63
-    def _install_collections(self):
63
+    def _set_init_collection_names(self):
64
+        collection_names = []
64 65
         init_collections = self.editorial_model.all_classes()
65 66
         for init_collection in init_collections.items():
66 67
             if init_collection.abstract:
67
-                collection_name = init_collection.uid
68
-                prefix = collection_prefix['object'] if collection_name != 'relation' else collection_prefix['relation']
69
-                collection_to_create = "%s%s" % (prefix, collection_name)
70
-                self._create_collection(collection_name=collection_to_create)
68
+                collection_names.append(init_collection.uid)
69
+        return collection_names
70
+
71
+    ## @brief Installs the basis collections of the database
72
+    def _install_collections(self):
73
+        init_collection_names = self.init_collections_names
74
+        for collection_name in init_collection_names:
75
+            prefix = collection_prefix['object'] if collection_name != 'relation' else collection_prefix['relation']
76
+            collection_to_create = "%s%s" % (prefix, collection_name)
77
+            self._create_collection(collection_name=collection_to_create)
71 78
 
72 79
     ## @brief Creates a collection in the database
73 80
     # @param collection_name str
@@ -134,7 +141,7 @@ class MongoDbMigrationHandler(object):
134 141
     ## @brief deletes a collection corresponding to a given uid
135 142
     # @see register_change()
136 143
     def _emclass_delete(self, model, uid, initial_state, new_state):
137
-        if uid not in MongoDbMigrationHandler.INIT_COLLECTIONS_NAMES:
144
+        if uid not in self.init_collections_names():
138 145
             collection_name = object_collection_name(model.classes(uid))
139 146
             self._delete_collection(collection_name)
140 147
 

Loading…
Cancel
Save