Project

General

Profile

1
--
2
-- PostgreSQL database dump
3
--
4

    
5
-- Dumped from database version 9.4.1
6
-- Dumped by pg_dump version 9.6.2
7

    
8
SET statement_timeout = 0;
9
SET lock_timeout = 0;
10
SET client_encoding = 'UTF8';
11
SET standard_conforming_strings = on;
12
SET check_function_bodies = false;
13
SET client_min_messages = warning;
14
SET row_security = off;
15

    
16
--
17
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: 
18
--
19

    
20
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
21

    
22

    
23
SET search_path = public, pg_catalog;
24

    
25
SET default_tablespace = '';
26

    
27
SET default_with_oids = false;
28

    
29
--
30
-- Name: dsm_api; Type: TABLE; Schema: public; Owner: dnet
31
--
32

    
33
CREATE TABLE dsm_api (
34
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
35
    id character varying(255) NOT NULL,
36
    protocol character varying(255),
37
    datasource character varying(255),
38
    contentdescription character varying(255) DEFAULT 'metadata'::character varying,
39
    active boolean DEFAULT false,
40
    removable boolean DEFAULT false,
41
    typology character varying(255) DEFAULT 'UNKNOWN'::character varying,
42
    compatibility character varying(255) DEFAULT 'UNKNOWN'::character varying,
43
    compatibility_override character varying(255) DEFAULT null,
44
    metadata_identifier_path character varying(512) DEFAULT NULL::character varying,
45
    last_collection_total integer,
46
    last_collection_date timestamp without time zone,
47
    last_collection_mdid character varying(255) DEFAULT NULL::character varying,
48
    last_aggregation_total integer,
49
    last_aggregation_date timestamp without time zone,
50
    last_aggregation_mdid character varying(255) DEFAULT NULL::character varying,
51
    last_download_total integer,
52
    last_download_date timestamp without time zone,
53
    last_download_objid character varying(255) DEFAULT NULL::character varying,
54
    last_validation_job character varying(255) DEFAULT NULL::character varying,
55
    baseurl text
56
);
57

    
58

    
59
ALTER TABLE dsm_api OWNER TO dnetapi;
60
ALTER TABLE ONLY dsm_api ADD CONSTRAINT dsm_api_pkey PRIMARY KEY (id);
61
ALTER TABLE ONLY dsm_api ADD CONSTRAINT dsm_api_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
62

    
63
--
64
-- Name: dsm_apiparams; Type: TABLE; Schema: public; Owner: dnet
65
--
66

    
67
CREATE TABLE dsm_apiparams (
68
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
69
    param character varying(255) NOT NULL,
70
    value character varying(255) DEFAULT ''::character varying NOT NULL,
71
    api character varying(255) NOT NULL
72
);
73

    
74

    
75
ALTER TABLE dsm_apiparams OWNER TO dnetapi;
76
ALTER TABLE ONLY dsm_apiparams ADD CONSTRAINT dsm_apicollection_pkey PRIMARY KEY (api, param);
77
ALTER TABLE ONLY dsm_apiparams ADD CONSTRAINT dsm_apicollections_api_fkey FOREIGN KEY (api) REFERENCES dsm_api(id);
78

    
79

    
80

    
81
--
82
-- Name: dsm_datasource_organization; Type: TABLE; Schema: public; Owner: dnet
83
--
84

    
85
CREATE TABLE dsm_datasource_organization (
86
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
87
    datasource character varying(255) NOT NULL,
88
    organization character varying(255) NOT NULL
89
);
90

    
91

    
92
ALTER TABLE dsm_datasource_organization OWNER TO dnet;
93
ALTER TABLE ONLY dsm_datasource_organization ADD CONSTRAINT dsm_organization_datasource_pkey PRIMARY KEY (datasource, organization);
94
ALTER TABLE ONLY dsm_datasource_organization ADD CONSTRAINT dsm_datasource_organization_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
95
ALTER TABLE ONLY dsm_datasource_organization ADD CONSTRAINT dsm_datasource_organization_organization_fkey FOREIGN KEY (organization) REFERENCES dsm_organizations(id) ON DELETE CASCADE;
96

    
97
--
98
-- Name: dsm_datasourcepids; Type: TABLE; Schema: public; Owner: dnet
99
--
100

    
101
CREATE TABLE dsm_datasourcepids (
102
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
103
    datasource character varying(255) NOT NULL,
104
    pid character varying(255) NOT NULL
105
);
106

    
107

    
108
ALTER TABLE dsm_datasourcepids OWNER TO dnet;
109
ALTER TABLE ONLY dsm_datasourcepids ADD CONSTRAINT dsm_datasourcepids_pkey PRIMARY KEY (datasource, pid);
110
ALTER TABLE ONLY dsm_datasourcepids ADD CONSTRAINT dsm_datasourcepids_datasource_fkey FOREIGN KEY (datasource) REFERENCES dsm_datasources(id);
111
ALTER TABLE ONLY dsm_datasourcepids ADD CONSTRAINT dsm_datasourcepids_pid_fkey FOREIGN KEY (pid) REFERENCES dsm_identities(pid);
112

    
113

    
114
--
115
-- Name: dsm_datasources; Type: TABLE; Schema: public; Owner: dnet
116
--
117

    
118
CREATE TABLE dsm_datasources (
119
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
120
    id character varying(255) NOT NULL,
121
    officialname character varying(512) NOT NULL,
122
    englishname character varying(512),
123
    websiteurl character varying(255),
124
    logourl character varying(255),
125
    contactemail character varying(255),
126
    latitude double precision DEFAULT 0.0,
127
    longitude double precision DEFAULT 0.0,
128
    timezone character varying(10) DEFAULT '0.0'::character varying,
129
    namespaceprefix character(12) NOT NULL,
130
    languages text DEFAULT ARRAY[]::character varying[],
131
    od_contenttypes text,
132
    collectedfrom character varying(255),
133
    dateofvalidation date,
134
    optional1 character varying(255),
135
    optional2 character varying(255),
136
    typology character varying(255) NOT NULL,
137
    provenanceaction character varying(255) DEFAULT 'UNKNOWN'::character varying,
138
    dateofcollection date DEFAULT ('now'::text)::date,
139
    platform character varying(255),
140
    activationid character varying(255),
141
    description text,
142
    releasestartdate date,
143
    releaseenddate date,
144
    missionstatementurl character varying(512),
145
    dataprovider boolean,
146
    serviceprovider boolean,
147
    databaseaccesstype character varying(32),
148
    datauploadtype character varying(32),
149
    databaseaccessrestriction character varying(32),
150
    datauploadrestriction character varying(32),
151
    versioning boolean,
152
    citationguidelineurl character varying(512),
153
    qualitymanagementkind character varying(32),
154
    pidsystems text,
155
    certificates text,
156
    aggregator character varying(64) DEFAULT 'OPENAIRE'::character varying,
157
    issn character varying(20),
158
    eissn character varying(20),
159
    lissn character varying(20),
160
    registeredby character varying(255),
161
    registrationdate date,
162
    subjects text DEFAULT ARRAY[]::character varying[],
163
    managed boolean DEFAULT false
164
);
165

    
166
ALTER TABLE ONLY dsm_datasources ADD CONSTRAINT dsm_datasources_namespaceprefix_key UNIQUE (namespaceprefix);
167
ALTER TABLE ONLY dsm_datasources ADD CONSTRAINT dsm_datasources_pkey PRIMARY KEY (id);
168
ALTER TABLE ONLY dsm_datasources ADD CONSTRAINT dsm_datasources_collectedfrom_fkey FOREIGN KEY (collectedfrom) REFERENCES dsm_datasources(id);
169

    
170
CREATE INDEX dsm_datasources_id_idx ON dsm_datasources (id);
171
CREATE INDEX dsm_datasources_contactemail_idx ON dsm_datasources (contactemail);
172
CREATE INDEX dsm_datasources_englishname_idx ON dsm_datasources (englishname);
173
CREATE INDEX dsm_datasources_officialname_idx ON dsm_datasources (officialname);
174

    
175
ALTER TABLE dsm_datasources OWNER TO dnetapi;
176

    
177
--
178
-- Name: dsm_identities; Type: TABLE; Schema: public; Owner: dnet
179
--
180

    
181
CREATE TABLE dsm_identities (
182
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
183
    pid character varying(255) NOT NULL,
184
    issuertype character varying(255)
185
);
186

    
187

    
188
ALTER TABLE dsm_identities OWNER TO dnetapi;
189
ALTER TABLE ONLY dsm_identities ADD CONSTRAINT dsm_identities_pkey PRIMARY KEY (pid);
190

    
191

    
192
--
193
-- Name: dsm_organizationpids; Type: TABLE; Schema: public; Owner: dnet
194
--
195

    
196
CREATE TABLE dsm_organizationpids (
197
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
198
    organization character varying(255) NOT NULL,
199
    pid character varying(255) NOT NULL
200
);
201

    
202
ALTER TABLE dsm_organizationpids OWNER TO dnet;
203
ALTER TABLE ONLY dsm_organizationpids ADD CONSTRAINT dsm_organizationpids_pkey PRIMARY KEY (organization, pid);
204
ALTER TABLE ONLY dsm_organizationpids ADD CONSTRAINT dsm_organizationpids_organization_fkey FOREIGN KEY (organization) REFERENCES dsm_organizations(id);
205

    
206

    
207
--
208
-- Name: dsm_organizations; Type: TABLE; Schema: public; Owner: dnet
209
--
210

    
211
CREATE TABLE dsm_organizations (
212
    _dnet_resource_identifier_ CHARACTER VARYING(2048) DEFAULT ((('temp_'::text || md5((clock_timestamp())::text)) || '_'::text) || md5((random())::text)),
213
    id character varying(255) NOT NULL,
214
    legalshortname character varying(255),
215
    legalname character varying(255),
216
    websiteurl text,
217
    logourl character varying(255),
218
    country character varying(255),
219
    collectedfrom character varying(255),
220
    optional1 character varying(255),
221
    optional2 character varying(255),
222
    dateofcollection date DEFAULT ('now'::text)::date NOT NULL,
223
    provenanceaction character varying(255) DEFAULT 'UNKNOWN'::character varying
224
);
225

    
226

    
227
ALTER TABLE dsm_organizations OWNER TO dnetapi;
228
ALTER TABLE ONLY dsm_organizations ADD CONSTRAINT dsm_organizations_pkey PRIMARY KEY (id);
229
ALTER TABLE ONLY dsm_organizations ADD CONSTRAINT dsm_organizations_collectedfrom_fkey FOREIGN KEY (collectedfrom) REFERENCES dsm_datasources(id);
230

    
231
CREATE INDEX dsm_organizations_country_idx ON dsm_organizations (country);
232

    
233

    
234
CREATE TABLE funders (
235
  id character varying(255),
236
  name character varying(255),
237
  shortname character varying(255),
238
  jurisdiction character varying(255),
239
  websiteurl text,
240
  policy character varying(255),
241
  registrationdate date DEFAULT ('now'::text)::date NOT NULL,
242
  lastupdatedate date
243
);
244

    
245
GRANT ALL ON funders to dnetapi ;
246
ALTER TABLE ONLY funders ADD CONSTRAINT funders_pkey PRIMARY KEY (id);
247

    
248
CREATE TABLE funder_identity (
249
  funder character varying(255),
250
  pid character varying(255)
251
);
252

    
253
GRANT ALL ON funder_identity to dnetapi ;
254
ALTER TABLE ONLY funder_identity ADD CONSTRAINT funder_identity_funder_fkey FOREIGN KEY (funder) REFERENCES funders(id);
255
ALTER TABLE ONLY funder_identity ADD CONSTRAINT funder_identity_pid_fkey FOREIGN KEY (pid) REFERENCES dsm_identities(pid);
256

    
257
ALTER TABLE fundingpaths ADD COLUMN funderid varchar(255) ;
258
ALTER TABLE fundingpaths ADD CONSTRAINT fundingpaths_funderid_fkey FOREIGN KEY (funderid) REFERENCES funders(id);
259

    
260
--
261
-- Name: search_api; Type: VIEW; Schema: public; Owner: dnet
262
--
263

    
264
CREATE VIEW search_api AS
265
 SELECT a.id,
266
    a.compatibility,
267
    a.protocol,
268
    a.active,
269
    a.last_aggregation_date,
270
    a.last_aggregation_total,
271
    d.id AS repoid,
272
    d.officialname,
273
    d.englishname,
274
    d.namespaceprefix,
275
    (array_agg(DISTINCT o.country))[1] AS country,
276
    (array_agg(DISTINCT o.legalname))[1] AS organization
277
   FROM (((dsm_api a
278
     LEFT JOIN dsm_datasources d ON (((a.datasource)::text = (d.id)::text)))
279
     LEFT JOIN dsm_datasource_organization dor ON (((d.id)::text = (dor.datasource)::text)))
280
     LEFT JOIN dsm_organizations o ON (((dor.organization)::text = (o.id)::text)))
281
  GROUP BY a.id, a.compatibility, a.protocol, a.active, a.last_aggregation_date, a.last_aggregation_total, d.id, d.officialname, d.englishname, d.namespaceprefix;
282

    
283

    
284
ALTER TABLE search_api OWNER TO dnetapi;
285

    
286
CREATE VIEW browse_activation AS
287
 SELECT dsm_api.active::text AS term,
288
    count(*) AS total
289
   FROM dsm_api
290
  GROUP BY dsm_api.active
291
  ORDER BY count(*) DESC;
292

    
293
CREATE VIEW browse_compatibility AS
294
 SELECT a.compatibility AS term,
295
    count(*) AS total
296
   FROM dsm_api a
297
  GROUP BY a.compatibility
298
  ORDER BY count(*) DESC;
299

    
300

    
301

    
302
CREATE VIEW browse_countries AS
303
 SELECT o.country AS term,
304
    count(*) AS total
305
   FROM dsm_api a
306
     LEFT JOIN dsm_datasources d ON a.datasource::text = d.id::text
307
     LEFT JOIN dsm_datasource_organization dao ON d.id::text = dao.datasource::text
308
     LEFT JOIN dsm_organizations o ON dao.organization::text = o.id::text
309
  GROUP BY o.country
310
  ORDER BY count(*) DESC;
311

    
312

    
313
CREATE VIEW browse_protocols AS
314
 SELECT a.protocol AS term,
315
    count(*) AS total
316
   FROM dsm_api a
317
  GROUP BY a.protocol
318
  ORDER BY count(*) DESC;
319

    
320
CREATE VIEW browse_typologies AS
321
 SELECT a.typology AS term,
322
    count(*) AS total
323
   FROM dsm_api a
324
  GROUP BY a.typology
325
  ORDER BY count(*) DESC;
326

    
327
CREATE OR REPLACE VIEW dsm_datasource_api AS (
328
  SELECT
329
    row_number() OVER (ORDER BY a.id) AS rowid,
330
    d.officialname,
331
    d.englishname,
332
    d.websiteurl,
333
    d.contactemail,
334
    d.registeredby,
335
    d.typology,
336
    d.platform,
337
    d.managed,
338
    a.protocol,
339
    a.contentdescription,
340
    a.active,
341
    a.removable,
342
    a.typology AS apitypology,
343
    a.compatibility,
344
    a.baseurl
345
  FROM dsm_datasources d LEFT OUTER JOIN dsm_api a ON (d.id = a.datasource));
346
grant select on dsm_datasource_api to dnetapi ;
(3-3/6)