|
@@ -2,7 +2,7 @@
|
2
|
2
|
import datetime
|
3
|
3
|
|
4
|
4
|
from lodel.editorial_model.components import EmClass, EmField
|
5
|
|
-
|
|
5
|
+from lodel.editorial_model.model import EditorialModel
|
6
|
6
|
from .utils import get_connection_args, connect, collection_prefix, object_collection_name, mongo_fieldname
|
7
|
7
|
from lodel.leapi.datahandlers.base_classes import DataHandler
|
8
|
8
|
from lodel.plugin import LodelHook
|
|
@@ -16,7 +16,7 @@ class MigrationHandlerError(Exception):
|
16
|
16
|
pass
|
17
|
17
|
|
18
|
18
|
@LodelHook('mongodb_mh_init_db')
|
19
|
|
-def mongodb_mh_init_db(conn_args=None):
|
|
19
|
+def mongodb_mh_init_db(editorial_model, conn_args=None):
|
20
|
20
|
connection_args = get_connection_args('default') if conn_args is None else get_connection_args(conn_args['name'])
|
21
|
21
|
migration_handler = MongoDbMigrationHandler(connection_args)
|
22
|
22
|
migration_handler._install_collections()
|
|
@@ -26,13 +26,15 @@ class MongoDbMigrationHandler(object):
|
26
|
26
|
|
27
|
27
|
COMMANDS_IFEXISTS_DROP = 'drop'
|
28
|
28
|
COMMANDS_IFEXISTS_NOTHING = 'nothing'
|
29
|
|
- INIT_COLLECTIONS_NAMES = ['object', 'relation', 'entitie', 'person', 'text', 'entry']
|
|
29
|
+ #INIT_COLLECTIONS_NAMES = ['object', 'relation', 'entitie', 'person', 'text', 'entry']
|
30
|
30
|
MIGRATION_HANDLER_DEFAULT_SETTINGS = {'dry_run': False, 'foreign_keys': True, 'drop_if_exists': False}
|
31
|
31
|
|
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, conn_args=None, **kwargs):
|
|
35
|
+ def __init__(self, editorial_model, conn_args=None, **kwargs):
|
|
36
|
+ self.editorial_model = editorial_model
|
|
37
|
+
|
36
|
38
|
conn_args = get_connection_args() if conn_args is None else conn_args
|
37
|
39
|
|
38
|
40
|
if len(conn_args.keys()) == 0:
|
|
@@ -59,10 +61,13 @@ class MongoDbMigrationHandler(object):
|
59
|
61
|
|
60
|
62
|
## @brief Installs the basis collections of the database
|
61
|
63
|
def _install_collections(self):
|
62
|
|
- for collection_name in MongoDbMigrationHandler.INIT_COLLECTIONS_NAMES:
|
63
|
|
- prefix = collection_prefix['object'] if collection_name != 'relation' else collection_prefix['relation']
|
64
|
|
- collection_to_create = "%s%s" % (prefix, collection_name)
|
65
|
|
- self._create_collection(collection_name=collection_to_create)
|
|
64
|
+ init_collections = self.editorial_model.all_classes()
|
|
65
|
+ for init_collection in init_collections.items():
|
|
66
|
+ 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)
|
66
|
71
|
|
67
|
72
|
## @brief Creates a collection in the database
|
68
|
73
|
# @param collection_name str
|