equal
deleted
inserted
replaced
172 |
172 |
173 @_checker |
173 @_checker |
174 def check_text_index(schema, cnx, eids, fix=1): |
174 def check_text_index(schema, cnx, eids, fix=1): |
175 """check all entities registered in the text index""" |
175 """check all entities registered in the text index""" |
176 print('Checking text index') |
176 print('Checking text index') |
177 msg = ' Entity with eid %s exists in the text index but in no source (autofix will remove from text index)' |
177 msg = (' Entity with eid %s exists in the text index but not in any ' |
|
178 'entity type table (autofix will remove from text index)') |
178 cursor = cnx.system_sql('SELECT uid FROM appears;') |
179 cursor = cnx.system_sql('SELECT uid FROM appears;') |
179 for row in cursor.fetchall(): |
180 for row in cursor.fetchall(): |
180 eid = row[0] |
181 eid = row[0] |
181 if not has_eid(cnx, cursor, eid, eids): |
182 if not has_eid(cnx, cursor, eid, eids): |
182 sys.stderr.write(msg % eid) |
183 sys.stderr.write(msg % eid) |
188 @_checker |
189 @_checker |
189 def check_entities(schema, cnx, eids, fix=1): |
190 def check_entities(schema, cnx, eids, fix=1): |
190 """check all entities registered in the repo system table""" |
191 """check all entities registered in the repo system table""" |
191 print('Checking entities system table') |
192 print('Checking entities system table') |
192 # system table but no source |
193 # system table but no source |
193 msg = ' Entity %s with eid %s exists in the system table but in no source (autofix will delete the entity)' |
194 msg = (' Entity %s with eid %s exists in "entities" table but not in any ' |
|
195 'entity type table (autofix will delete the entity)') |
194 cursor = cnx.system_sql('SELECT eid,type FROM entities;') |
196 cursor = cnx.system_sql('SELECT eid,type FROM entities;') |
195 for row in cursor.fetchall(): |
197 for row in cursor.fetchall(): |
196 eid, etype = row |
198 eid, etype = row |
197 if not has_eid(cnx, cursor, eid, eids): |
199 if not has_eid(cnx, cursor, eid, eids): |
198 sys.stderr.write(msg % (etype, eid)) |
200 sys.stderr.write(msg % (etype, eid)) |
241 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWEType as s ' |
243 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWEType as s ' |
242 'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_instance_of_relation as cs ' |
244 'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_instance_of_relation as cs ' |
243 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)') |
245 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)') |
244 notify_fixed(True) |
246 notify_fixed(True) |
245 print('Checking entities tables') |
247 print('Checking entities tables') |
246 msg = ' Entity with eid %s exists in the %s table but not in the system table (autofix will delete the entity)' |
248 msg = (' Entity with eid %s exists in the %s table but not in "entities" ' |
|
249 'table (autofix will delete the entity)') |
247 for eschema in schema.entities(): |
250 for eschema in schema.entities(): |
248 if eschema.final: |
251 if eschema.final: |
249 continue |
252 continue |
250 table = SQL_PREFIX + eschema.type |
253 table = SQL_PREFIX + eschema.type |
251 column = SQL_PREFIX + 'eid' |
254 column = SQL_PREFIX + 'eid' |
260 cnx.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid)) |
263 cnx.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid)) |
261 notify_fixed(fix) |
264 notify_fixed(fix) |
262 |
265 |
263 |
266 |
264 def bad_related_msg(rtype, target, eid, fix): |
267 def bad_related_msg(rtype, target, eid, fix): |
265 msg = ' A relation %s with %s eid %s exists but no such entity in sources' |
268 msg = (' A relation %(rtype)s with %(target)s eid %(eid)d exists but ' |
266 sys.stderr.write(msg % (rtype, target, eid)) |
269 'entity #(eid)d does not exist') |
|
270 sys.stderr.write(msg % {'rtype': rtype, 'target': target, 'eid': eid}) |
267 notify_fixed(fix) |
271 notify_fixed(fix) |
268 |
272 |
269 |
273 |
270 def bad_inlined_msg(rtype, parent_eid, eid, fix): |
274 def bad_inlined_msg(rtype, parent_eid, eid, fix): |
271 msg = (' An inlined relation %s from %s to %s exists but the latter ' |
275 msg = (' An inlined relation %s from %s to %s exists but the latter ' |