|
@@ -19,8 +19,8 @@ class MigrationHandlerError(Exception):
|
19
|
19
|
@LodelHook('mongodb_mh_init_db')
|
20
|
20
|
def mongodb_mh_init_db(classes_list, 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 = MigrationHandler(classes_list, conn_args=connection_args)
|
23
|
|
- migration_handler.init_db()
|
|
22
|
+ migration_handler = MigrationHandler(conn_args=connection_args)
|
|
23
|
+ migration_handler.init_db(classes_list)
|
24
|
24
|
migration_handler.database.close()
|
25
|
25
|
|
26
|
26
|
class MigrationHandler(object):
|
|
@@ -32,11 +32,22 @@ class MigrationHandler(object):
|
32
|
32
|
## @brief Constructs a MongoDbMigrationHandler
|
33
|
33
|
# @param conn_args dict : a dictionary containing the connection options
|
34
|
34
|
# @param **kwargs : extra arguments
|
35
|
|
- def __init__(self, classes_list, conn_args=None, **kwargs):
|
36
|
|
- self._classes_handled = classes_list
|
37
|
|
-
|
38
|
|
- conn_args = get_connection_args() if conn_args is None else conn_args
|
39
|
|
-
|
|
35
|
+ def __init__(self, **kwargs):
|
|
36
|
+
|
|
37
|
+ conn_args = dict()
|
|
38
|
+ if 'host' in kwargs:
|
|
39
|
+ conn_args['host'] = kwargs['host']
|
|
40
|
+ if 'port' in kwargs:
|
|
41
|
+ conn_args['port'] = kwargs['port']
|
|
42
|
+ if 'db_name' in kwargs:
|
|
43
|
+ conn_args['db_name'] = kwargs['db_name']
|
|
44
|
+ if 'username' in kwargs:
|
|
45
|
+ conn_args['username'] = kwargs['username']
|
|
46
|
+ if 'password' in kwargs:
|
|
47
|
+ conn_args['password'] = kwargs['password']
|
|
48
|
+
|
|
49
|
+ if len(conn_args.keys()) == 0:
|
|
50
|
+ conn_args = get_connection_args()
|
40
|
51
|
if len(conn_args.keys()) == 0:
|
41
|
52
|
raise MigrationHandlerError("No connection arguments were given")
|
42
|
53
|
|
|
@@ -55,12 +66,12 @@ class MigrationHandler(object):
|
55
|
66
|
|
56
|
67
|
self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_is_exists' in kwargs else \
|
57
|
68
|
MigrationHandler.MIGRATION_HANDLER_DEFAULT_SETTINGS['drop_if_exists']
|
58
|
|
-
|
59
|
|
- self._set_init_collection_names()
|
60
|
|
-
|
61
|
|
- def _set_init_collection_names(self):
|
|
69
|
+
|
|
70
|
+ self.init_collections_names = None
|
|
71
|
+
|
|
72
|
+ def _set_init_collection_names(self, emclass_list):
|
62
|
73
|
collection_names = ['relation']
|
63
|
|
- for dynclass in self._classes_handled:
|
|
74
|
+ for dynclass in emclass_list:
|
64
|
75
|
if not dynclass.is_abstract() \
|
65
|
76
|
and isinstance(dynclass._ro_datasource,MongoDbDatasource) \
|
66
|
77
|
and isinstance(dynclass._rw_datasource, MongoDbDatasource):
|
|
@@ -68,7 +79,8 @@ class MigrationHandler(object):
|
68
|
79
|
self.init_collections_names = collection_names
|
69
|
80
|
|
70
|
81
|
## @brief Installs the basis collections of the database
|
71
|
|
- def init_db(self):
|
|
82
|
+ def init_db(self, emclass_list):
|
|
83
|
+ self.init_collections_names(emclass_list)
|
72
|
84
|
init_collection_names = self.init_collections_names
|
73
|
85
|
for collection_name in init_collection_names:
|
74
|
86
|
prefix = collection_prefix['object'] if collection_name != 'relation' else collection_prefix['relation']
|