| 1 | |
| 2 | == Database cleanup queries == |
| 3 | |
| 4 | All entities with more than one CURRENT_VERSION: |
| 5 | {{{ |
| 6 | select count(*) as cnt, id, node_type from openmind.node |
| 7 | where system_status = 'CURRENT_VERSION' |
| 8 | group by id |
| 9 | having cnt > 1 |
| 10 | order by cnt desc; |
| 11 | }}} |
| 12 | |
| 13 | All relations without source or target: |
| 14 | {{{ |
| 15 | select * from openmind.node where node_type = 'RELATION' and (source_id is null or target_id is null); |
| 16 | }}} |
| 17 | |
| 18 | All relations with target pointing at nonexistent entity: |
| 19 | {{{ |
| 20 | select * from openmind.node rel |
| 21 | left outer join openmind.node ent |
| 22 | on rel.target_id = ent.id |
| 23 | where |
| 24 | rel.node_type = 'RELATION' |
| 25 | and ent.id is null; |
| 26 | }}} |
| 27 | |
| 28 | All current relations pointing at non-current target entities: |
| 29 | {{{ |
| 30 | select * from openmind.node rel, openmind.node ent |
| 31 | where |
| 32 | rel.target_id = ent.id |
| 33 | and rel.target_modif = ent.modification_time |
| 34 | and rel.system_status = 'CURRENT_VERSION' |
| 35 | and ent.system_status != 'CURRENT_VERSION'; |
| 36 | }}} |