No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

migration_handler.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. from lodel.datasource.generic.migrationhandler import GenericMigrationHandler
  3. from lodel.datasource.mongodb.datasource import MongoDbDataSource
  4. from lodel.editorial_model.components import EmClass, EmField
  5. class MigrationHandlerChangeError(Exception):
  6. pass
  7. ## @brief Modifies a MongoDb database given editorial model changes
  8. class MongoDbMigrationHandler(GenericMigrationHandler):
  9. ## @brief constructs a MongoDbMigrationHandler
  10. # @param conn_args dict : a dictionary containing connection options
  11. # @param **kwargs : extra arguments given to the connection methods
  12. def __init__(self, conn_args=None, **kwargs):
  13. if conn_args is None:
  14. conn_args = {} # TODO : récupérer les options de connexion dans les settings
  15. self.connection_name = conn_args['name']
  16. # del conn_args['module']
  17. self.db_conn = MongoDbDataSource(self.connection_name)
  18. # TODO Réimplémenter la partie sur les settings
  19. mh_settings = {}
  20. self.dryrun = kwargs['dryrun'] if 'dryrun' in kwargs else mh_settings['dryrun']
  21. self.foreign_keys = kwargs['foreign_keys'] if 'foreign_keys' in kwargs else mh_settings['foreign_keys']
  22. self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_if_exists' in kwargs else mh_settings['drop_if_exists']
  23. self._create_default_collections(self.drop_if_exists)
  24. ## @brief Modify the database given an EM change
  25. #
  26. # @param em model : The EditorialModel.model object to provide the global context.
  27. # @param uid str : The uid of the changed component.
  28. # @param initial_state dict|None : dict with field name as key and field value as value. Represents the original state. None means it's a creation of a new component.
  29. # @param new_state dict|None : dict with field name as key and field value as value. Represents the new state. None means it's a component deletion.
  30. # @throw MigrationHandlerChangeError if the change was refused
  31. def register_change(self, em, uid, initial_state, new_state):
  32. pass
  33. def _create_default_collections(self, drop_if_exist=False):
  34. pass