Project

General

Profile

1
/**
2
 * Correct generated System Metadata entries
3
 * 1. find system metadata with incomplete revision history
4
 */
5

    
6
-- these are old (obsoleted) entries that are not marked as such
7
select sm.guid, sm.obsoleted_by, sm.obsoletes, sm_by.guid as should_be_obsoleted_by
8
from systemmetadata sm, systemmetadata sm_by
9
where sm.guid = sm_by.obsoletes
10
and sm.obsoleted_by is null;
11
-- update them
12
BEGIN;
13
update systemmetadata sm
14
set obsoleted_by = sm_by.guid,
15
date_modified = now()
16
from systemmetadata sm_by
17
where sm.guid = sm_by.obsoletes
18
and sm.obsoleted_by is null;
19
--ROLLBACK;
20
COMMIT;
21

    
22
-- these are ones that should be marked as newer revisions
23
select sm.guid, sm.obsoleted_by, sm.obsoletes, sm_s.guid as should_obsolete
24
from systemmetadata sm, systemmetadata sm_s
25
where sm.guid = sm_s.obsoleted_by
26
and sm.obsoletes is null;
27

    
28
-- these are ones that should be marked as archived=true but are not
29
select sm. guid --count(sm.guid)
30
from systemmetadata sm, identifier id
31
where sm.guid = id.guid
32
and not exists (select * from xml_documents doc where doc.docid = id.docid and doc.rev = id.rev)
33
and sm.archived != true
34
and sm.obsoleted_by is null;
35

    
36
-- update them
37
BEGIN;
38
update systemmetadata sm
39
set archived = true
40
from identifier id
41
where sm.guid = id.guid
42
and not exists (select * from xml_documents doc where doc.docid = id.docid and doc.rev = id.rev)
43
and sm.archived != true
44
and sm.obsoleted_by is null;
45
COMMIT;
46
--ROLLBACK;
(26-26/83)