Revision 48165
Added by Claudio Atzori almost 7 years ago
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/patch-db/migrate_dsm.sql | ||
---|---|---|
5 | 5 |
WHERE ns.nspname = 'public' |
6 | 6 |
ORDER BY proname; |
7 | 7 |
|
8 |
-- cleanup the unnecessary triggers: the following SQL produces the deletion statement list |
|
9 |
SELECT 'DROP TRIGGER ' || trg.tgname || ' ON ' || tbl.relname || ';' |
|
10 |
FROM pg_trigger trg |
|
11 |
JOIN pg_class tbl on trg.tgrelid = tbl.oid |
|
12 |
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace |
|
13 |
WHERE trg.tgname like 'notify_%'; |
|
14 |
|
|
8 | 15 |
-- export the new dnet_dsm schema using |
9 |
-- pg_dump --schema-only -h localhost -U dnet dnet_dsm | gzip -c > /tmp/dnet_dsm.sql.gz |
|
16 |
-- pg_dump --schema-only -h localhost -U dnet dnet_dsm | gzip -c > /tmp/dnet_dsm.sql.gz
|
|
10 | 17 |
-- rename tables and index names in order to include prefix "dsm_" |
11 | 18 |
-- import the dsm table schema to the existing openaire database: |
12 |
-- psql -h localhost -U dnet dnet_openaireplus -f dnet_dsm.sql |
|
19 |
-- psql -h localhost -U dnet dnet_openaireplus -f dnet_dsm.sql
|
|
13 | 20 |
|
14 | 21 |
-- insert into the new dsm_* tables picking the information from the old tables |
15 |
INSERT INTO dsm_datasources |
|
16 |
SELECT |
|
17 |
d.id, |
|
18 |
d.officialname, |
|
19 |
d.englishname, |
|
20 |
d.websiteurl, |
|
21 |
d.logourl, |
|
22 |
d.contactemail, |
|
23 |
d.latitude, |
|
24 |
d.longitude, |
|
25 |
d.timezone, |
|
26 |
d.namespaceprefix, |
|
27 |
ARRAY(SELECT trim(s) |
|
28 |
FROM unnest(string_to_array(d.od_languages, ',')) AS s) AS languages, |
|
29 |
ARRAY(SELECT trim(s) |
|
30 |
FROM unnest(string_to_array(d.od_contenttypes, '-')) AS s) AS od_contenttypes, |
|
31 |
d.collectedfrom, |
|
32 |
d.dateofvalidation, |
|
33 |
d.optional1, |
|
34 |
d.optional2, |
|
35 |
d.datasourceclass AS typology, |
|
36 |
d.provenanceactionclass AS provenanceaction, |
|
37 |
d.dateofcollection, |
|
38 |
d.typology AS platform, |
|
39 |
d.activationid, |
|
40 |
d.description, |
|
41 |
d.releasestartdate, |
|
42 |
d.releaseenddate, |
|
43 |
d.missionstatementurl, |
|
44 |
d.dataprovider, |
|
45 |
d.serviceprovider, |
|
46 |
d.databaseaccesstype, |
|
47 |
d.datauploadtype, |
|
48 |
d.databaseaccessrestriction, |
|
49 |
d.datauploadrestriction, |
|
50 |
d.versioning, |
|
51 |
d.citationguidelineurl, |
|
52 |
d.qualitymanagementkind, |
|
53 |
d.pidsystems, |
|
54 |
d.certificates, |
|
55 |
d.aggregator, |
|
56 |
d.issn, |
|
57 |
d.eissn, |
|
58 |
d.lissn, |
|
59 |
d.registeredby, |
|
60 |
ARRAY_AGG(s.name) AS subjects |
|
61 |
FROM datasources d LEFT OUTER JOIN datasource_subject sd ON (d.id = sd.datasource) |
|
62 |
LEFT OUTER JOIN subjects s ON (sd.subject = s.id) |
|
63 |
GROUP BY |
|
64 |
d.id; |
|
22 |
insert into dsm_datasources |
|
23 |
select d.id, |
|
24 |
d.officialname, |
|
25 |
d.englishname, |
|
26 |
d.websiteurl, |
|
27 |
d.logourl, |
|
28 |
d.contactemail, |
|
29 |
d.latitude, |
|
30 |
d.longitude, |
|
31 |
d.timezone, |
|
32 |
d.namespaceprefix, |
|
33 |
ARRAY(select trim(s) from unnest(string_to_array(d.od_languages, ',')) as s) as languages, |
|
34 |
ARRAY(select trim(s) from unnest(string_to_array(d.od_contenttypes, '-')) as s) as od_contenttypes, |
|
35 |
d.collectedfrom, |
|
36 |
d.dateofvalidation, |
|
37 |
d.optional1, |
|
38 |
d.optional2, |
|
39 |
d.datasourceclass as typology, |
|
40 |
d.provenanceactionclass as provenanceaction, |
|
41 |
d.dateofcollection, |
|
42 |
d.typology as platform, |
|
43 |
d.activationid, |
|
44 |
d.description, |
|
45 |
d.releasestartdate, |
|
46 |
d.releaseenddate, |
|
47 |
d.missionstatementurl, |
|
48 |
d.dataprovider, |
|
49 |
d.serviceprovider, |
|
50 |
d.databaseaccesstype, |
|
51 |
d.datauploadtype, |
|
52 |
d.databaseaccessrestriction, |
|
53 |
d.datauploadrestriction, |
|
54 |
d.versioning, |
|
55 |
d.citationguidelineurl, |
|
56 |
d.qualitymanagementkind, |
|
57 |
d.pidsystems, |
|
58 |
d.certificates, |
|
59 |
d.aggregator, |
|
60 |
d.issn, |
|
61 |
d.eissn, |
|
62 |
d.lissn, |
|
63 |
d.registeredby, |
|
64 |
ARRAY_AGG(s.name) as subjects |
|
65 |
from datasources d |
|
66 |
left outer join datasource_subject sd on (d.id = sd.datasource) |
|
67 |
left outer join subjects s on (sd.subject = s.id) |
|
68 |
group by |
|
69 |
d.id; |
|
65 | 70 |
|
66 |
INSERT INTO dsm_api |
|
67 |
SELECT |
|
68 |
a.id, |
|
69 |
a.protocolclass AS protocol, |
|
70 |
a.datasource, |
|
71 |
a.contentdescriptionclass AS contentdescription, |
|
72 |
a.active, |
|
73 |
a.removable, |
|
74 |
a.typologyclass AS typology, |
|
75 |
a.compatibilityclass AS compatibility, |
|
76 |
... |
|
77 |
FROM api a LEFT OUTER JOIN apicollections ac ON (a.id = ac.api) |
|
78 |
GROUP BY a.id; |
|
71 |
insert into dsm_api |
|
72 |
select a.id, |
|
73 |
a.protocolclass as protocol, |
|
74 |
a.datasource, |
|
75 |
a.contentdescriptionclass as contentdescription, |
|
76 |
a.active, |
|
77 |
a.removable, |
|
78 |
a.typologyclass as typology, |
|
79 |
a.compatibilityclass as compatibility |
|
80 |
from api a; |
|
79 | 81 |
|
82 |
update dsm_api da set metadata_identifier_path = ac.original from apicollections ac where da.id = ac.api and ac.param = 'metadata_identifier_path' ; |
|
83 |
update dsm_api da set last_collection_total = ac.original::integer from apicollections ac where da.id = ac.api and ac.param = 'last_collection_total' ; |
|
84 |
update dsm_api da set last_collection_date = ac.original::date from apicollections ac where da.id = ac.api and ac.param = 'last_collection_date' ; |
|
85 |
update dsm_api da set last_collection_mdid = ac.original from apicollections ac where da.id = ac.api and ac.param = 'last_collection_mdid' ; |
|
86 |
update dsm_api da set last_aggregation_total = ac.original::integer from apicollections ac where da.id = ac.api and ac.param = 'last_aggregation_total' ; |
|
87 |
update dsm_api da set last_aggregation_date = ac.original::date from apicollections ac where da.id = ac.api and ac.param = 'last_aggregation_date' ; |
|
88 |
update dsm_api da set last_aggregation_mdid = ac.original from apicollections ac where da.id = ac.api and ac.param = 'last_aggregation_mdid' ; |
|
89 |
update dsm_api da set last_download_total = ac.original::integer from apicollections ac where da.id = ac.api and ac.param = 'last_download_total' ; |
|
90 |
update dsm_api da set last_download_date = ac.original::date from apicollections ac where da.id = ac.api and ac.param = 'last_download_date' ; |
|
91 |
update dsm_api da set last_download_objid = ac.original from apicollections ac where da.id = ac.api and ac.param = 'last_download_objid' ; |
|
92 |
update dsm_api da set last_validation_job = ac.original from apicollections ac where da.id = ac.api and ac.param = 'last_validation_job' ; |
|
93 |
update dsm_api da set baseurl = CASE WHEN (ac.edited is not null and ac.edited != '') THEN ac.edited ELSE ac.original END from apicollections ac where da.id = ac.api and ac.param = 'baseUrl' ; |
|
80 | 94 |
|
81 |
INSERT INTO dsm_apiparams |
|
82 |
SELECT |
|
83 |
a.param, |
|
84 |
a.edited ? a.original !, |
|
85 |
a.api |
|
86 |
FROM apicollections |
|
87 |
WHERE ... |
|
95 |
insert into dsm_apiparams |
|
96 |
select |
|
97 |
a.param, |
|
98 |
CASE |
|
99 |
WHEN (a.edited is not null and a.edited != '') THEN a.edited ELSE a.original |
|
100 |
END AS value, |
|
101 |
a.api |
|
102 |
from apicollections a |
|
103 |
where param != 'baseUrl' AND accessparam is true; |
|
88 | 104 |
|
89 |
|
|
90 | 105 |
INSERT INTO dsm_organizations |
91 | 106 |
SELECT |
92 | 107 |
o.id, |
... | ... | |
138 | 153 |
op.pid |
139 | 154 |
FROM organizationpids op; |
140 | 155 |
|
156 |
-- !!!!! data insert complete !!!!! |
|
157 |
-- TODO add below the deletion statements for the old tables. |
|
141 | 158 |
|
142 | 159 |
|
143 | 160 |
|
... | ... | |
155 | 172 |
|
156 | 173 |
|
157 | 174 |
|
175 |
|
|
176 |
|
Also available in: Unified diff
updated DSM migration instructions