[sources] Drop 'moved_entities' table handling
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 29 Sep 2016 11:44:19 +0200
changeset 11757 e845746b4d3c
parent 11756 60fed6272771
child 11758 3f81636a75db
[sources] Drop 'moved_entities' table handling This was clumsy and could be handled using exturi / cwsource, as the ldap source now does.
cubicweb/hooks/metadata.py
cubicweb/misc/migration/3.21.0_Any.py
cubicweb/misc/migration/3.21.2_Any.py
cubicweb/misc/migration/3.24.0_Any.py
cubicweb/server/checkintegrity.py
cubicweb/server/sources/datafeed.py
cubicweb/server/sources/native.py
--- a/cubicweb/hooks/metadata.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/hooks/metadata.py	Thu Sep 29 11:44:19 2016 +0200
@@ -200,15 +200,6 @@
             syssource = newsource.repo_source
             oldsource = self._cw.entity_from_eid(schange[self.eidfrom])
             entity = self._cw.entity_from_eid(self.eidfrom)
-            # we don't want the moved entity to be reimported later.  To
-            # distinguish this state, move the record from the 'entities' table
-            # to 'moved_entities'.  External source will then have consider
-            # case where `extid2eid` returns a negative eid as 'this entity was
-            # known but has been moved, ignore it'.
-            extid = self._cw.entity_metas(entity.eid)['extid']
-            assert extid is not None
-            attrs = {'eid': entity.eid, 'extid': b64encode(extid).decode('ascii')}
-            self._cw.system_sql(syssource.sqlgen.insert('moved_entities', attrs), attrs)
             attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None,
                      'asource': 'system'}
             self._cw.system_sql(syssource.sqlgen.update('entities', attrs, ['eid']), attrs)
--- a/cubicweb/misc/migration/3.21.0_Any.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/misc/migration/3.21.0_Any.py	Thu Sep 29 11:44:19 2016 +0200
@@ -133,21 +133,7 @@
 for query in helper.sqls_create_multicol_unique_index('entities', ['extid']):
     cu.execute(query)
 
-if 'moved_entities' not in helper.list_tables(cu):
-    sql('''
-    CREATE TABLE moved_entities (
-      eid INTEGER PRIMARY KEY NOT NULL,
-      extid VARCHAR(256) UNIQUE
-    )
-    ''')
-
-moved_entities = sql('SELECT -eid, extid FROM entities WHERE eid < 0',
-                     ask_confirm=False)
-if moved_entities:
-    cu.executemany('INSERT INTO moved_entities (eid, extid) VALUES (%s, %s)',
-                   moved_entities)
-    sql('DELETE FROM entities WHERE eid < 0')
-
+sql('DELETE FROM entities WHERE eid < 0')
 commit()
 
 sync_schema_props_perms('CWEType')
--- a/cubicweb/misc/migration/3.21.2_Any.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/misc/migration/3.21.2_Any.py	Thu Sep 29 11:44:19 2016 +0200
@@ -1,7 +1,1 @@
 sync_schema_props_perms('cwuri')
-
-helper = repo.system_source.dbhelper
-cu = session.cnxset.cu
-helper.set_null_allowed(cu, 'moved_entities', 'extid', 'VARCHAR(256)', False)
-
-commit()
--- a/cubicweb/misc/migration/3.24.0_Any.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/misc/migration/3.24.0_Any.py	Thu Sep 29 11:44:19 2016 +0200
@@ -2,3 +2,5 @@
 add_entity_type('CWSession')
 rql('DELETE CWProperty X WHERE X pkey "system.version.pyramid"',
     ask_confirm=False)
+
+sql('DROP TABLE moved_entities')
--- a/cubicweb/server/checkintegrity.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/server/checkintegrity.py	Thu Sep 29 11:44:19 2016 +0200
@@ -447,8 +447,7 @@
     schema = cnx.repo.schema
     schema_indices = SYSTEM_INDICES.copy()
     if source.dbdriver == 'postgres':
-        schema_indices.update({'appears_words_idx': ('appears', 'words'),
-                               'moved_entities_extid_key': ('moved_entities', 'extid')})
+        schema_indices.update({'appears_words_idx': ('appears', 'words')})
         index_filter = lambda idx: not (idx.startswith('pg_') or idx.endswith('_pkey'))
     else:
         schema_indices.update({'appears_uid': ('appears', 'uid'),
--- a/cubicweb/server/sources/datafeed.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/server/sources/datafeed.py	Thu Sep 29 11:44:19 2016 +0200
@@ -233,8 +233,7 @@
         source_uris = self.source_uris(cnx)
         try:
             parser = self._get_parser(cnx, import_log=importlog,
-                                      source_uris=source_uris,
-                                      moved_uris=self.moved_uris(cnx))
+                                      source_uris=source_uris)
         except ObjectNotFound:
             msg = 'failed to load parser for %s'
             importlog.record_error(msg % ('source "%s"' % self.uri))
@@ -260,10 +259,6 @@
         return dict((self.decode_extid(uri), (eid, type))
                     for uri, eid, type in cnx.system_sql(sql, {'source': self.uri}).fetchall())
 
-    def moved_uris(self, cnx):
-        sql = 'SELECT extid FROM moved_entities'
-        return set(self.decode_extid(uri) for uri, in cnx.system_sql(sql).fetchall())
-
     def init_import_log(self, cnx, import_log_eid=None, **kwargs):
         if import_log_eid is None:
             import_log = cnx.create_entity('CWDataImport', cw_import_of=self,
@@ -280,16 +275,13 @@
 class DataFeedParser(AppObject):
     __registry__ = 'parsers'
 
-    def __init__(self, cnx, source, import_log=None, source_uris=None, moved_uris=None):
+    def __init__(self, cnx, source, import_log=None, source_uris=None):
         super(DataFeedParser, self).__init__(cnx)
         self.source = source
         self.import_log = import_log
         if source_uris is None:
             source_uris = {}
         self.source_uris = source_uris
-        if moved_uris is None:
-            moved_uris = ()
-        self.moved_uris = moved_uris
         self.stats = {'created': set(), 'updated': set(), 'checked': set()}
 
     def normalize_url(self, url):
--- a/cubicweb/server/sources/native.py	Fri Sep 30 17:36:40 2016 +0200
+++ b/cubicweb/server/sources/native.py	Thu Sep 29 11:44:19 2016 +0200
@@ -1361,10 +1361,6 @@
   extid VARCHAR(256)
 );;
 CREATE INDEX entities_type_idx ON entities(type);;
-CREATE TABLE moved_entities (
-  eid INTEGER PRIMARY KEY NOT NULL,
-  extid VARCHAR(256) UNIQUE NOT NULL
-);;
 
 CREATE TABLE transactions (
   tx_uuid CHAR(32) PRIMARY KEY NOT NULL,