Revision 47021
Added by Claudio Atzori about 7 years ago
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/patch-db/migrate_dsm.sql | ||
---|---|---|
1 |
-- cleanup the unnecessary functions: the following SQL produces the deletion statement list |
|
2 |
SELECT 'DROP FUNCTION ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ');' |
|
3 |
FROM pg_proc INNER JOIN pg_namespace ns ON (pg_proc.pronamespace = ns.oid) |
|
4 |
WHERE ns.nspname = 'public' order by proname; |
|
5 |
|
|
6 |
-- export the new dnet_dsm schema using |
|
7 |
-- pg_dump --schema-only -h localhost -U dnet dnet_dsm | gzip -c > /tmp/dnet_dsm.sql.gz |
|
8 |
-- rename tables and index names in order to include prefix "dsm_" |
|
9 |
-- import the dsm table schema to the existing openaire database: |
|
10 |
-- psql -h localhost -U dnet dnet_openaireplus -f dnet_dsm.sql |
|
11 |
|
|
12 |
-- insert into the new dsm_* tables picking the information from the old tables |
|
13 |
insert into dsm_datasources |
|
14 |
select d.id, |
|
15 |
d.officialname, |
|
16 |
d.englishname, |
|
17 |
d.websiteurl, |
|
18 |
d.logourl, |
|
19 |
d.contactemail, |
|
20 |
d.latitude, |
|
21 |
d.longitude, |
|
22 |
d.timezone, |
|
23 |
d.namespaceprefix, |
|
24 |
ARRAY(select trim(s) from unnest(string_to_array(d.od_languages, ',')) as s) as languages, |
|
25 |
ARRAY(select trim(s) from unnest(string_to_array(d.od_contenttypes, '-')) as s) as od_contenttypes, |
|
26 |
d.collectedfrom, |
|
27 |
d.dateofvalidation, |
|
28 |
d.optional1, |
|
29 |
d.optional2, |
|
30 |
d.datasourceclass as typology, |
|
31 |
d.provenanceactionclass as provenanceaction, |
|
32 |
d.dateofcollection, |
|
33 |
d.typology as platform, |
|
34 |
d.activationid, |
|
35 |
d.description, |
|
36 |
d.releasestartdate, |
|
37 |
d.releaseenddate, |
|
38 |
d.missionstatementurl, |
|
39 |
d.dataprovider, |
|
40 |
d.serviceprovider, |
|
41 |
d.databaseaccesstype, |
|
42 |
d.datauploadtype, |
|
43 |
d.databaseaccessrestriction, |
|
44 |
d.datauploadrestriction, |
|
45 |
d.versioning, |
|
46 |
d.citationguidelineurl, |
|
47 |
d.qualitymanagementkind, |
|
48 |
d.pidsystems, |
|
49 |
d.certificates, |
|
50 |
d.aggregator, |
|
51 |
d.issn, |
|
52 |
d.eissn, |
|
53 |
d.lissn, |
|
54 |
d.registeredby, |
|
55 |
ARRAY_AGG(s.name) as subjects |
|
56 |
from datasources d left outer join datasource_subject sd on (d.id = sd.datasource) left outer join subjects s on (sd.subject = s.id) |
|
57 |
group by |
|
58 |
d.id; |
|
59 |
|
|
60 |
insert into dsm_api |
|
61 |
select a.id, |
|
62 |
a.protocolclass as protocol, |
|
63 |
a.datasource, |
|
64 |
a.contentdescriptionclass as contentdescription, |
|
65 |
a.active, |
|
66 |
a.removable, |
|
67 |
a.typologyclass as typology, |
|
68 |
a.compatibilityclass as compatibility, |
|
69 |
... |
|
70 |
from api a left outer join apicollections ac on (a.id = ac.api) |
|
71 |
group by a.id; |
|
72 |
|
|
73 |
|
|
74 |
insert into dsm_apiparams |
|
75 |
select a.param, |
|
76 |
a.edited? a.original!, |
|
77 |
a.api |
|
78 |
from apicollections |
|
79 |
where ... |
|
80 |
|
|
81 |
|
|
82 |
insert into dsm_organizations |
|
83 |
select o.id, |
|
84 |
o.legalshortname, |
|
85 |
o.legalname, |
|
86 |
o.websiteurl, |
|
87 |
o.logourl, |
|
88 |
o.ec_legalbody, |
|
89 |
o.ec_legalperson, |
|
90 |
o.ec_nonprofit, |
|
91 |
o.ec_researchorganization, |
|
92 |
o.ec_highereducation, |
|
93 |
o.ec_internationalorganizationeurinterests, |
|
94 |
o.ec_internationalorganization, |
|
95 |
o.ec_enterprise, |
|
96 |
o.ec_smevalidated, |
|
97 |
o.ec_nutscode, |
|
98 |
o.countryclass as country, |
|
99 |
o.collectedfrom, |
|
100 |
o.optional1, |
|
101 |
o.optional2, |
|
102 |
o.dateofcollection, |
|
103 |
o.provenanceactionclass as provenanceaction |
|
104 |
from organizations o; |
|
105 |
|
|
106 |
insert into dsm_datasource_organization |
|
107 |
select dorg.datasource, dorg.organization |
|
108 |
from datasource_organization dorg; |
|
109 |
|
|
110 |
|
|
111 |
insert into dsm_identities |
|
112 |
select i.pid, i.issuertypeclass as issuertype |
|
113 |
from identities i; |
|
114 |
|
|
115 |
insert into dsm_datasourcepids |
|
116 |
select dp.datasource, dp.pid |
|
117 |
from datasourcepids dp; |
|
118 |
|
|
119 |
|
|
120 |
insert into dsm_organizationpids |
|
121 |
select op.organization, op.pid |
|
122 |
from organizationpids op; |
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
Also available in: Unified diff
early version