[c-c db-check] add some sql queries to fix cw_source/is/is_instance relations according to data in the entities table stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 22 Jul 2011 15:58:05 +0200
branchstable
changeset 7687 4f5ab60e71cc
parent 7686 6580b5a0f1cf
child 7688 f1b6e7c09a6f
[c-c db-check] add some sql queries to fix cw_source/is/is_instance relations according to data in the entities table
server/checkintegrity.py
--- a/server/checkintegrity.py	Fri Jul 22 15:41:17 2011 +0200
+++ b/server/checkintegrity.py	Fri Jul 22 15:58:05 2011 +0200
@@ -188,6 +188,18 @@
             if fix:
                 session.system_sql('DELETE FROM entities WHERE eid=%s;' % eid)
             notify_fixed(fix)
+    session.system_sql('INSERT INTO cw_source_relation (eid_from, eid_to) '
+                       'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWSource as s '
+                       'WHERE s.cw_name=e.asource AND NOT EXISTS(SELECT 1 FROM cw_source_relation as cs '
+                       '  WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)')
+    session.system_sql('INSERT INTO is_relation (eid_from, eid_to) '
+                       'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWEType as s '
+                       'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_relation as cs '
+                       '  WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)')
+    session.system_sql('INSERT INTO is_instance_of_relation (eid_from, eid_to) '
+                       'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWEType as s '
+                       'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_instance_of_relation as cs '
+                       '  WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)')
     print 'Checking entities tables'
     for eschema in schema.entities():
         if eschema.final: