|
@@ -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:
|