# HG changeset patch # User Sylvain Thénault # Date 1475046134 -7200 # Node ID 307d96c0ab5a028d0fb3250aba5d61c431c960a6 # Parent 9a3663ec4ead07bc959cccea6ea9e1ae51513594 [massive store] Follow configuration of the metadata generator Don't drop constraints and indexes for tables that are ignored by the metadata generator given to the store. One may now easily disable insertion of e.g. created_by / owned_by by removing them from the MetadataGenerator.META_RELATIONS set, in which case indexes for associated table won't be removed by the massive store. diff -r 9a3663ec4ead -r 307d96c0ab5a cubicweb/dataimport/massive_store.py --- a/cubicweb/dataimport/massive_store.py Mon Oct 17 16:53:28 2016 +0200 +++ b/cubicweb/dataimport/massive_store.py Wed Sep 28 09:02:14 2016 +0200 @@ -119,10 +119,12 @@ They will be recreated by the `finish` method. """ - for tablename in ('created_by_relation', 'owned_by_relation', - 'is_instance_of_relation', 'is_relation'): - self._dbh.drop_constraints(tablename) - self._dbh.drop_indexes(tablename) + rtypes = [rtype for rtype in self.metagen.meta_relations + if not self.schema.rschema(rtype).final] + rtypes += ('is_instance_of', 'is', 'cw_source') + for rtype in rtypes: + self._dbh.drop_constraints(rtype + '_relation') + self._dbh.drop_indexes(rtype + '_relation') # don't drop constraints for the entities table, the only one is the primary key's index on # eid and we want to keep it self._dbh.drop_indexes('entities') diff -r 9a3663ec4ead -r 307d96c0ab5a cubicweb/dataimport/stores.py --- a/cubicweb/dataimport/stores.py Mon Oct 17 16:53:28 2016 +0200 +++ b/cubicweb/dataimport/stores.py Wed Sep 28 09:02:14 2016 +0200 @@ -416,10 +416,7 @@ """ __deprecation_warning__ = '[3.23] this class is deprecated, use MetadataGenerator instead' - META_RELATIONS = (META_RTYPES - - VIRTUAL_RTYPES - - set(('eid', 'cwuri', - 'is', 'is_instance_of', 'cw_source'))) + META_RELATIONS = MetadataGenerator.META_RELATIONS def __init__(self, cnx, baseurl=None, source=None): self._cnx = cnx diff -r 9a3663ec4ead -r 307d96c0ab5a cubicweb/dataimport/test/test_massive_store.py --- a/cubicweb/dataimport/test/test_massive_store.py Mon Oct 17 16:53:28 2016 +0200 +++ b/cubicweb/dataimport/test/test_massive_store.py Wed Sep 28 09:02:14 2016 +0200 @@ -154,6 +154,19 @@ self.assertIn(build_index_name('owned_by_relation', ['eid_from'], 'idx_'), indexes) + def test_consider_metagen(self): + """Ensure index on owned_by is not deleted if we don't consider this metadata.""" + with self.admin_access.repo_cnx() as cnx: + metagen = stores.MetadataGenerator(cnx, meta_skipped=('owned_by',)) + store = MassiveObjectStore(cnx, metagen=metagen) + + store._drop_constraints() + indexes = all_indexes(cnx) + self.assertIn(build_index_name('owned_by_relation', ['eid_from', 'eid_to'], 'key_'), + indexes) + self.assertIn(build_index_name('owned_by_relation', ['eid_from'], 'idx_'), + indexes) + def test_eids_seq_range(self): with self.admin_access.repo_cnx() as cnx: store = MassiveObjectStore(cnx, eids_seq_range=1000)