Project

General

Profile

1
--
2
-- sqoopQL database dump
3
--
4

    
5
SET statement_timeout = 0;
6
SET client_encoding = 'UTF8';
7
SET standard_conforming_strings = on;
8
SET check_function_bodies = false;
9
SET client_min_messages = warning;
10

    
11
--
12
-- Name: shadow; Type: SCHEMA; Schema: -; Owner: sqoop
13
--
14

    
15
DROP SCHEMA IF EXISTS backup CASCADE;
16

    
17
--
18
-- Name: shadow; Type: SCHEMA; Schema: -; Owner: sqoop
19
--
20
DROP SCHEMA  IF EXISTS shadow CASCADE;
21
CREATE SCHEMA shadow;
22

    
23
--ALTER SCHEMA shadow OWNER TO sqoop;
24

    
25
 SET search_path = shadow, pg_catalog;
26

    
27

    
28
--
29
-- Name: concept; Type: TABLE; Schema: public; Owner: dnet; Tablespace: 
30
--
31

    
32
CREATE TABLE shadow.concept (
33
    id text NOT NULL,
34
    name text ,
35
    category text
36
);
37

    
38

    
39

    
40
--
41
-- Name: datasource; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
42
--
43

    
44
CREATE TABLE shadow.datasource (
45
    id text NOT NULL,
46
    datasource_results text NOT NULL,
47
    datasource_organizations text NOT NULL,
48
    datasource_languages text NOT NULL,
49
    datasource_topics text NOT NULL,
50
    name text ,
51
    type text,
52
    compatibility text,
53
    latitude text,
54
    longitude text,
55
    dateofvalidation text,
56
    yearofvalidation integer,
57
    websiteurl text,
58
    piwik_id integer,
59
    harvested TEXT DEFAULT 'false',
60
    deletedbyinference TEXT,
61
    number integer DEFAULT 1 NOT NULL
62
);
63

    
64
--
65
-- Name: datasource_languages; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
66
--
67

    
68
CREATE TABLE shadow.datasource_languages (
69
    id text NOT NULL,
70
    language text
71
);
72

    
73

    
74
--
75
-- Name: datasource_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
76
--
77

    
78
--
79
CREATE TABLE shadow.datasource_organizations (
80
    id text NOT NULL,
81
    organization text NOT NULL
82
);
83

    
84

    
85

    
86
--
87
-- Name: result_datasources; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
88
--
89

    
90
CREATE TABLE shadow.result_datasources (
91
    id text NOT NULL,
92
    datasource text NOT NULL
93
);
94

    
95

    
96

    
97
--
98
-- Name: datasource_results; Type: VIEW; Schema: shadow; Owner: sqoop
99
--
100

    
101
--CREATE VIEW shadow.datasource_results AS
102
--    SELECT result_datasources.datasource AS id, result_datasources.id AS result FROM result_datasources;
103

    
104
--
105
-- Name: datasource_topics; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
106
-- Name: defaults; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
107
--
108

    
109
CREATE TABLE shadow.defaults (
110
    tablename text NOT NULL,
111
    xaxis text,
112
    yaxis text,
113
    agg text,
114
    zaxis text,
115
    type text,
116
    tableorder integer NOT NULL
117
);
118

    
119

    
120
--
121
-- Name: category; Type: TABLE; Schema: public; Owner: dnet; Tablespace: 
122
--
123
CREATE TABLE shadow.category (
124
    id text NOT NULL,
125
    name text,
126
    context text
127
);
128

    
129
--
130
-- Name: claim; Type: TABLE; Schema: public; Owner: dnet; Tablespace: 
131
--
132

    
133
CREATE TABLE shadow.claim (
134
    id text NOT NULL,
135
    date text ,
136
    userid text
137
);
138

    
139

    
140
--
141
-- Name: context; Type: TABLE; Schema: public; Owner: dnet; Tablespace: 
142
--
143

    
144
CREATE TABLE shadow.context (
145
    id text NOT NULL,
146
    name text
147
);
148

    
149
--
150
-- Name: organization; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
151
--
152

    
153
CREATE TABLE shadow.organization (
154
    id text NOT NULL,
155
    organization_datasources text NOT NULL,
156
    organization_projects text NOT NULL,
157
    name text,
158
    country text,
159
    websiteurl  text,
160
  deletedbyinference TEXT,
161
  number integer DEFAULT 1 NOT NULL
162
);
163

    
164

    
165

    
166
--
167
-- Name: organization_datasources; Type: VIEW; Schema: shadow; Owner: sqoop
168
--
169

    
170
CREATE VIEW shadow.organization_datasources AS
171
    SELECT datasource_organizations.organization AS id, datasource_organizations.id AS datasource FROM datasource_organizations;
172

    
173
--
174
-- Name: project_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
175
--
176

    
177
CREATE TABLE shadow.project_organizations (
178
    id text NOT NULL,
179
    organization text NOT NULL
180
);
181

    
182

    
183
--
184
-- Name: project_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
185
--
186

    
187
CREATE TABLE shadow.result_organizations (
188
    id text NOT NULL,
189
    organization text NOT NULL
190
);
191

    
192

    
193
--
194
-- Name: organization_projects; Type: VIEW; Schema: shadow; Owner: sqoop
195
--
196

    
197
CREATE VIEW shadow.organization_projects AS
198
    SELECT project_organizations.id AS project, project_organizations.organization AS id FROM project_organizations;
199

    
200
--
201
-- Name: project; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
202
--
203

    
204
CREATE TABLE shadow.project (
205
    id text NOT NULL,
206
    project_organizations text NOT NULL,
207
    project_results text NOT NULL,
208
    acronym text ,
209
    title text ,
210
    funder text,
211
    funding_lvl0 text,
212
    funding_lvl1 text,
213
    funding_lvl2 text,
214
     funding_lvl3 text,
215
    sc39 text,
216
    type text,
217
    url text,
218
    start_year integer,
219
    end_year integer,
220
    duration integer,
221
    haspubs text DEFAULT 'no'::text,
222
    numpubs integer,
223
    enddate text,
224
    startdate text,
225
    daysforlastpub integer,
226
    delayedpubs integer,
227
    callidentifier  text,
228
    code text,
229
    ecarticle293 text,
230
    sources text,
231
  deletedbyinference TEXT,
232
    number text
233
);
234

    
235
--
236
-- Name: result_projects; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
237
--
238

    
239
 CREATE TABLE shadow.project_oids (
240
    id text NOT NULL,
241
    orid text
242
);
243

    
244

    
245

    
246
 CREATE TABLE shadow.result_oids (
247
    id text NOT NULL,
248
    orid text
249
);
250

    
251

    
252
 CREATE TABLE shadow.organization_oids (
253
    id text NOT NULL,
254
   orid text
255
);
256

    
257

    
258
 CREATE TABLE shadow.datasource_oids (
259
    id text NOT NULL,
260
   orid text
261
);
262

    
263
 CREATE TABLE shadow.person_oids (
264
    id text NOT NULL,
265
   orid text
266
);
267

    
268

    
269
 CREATE TABLE shadow.project_keywords (
270
    id text NOT NULL,
271
    keyword text
272
);
273

    
274

    
275
 CREATE TABLE shadow.project_subjects (
276
    id text NOT NULL,
277
    subject text
278
);
279

    
280

    
281
--ALTER TABLE shadow.result_projects OWNER TO sqoop;
282

    
283
CREATE TABLE shadow.project_results (
284
    id text NOT NULL,
285
    result text NOT NULL,
286
    daysfromend integer
287
);
288

    
289

    
290
--
291
-- Name: result; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
292
--
293

    
294
CREATE TABLE shadow.result (
295
    id text NOT NULL,
296
    result_topics text NOT NULL,
297
    result_languages text NOT NULL,
298
    result_projects text NOT NULL,
299
    result_datasources text NOT NULL,
300
    result_classifications text NOT NULL,
301
    result_infrastructures text NOT NULL,
302
    result_claims text NOT NULL,
303
    result_results text NOT NULL,
304
  title text,
305
  format text,
306
  publisher text,
307
  journal text,
308
  year integer,
309
  date text ,
310
  access_mode text,
311
  bestlicense text,
312
  type text ,
313
  embargo_end_date text,
314
  delayed text,
315
  authors integer,
316
  source text,
317
  deletedbyinference TEXT,
318
  number integer DEFAULT 1 NOT NULL
319
);
320

    
321

    
322

    
323
--
324
-- Name: result_claims; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
325
--
326

    
327
CREATE TABLE shadow.result_claims (
328
    id text NOT NULL,
329
    claim text NOT NULL
330
);
331

    
332
CREATE TABLE shadow.result_citations (
333
  id text NOT NULL,
334
  result text NOT NULL
335
--  trust text,
336
--  provenance text,
337
--  citation text
338
);
339

    
340

    
341
--
342
-- Name: result_classifications; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
343
--
344

    
345
CREATE TABLE shadow.result_classifications (
346
    id text NOT NULL,
347
    type text NOT NULL
348
);
349

    
350
--
351
-- Name: result_concepts; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
352
--
353

    
354
CREATE TABLE shadow.result_concepts (
355
    id text NOT NULL,
356
    concept text NOT NULL
357
);
358

    
359
--
360
-- Name: result_languages; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
361
--
362

    
363
CREATE TABLE shadow.result_languages (
364
    id text NOT NULL,
365
    language text NOT NULL
366
);
367

    
368

    
369
--
370
-- Name: result_results; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
371
--
372

    
373
CREATE TABLE shadow.result_results (
374
    id text NOT NULL,
375
    result text NOT NULL
376
);
377

    
378

    
379

    
380
--
381
-- Name: result_topics; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: 
382
--
383

    
384
CREATE TABLE shadow.result_topics (
385
    id text NOT NULL,
386
    topic text
387
);
388

    
389

    
390
CREATE TABLE shadow.result_descriptions (
391
    id text NOT NULL,
392
    description  text
393
);
394

    
395
--
396
-- DATASOURCE Extra Inserts
397
--
398

    
399

    
400
CREATE TABLE shadow.person (
401
    id text NOT NULL,
402
    person_results text NOT NULL,
403
  firstname text,
404
  lastname text,
405
  fullname text ,
406
  nationality text ,
407
  email text,
408
  phone text,
409
  deletedbyinference TEXT,
410
  number text
411
);
412

    
413

    
414
CREATE TABLE shadow.person_results (
415
    id text NOT NULL,
416
    result text NOT NULL
417
);
418

    
419
CREATE TABLE shadow.project_persons (
420
  id text NOT NULL,
421
  person text NOT NULL
422
);
423

    
424
CREATE TABLE shadow.result_pids (
425
  id text NOT NULL,
426
  type text ,
427
  pid text
428
);
429

    
430

    
431

    
432

    
433

    
434

    
435

    
436
CREATE OR REPLACE FUNCTION shadow.extra_defaults_datasource()
437
 RETURNS void AS
438
$BODY$
439
BEGIN
440

    
441
INSERT INTO "shadow".datasource (id,datasource_results,datasource_organizations,datasource_languages,datasource_topics,name,type,compatibility,number) (SELECT 'other','other','other','other','other','Other','Repository','unknown',1 WHERE NOT EXISTS (SELECT 1 FROM "shadow".datasource WHERE name='Unknown Repository'));
442
UPDATE "shadow".datasource SET name='Other' where name='Unknown Repository';
443
UPDATE "shadow".result_datasources SET datasource=(SELECT id FROM "shadow".datasource WHERE name='Other') WHERE datasource NOT IN (SELECT id FROM "shadow".datasource);
444

    
445
TRUNCATE TABLE "shadow".defaults;
446
INSERT INTO "shadow".defaults VALUES ('result', 'year', 'number', 'count', '', 'column', 1);
447
INSERT INTO "shadow".defaults VALUES ('project', 'funding_lvl1', 'number', 'count', '', 'column', 2);
448
INSERT INTO "shadow".defaults VALUES ('organization', 'country', 'number', 'count', '', 'column',  3);
449
INSERT INTO "shadow".defaults VALUES ('datasource', 'oa_compatible', 'number', 'count', '', 'column', 4);
450

    
451
UPDATE "shadow".datasource SET yearofvalidation=null WHERE yearofvalidation='-1';
452

    
453

    
454
UPDATE shadow.project SET funder='FCT' WHERE funder='Fundação para a Ciência e a Tecnologia, I.P.';
455

    
456
  update shadow.datasource set harvested ='true' where datasource.id in ( select distinct d.id from datasource d, datasource_results dr where d.id=dr.id);
457

    
458
END
459
$BODY$
460
  LANGUAGE plpgsql VOLATILE
461
  COST 100;
462
ALTER FUNCTION shadow.extra_defaults_datasource()
463
  OWNER TO sqoop;
464

    
465

    
466
--
467
-- Project Results Extra Inserts
468
--
469

    
470
CREATE OR REPLACE FUNCTION shadow.update_project_results()
471
  RETURNS void AS
472
$BODY$
473
BEGIN
474

    
475

    
476
CREATE OR REPLACE VIEW shadow.project_results_publication AS
477
SELECT  "shadow".result_projects.id AS result,
478
"shadow".result_projects.project AS project_results,
479
"shadow"."result"."date" as  resultdate,
480
"shadow"."project"."enddate" as projectenddate,
481
"shadow".result_projects.daysfromend
482
as daysfromend FROM  "shadow".result_projects,
483
"shadow".result,
484
"shadow".project
485
 where  "shadow".result_projects.id="shadow".result.result_projects
486
 and  "shadow".result.type='publication'
487
 and  "shadow".project.project_results= "shadow".result_projects.project;
488

    
489
END
490
$BODY$
491
  LANGUAGE plpgsql VOLATILE
492
  COST 100;
493
ALTER FUNCTION shadow.update_project_results()
494
  OWNER TO sqoop;
495

    
496

    
497

    
498
--
499
-- Project Has Publications Extra Inserts
500
--
501
CREATE OR REPLACE FUNCTION shadow.project_has_pubs()
502
  RETURNS void AS
503
$BODY$
504
BEGIN
505

    
506

    
507
 CREATE OR REPLACE VIEW shadow.project_pub_count AS
508
 SELECT count(*) AS count, project_results_publication.project_results
509
 FROM shadow.project_results_publication
510
 GROUP BY project_results_publication.project_results;
511

    
512
--HAS PUBS
513
UPDATE "shadow"."project" SET haspubs='yes' WHERE project_results in (select project_results from shadow.project_results_publication );
514

    
515

    
516
END
517
$BODY$
518
  LANGUAGE plpgsql VOLATILE
519
  COST 100;
520
ALTER FUNCTION shadow.project_has_pubs()
521
  OWNER TO sqoop;
522

    
523

    
524
--
525
-- Project Publications Count Updates
526
--
527

    
528

    
529
CREATE OR REPLACE FUNCTION shadow.project_pubs_count()
530
  RETURNS void AS
531
$BODY$
532
BEGIN
533

    
534
 --COUNT PUBS
535

    
536
UPDATE "shadow"."project" SET numpubs=( SELECT  count from  shadow.project_pub_count
537
WHERE shadow.project_pub_count.project_results = shadow.project.project_results )
538
where "shadow"."project".project_results in (  SELECT "shadow".project_results_publication.project_results   FROM  shadow.project_results_publication  );
539

    
540

    
541
END
542
$BODY$
543
  LANGUAGE plpgsql VOLATILE
544
  COST 100;
545
ALTER FUNCTION shadow.project_pubs_count()
546
  OWNER TO sqoop;
547

    
548

    
549

    
550
--
551
-- Project  Delayed Publications
552
--
553

    
554
CREATE OR REPLACE FUNCTION shadow.project_delayedpubs()
555
  RETURNS void AS
556
$BODY$
557
BEGIN
558
--delayedpubs PUBS
559

    
560
create or replace view shadow.delayedpubs as SELECT count(*) , project_results from "shadow"."project_results_publication"
561
 WHERE  "shadow"."project_results_publication".daysfromend > 0 group by project_results;
562

    
563
UPDATE "shadow"."project" SET delayedpubs = (SELECT "shadow"."delayedpubs".count from "shadow"."delayedpubs"
564
 WHERE  "shadow"."delayedpubs".project_results=project.project_results ) where "shadow".project.project_results in ( select project_results from  "shadow"."delayedpubs" );
565

    
566

    
567
END
568
$BODY$
569
  LANGUAGE plpgsql VOLATILE
570
  COST 100;
571
ALTER FUNCTION shadow.project_delayedpubs()
572
  OWNER TO sqoop;
573

    
574

    
575
--
576
-- Project    daysforlastpub
577
--
578

    
579
CREATE OR REPLACE FUNCTION shadow.project_daysforlastpub()
580
  RETURNS void AS
581
$BODY$
582
BEGIN
583

    
584

    
585
--daysforlastpub
586

    
587
UPDATE "shadow"."project" SET daysforlastpub = (
588
SELECT max(daysfromend)
589
FROM "shadow"."project_results_publication" WHERE shadow.project.project_results = shadow.project_results_publication.project_results AND "shadow"."project_results_publication".daysfromend > 0  )
590
where    "shadow".project.project_results in ( select project_results from  "shadow"."delayedpubs" );
591

    
592

    
593
END
594
$BODY$
595
  LANGUAGE plpgsql VOLATILE
596
  COST 100;
597
ALTER FUNCTION shadow.project_daysforlastpub()
598
  OWNER TO sqoop;
599

    
600
--
601
-- Project    delayed
602
--
603

    
604

    
605
CREATE OR REPLACE FUNCTION shadow.project_delayed ()
606
  RETURNS void AS
607
$BODY$
608
BEGIN
609

    
610
--delayed
611

    
612
UPDATE "shadow"."result" SET delayed = 'yes' WHERE result.id IN
613
(SELECT  result  from shadow.project_results_publication where daysfromend >0);
614

    
615

    
616
END
617
$BODY$
618
  LANGUAGE plpgsql VOLATILE
619
  COST 100;
620
ALTER FUNCTION shadow.project_delayed()
621
  OWNER TO sqoop;
622

    
623

    
624
--
625
-- Cleaning Up Temps
626
-- 
627
CREATE OR REPLACE FUNCTION shadow.cleanTemps ()
628
  RETURNS void AS
629
$BODY$
630
BEGIN
631

    
632
drop view if exists  shadow.delayedpubs   ;
633
drop view  if exists  shadow.project_pub_count   ;
634
drop view if exists  shadow.delayedpubs    ;
635

    
636
drop view  if exists  shadow.project_results_publication   ;
637
END
638
$BODY$
639
  LANGUAGE plpgsql VOLATILE
640
  COST 100;
641
ALTER FUNCTION shadow.cleanTemps()
642
  OWNER TO sqoop;
643

    
644

    
645
  ---functions
646

    
647
--
648
-- Name: create_indexes(); Type: FUNCTION; Schema: shadow; Owner: sqoop
649
--
650

    
651
CREATE FUNCTION shadow.create_indexes() RETURNS void
652
    LANGUAGE plpgsql
653
    AS $$
654

    
655
BEGIN
656

    
657
CREATE INDEX datasource_datasource_languages ON  "shadow".datasource USING btree (datasource_languages);
658
CREATE INDEX datasource_datasource_organizations ON   "shadow".datasource USING btree (datasource_organizations);
659
CREATE INDEX datasource_datasource_results ON   "shadow".datasource USING btree (datasource_results);
660
CREATE INDEX datasource_datasource_topics ON   "shadow".datasource USING btree (datasource_topics);
661
CREATE INDEX datasource_id ON "shadow".datasource USING btree (id);
662
CREATE INDEX datasource_type ON   "shadow".datasource USING btree (type);
663
CREATE INDEX datasource_name ON   "shadow".datasource USING btree (name);
664
CREATE INDEX datasource_piwik_id ON "shadow".datasource USING btree (piwik_id);
665
CREATE INDEX result_access_mode ON   "shadow".result USING btree (access_mode);
666
CREATE INDEX result_authors ON   "shadow".result USING btree (authors);
667
CREATE INDEX result_id ON   "shadow".result USING btree (id);
668
CREATE INDEX result_result_datasources ON   "shadow".result USING btree (result_datasources);
669
CREATE INDEX result_result_languages ON   "shadow".result USING btree (result_languages);
670
CREATE INDEX result_result_projects ON   "shadow".result USING btree (result_projects);
671
CREATE INDEX result_result_topics ON   "shadow".result USING btree (result_topics);
672
CREATE INDEX result_year ON   "shadow".result USING btree (year);
673
CREATE INDEX result_date ON   "shadow"."result" USING btree ("date");
674
CREATE INDEX result_type ON   "shadow"."result" USING btree ("type");
675

    
676

    
677
CREATE INDEX project_acronym ON   "shadow"."project" USING btree (acronym);
678
CREATE INDEX project_enddate ON   "shadow"."project" USING btree (enddate);
679
CREATE INDEX project_id ON   "shadow"."project" USING btree (id);
680
CREATE INDEX project_project_results ON   "shadow"."project" USING btree (project_results);
681
CREATE INDEX project_results_result ON   "shadow"."project_results" USING btree (result);
682
CREATE INDEX project_results_project ON   "shadow"."project_results" USING btree (id);
683

    
684
CREATE INDEX result_oids_id ON "shadow".result_oids USING btree (id COLLATE pg_catalog."default");
685
CREATE INDEX result_oids_oid ON "shadow".result_oids USING btree(orid COLLATE pg_catalog."default");
686

    
687
CREATE INDEX result_pids_id ON "shadow".result_pids USING btree (id COLLATE pg_catalog."default");
688
CREATE INDEX result_pids_type ON "shadow".result_pids USING btree (type COLLATE pg_catalog."default");
689
CREATE INDEX result_pids_pid ON "shadow".result_pids USING btree(pid COLLATE pg_catalog."default");
690

    
691

    
692

    
693

    
694

    
695
CREATE INDEX datasource_lang_id
696
   ON shadow.datasource_languages (id ASC NULLS LAST);
697

    
698
CREATE INDEX dtsrc_org_id
699
  ON shadow.datasource_organizations
700
  USING btree
701
  (id COLLATE pg_catalog."default");
702

    
703
CREATE INDEX res_class_type
704
  ON shadow.result_classifications
705
  USING btree
706
  (type COLLATE pg_catalog."default");
707

    
708
CREATE INDEX res_class_id
709
  ON shadow.result_classifications
710
  USING btree
711
  (id COLLATE pg_catalog."default");
712

    
713
CREATE INDEX res_dtsrc_dtsrc
714
  ON shadow.result_datasources
715
  USING btree
716
  (datasource COLLATE pg_catalog."default");
717

    
718
CREATE INDEX res_dtsrc_id
719
  ON shadow.result_datasources
720
  USING btree
721
  (id COLLATE pg_catalog."default");
722

    
723
CREATE INDEX res_lang_lang
724
  ON shadow.result_languages
725
  USING btree
726
  (language COLLATE pg_catalog."default");
727

    
728
CREATE INDEX org_id
729
  ON shadow.organization
730
  USING btree
731
  (id COLLATE pg_catalog."default");
732

    
733
CREATE INDEX org_country
734
  ON shadow.organization
735
  USING btree
736
  (country COLLATE pg_catalog."default");
737

    
738
CREATE INDEX org_dtsrc
739
  ON shadow.organization
740
  USING btree
741
  (organization_datasources COLLATE pg_catalog."default");
742

    
743
CREATE INDEX org_proj
744
  ON shadow.organization
745
  USING btree
746
  (organization_projects COLLATE pg_catalog."default");
747

    
748
CREATE INDEX proj_funder
749
  ON shadow.project
750
  USING btree
751
  (funder COLLATE pg_catalog."default");
752

    
753
CREATE INDEX proj_title
754
  ON shadow.project
755
  USING btree
756
  (title COLLATE pg_catalog."default");
757

    
758
CREATE INDEX proj_fndlvl0
759
  ON shadow.project
760
  USING btree
761
  (funding_lvl0 COLLATE pg_catalog."default");
762

    
763

    
764
CREATE INDEX proj_fndlvl1
765
  ON shadow.project
766
  USING btree
767
  (funding_lvl1 COLLATE pg_catalog."default");
768

    
769
CREATE INDEX proj_fndlvl2
770
  ON shadow.project
771
  USING btree
772
  (funding_lvl2 COLLATE pg_catalog."default");
773

    
774

    
775
CREATE INDEX proj_org_org
776
  ON shadow.project_organizations
777
  USING btree
778
  (organization COLLATE pg_catalog."default");
779

    
780
CREATE INDEX proj_org_id
781
  ON shadow.project_organizations
782
  USING btree
783
  (id COLLATE pg_catalog."default");
784

    
785

    
786

    
787

    
788

    
789

    
790

    
791
CREATE INDEX res_res_id
792
  ON shadow.result_results
793
  USING btree
794
  (id COLLATE pg_catalog."default");
795

    
796

    
797

    
798
CREATE INDEX res_res_res
799
  ON shadow.result_results
800
  USING btree
801
  (result COLLATE pg_catalog."default");
802

    
803
CREATE INDEX res_lang_id
804
  ON shadow.result_languages
805
  USING btree
806
  (id COLLATE pg_catalog."default");
807
CREATE INDEX res_conc_id
808
  ON shadow.result_concepts
809
  USING btree
810
  (id COLLATE pg_catalog."default");
811

    
812
CREATE INDEX res_conc_conc
813
  ON shadow.result_concepts
814
  USING btree
815
  (concept COLLATE pg_catalog."default");
816

    
817
CREATE INDEX res_class
818
  ON shadow.result
819
  USING btree
820
  (result_classifications COLLATE pg_catalog."default");
821

    
822
CREATE INDEX res_bestlicense
823
  ON shadow.result
824
  USING btree
825
  (bestlicense COLLATE pg_catalog."default");
826

    
827
CREATE INDEX proj_sc39
828
  ON shadow.project
829
  USING btree
830
  (sc39 COLLATE pg_catalog."default");
831
CREATE INDEX proj_fndlvl3
832
  ON shadow.project
833
  USING btree
834
  (funding_lvl3 COLLATE pg_catalog."default");
835

    
836
CREATE INDEX dtsrc_type
837
  ON shadow.datasource
838
  USING btree
839
  (type COLLATE pg_catalog."default");
840

    
841
CREATE INDEX dtsrc_name
842
  ON shadow.datasource
843
  USING btree
844
  (name COLLATE pg_catalog."default");
845

    
846
CREATE INDEX dtsrc_compatibility
847
  ON shadow.datasource
848
  USING btree
849
  (compatibility COLLATE pg_catalog."default");
850

    
851
CREATE INDEX org_name
852
  ON shadow.organization
853
  USING btree
854
  (name COLLATE pg_catalog."default");
855

    
856
CREATE INDEX dtsrc_org_org
857
  ON shadow.datasource_organizations
858
  USING btree
859
  (organization COLLATE pg_catalog."default");
860

    
861

    
862
  END;$$;
863

    
864

    
865
ALTER FUNCTION shadow.create_indexes() OWNER TO sqoop;
866

    
867
--
868
-- Name: create_views(); Type: FUNCTION; Schema: shadow; Owner: sqoop
869
--
870

    
871
CREATE or replace FUNCTION "shadow".create_views() RETURNS void
872
    LANGUAGE plpgsql
873
    AS $$
874

    
875
BEGIN
876

    
877
CREATE OR REPLACE    VIEW  "shadow".datasource_results   as  SELECT datasource as id  , id  as  result FROM "shadow".result_datasources ;
878

    
879
CREATE OR REPLACE   VIEW "shadow".organization_datasources as SELECT   organization  as id , id as datasource  FROM "shadow".datasource_organizations ;
880

    
881
CREATE OR REPLACE   VIEW "shadow".organization_projects as SELECT  id  as project, organization as id FROM "shadow".project_organizations ;
882

    
883

    
884

    
885
CREATE OR REPLACE VIEW shadow.result_projects AS SELECT  shadow.project_results.result AS id,
886
  shadow.project_results.id AS project, ( select to_date("shadow"."result"."date", 'YYYY-MM-DD')- to_date("shadow"."project"."enddate", 'YYYY-MM-DD')
887
   from shadow.result, shadow.project where shadow.result.id =  shadow.project_results.result
888
   and shadow.project_results.id= shadow.project.id and shadow.result.type='publication' )
889
 as daysfromend FROM shadow.project_results;
890

    
891
 CREATE OR REPLACE   VIEW "shadow".datasource_topics AS
892
 SELECT distinct "shadow".datasource.id, "shadow".result_topics.topic
893
   FROM "shadow".datasource, "shadow".datasource_results, "shadow".result, "shadow".result_topics
894
  WHERE "shadow".datasource.datasource_results = "shadow".datasource_results.id AND "shadow".datasource_results.result = "shadow".result.id AND
895
  "shadow".result_topics.id = "shadow".result.result_topics;
896

    
897

    
898
  END;$$;
899
--
900
-- Name: create_charts(); Type: FUNCTION; Schema: shadow; Owner: sqoop
901
--
902

    
903
CREATE or replace FUNCTION "shadow".create_charts() RETURNS void
904
    LANGUAGE plpgsql
905
    AS $$
906

    
907
BEGIN
908

    
909
SELECT rd.datasource, rc.type, count(distinct rd.id) INTO "shadow".chart_datasource_pubs FROM "shadow".result_datasources rd, "shadow".result_classifications rc WHERE rd.id=rc.id GROUP BY rd.datasource, rc.type;
910
SELECT rd.datasource, r.year, count(distinct rd.id) INTO "shadow".chart_datasource_year FROM "shadow".result r, "shadow".result_datasources rd WHERE rd.id=r.id GROUP By rd.datasource, r.year;
911
SELECT rd.datasource, p.funder, count(distinct rd.id) INTO "shadow".chart_datasource_funders FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr WHERE p.id=pr.id AND pr.result=rd.id GROUP BY rd.datasource, p.funder;
912
SELECT rd.datasource, p.title, count(distinct rd.id) INTO "shadow".chart_datasource_projects FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr WHERE p.id=pr.id AND pr.result=rd.id GROUP BY rd.datasource, p.title;
913

    
914
  END;$$;
915

    
916
--
917
-- Name: create_charts(); Type: FUNCTION; Schema: shadow; Owner: sqoop
918
--
919

    
920
CREATE or replace FUNCTION "shadow".create_chart_indexes() RETURNS void
921
    LANGUAGE plpgsql
922
    AS $$
923

    
924
BEGIN
925

    
926
CREATE INDEX chart_datasource_pubs_datasource ON "shadow".chart_datasource_pubs USING btree(datasource);
927
CREATE INDEX chart_datasource_year_datasource ON "shadow".chart_datasource_year USING btree(datasource);
928
CREATE INDEX chart_datasource_funders_datasource ON "shadow".chart_datasource_funders USING btree(datasource);
929
CREATE INDEX chart_datasource_projects_datasource ON "shadow".chart_datasource_projects USING btree(datasource);
930

    
931

    
932
  END;$$;
933

    
934
--
935
-- Name: clean_tables(); Type: FUNCTION; Schema: shadow; Owner: sqoop
936
--
937

    
938
CREATE or replace FUNCTION "shadow".clean_tables() RETURNS void
939
    LANGUAGE plpgsql
940
    AS $$
941
BEGIN
942

    
943
CREATE TABLE "shadow".rd_distinct AS SELECT DISTINCT * FROM "shadow".result_datasources;
944
TRUNCATE "shadow".result_datasources;
945
INSERT INTO "shadow".result_datasources SELECT * FROM "shadow".rd_distinct;
946
DROP TABLE "shadow".rd_distinct;
947

    
948

    
949
  END;$$;
950

    
951
--DROP type if exists  infra_report_rec  cascade;
952

    
953
--CREATE TYPE  infra_report_rec as
954
--(Publications varchar(50), Open_Access_Publications varchar(50),
955
 --FP7_Publications varchar(50), FP7_Closed_Access_Publications varchar(50),
956
 --FP7_Open_Access_Publications varchar(50),
957
 --FP7_Restricted_Access_Publications varchar(50), FP7_Embargo_Publications varchar(50) );
958

    
959
--CREATE OR REPLACE FUNCTION shadow.getInfraReports()
960
--  RETURNS   infra_report_rec
961
--AS
962
--  $$
963
--DECLARE
964
--  result_record infra_report_rec;
965
--BEGIN
966
--
967
--  SELECT count(*)  INTO result_record.Publications  FROM shadow.result where type='publication';
968
--  SELECT count(*)   INTO result_record.Open_Access_Publications FROM shadow.result WHERE bestlicense='Open Access' and type='publication';
969
--
970
--SELECT count (distinct result_projects.id) INTO result_record.FP7_Publications FROM shadow.result, shadow.result_projects, shadow.project
971
--WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0 = 'FP7';
972
--
973
--SELECT count (distinct shadow.result_projects.id)
974
--	INTO result_record.FP7_Closed_Access_Publications
975
--	FROM shadow.result,
976
--	shadow.result_projects,
977
--	shadow.project
978
--	WHERE result.result_projects = result_projects.id
979
--	AND result_projects.project = project.id
980
--	AND funding_lvl0 = 'FP7'
981
--	AND bestlicense='Closed Access'
982
--	AND type='publication';
983
--
984
--
985
--SELECT count(distinct result_projects.id) INTO result_record.FP7_Open_Access_Publications  FROM shadow.result,
986
-- shadow.result_projects,  shadow.project
987
-- WHERE result_projects = result_projects.id AND result_projects.project = project.id and type='publication' and funding_lvl0 = 'FP7' and bestlicense='Open Access';
988
--
989
--SELECT count(distinct result_projects.id) INTO result_record.FP7_Restricted_Access_Publications
990
-- FROM shadow.result, shadow.result_projects, shadow.project
991
--  WHERE result.result_projects=result_projects.id
992
--   AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Restricted' and type='publication';
993
--
994
--
995
--SELECT count(distinct result_projects.id)  INTO result_record.FP7_Embargo_Publications FROM shadow.result, shadow.result_projects, shadow.project
996
--WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Embargo' and type='publication';
997
--
998
--RETURN result_record;
999
--
1000
--END
1001
--$$ LANGUAGE plpgsql;
1002
--
1003
--drop type if exists fp7_report_rec cascade;
1004
--
1005
--CREATE TYPE fp7_report_rec as
1006
--(FP7_Publications varchar(50),
1007
-- FP7_Projects varchar(50),
1008
-- FP7_SC39_Projects varchar(50),
1009
-- FP7_SC39_Publications varchar(50),
1010
-- FP7_SC39_Open_Access varchar(50));
1011
--
1012
--
1013
--CREATE OR REPLACE FUNCTION shadow.getFp7Reports()
1014
--  RETURNS   fp7_report_rec
1015
--AS
1016
--  $$
1017
--
1018
--DECLARE
1019
--  result_record fp7_report_rec;
1020
--
1021
--BEGIN
1022
--
1023
----FP7 WITH PUBS
1024
--SELECT count(distinct project.id) into result_record.FP7_Publications FROM shadow.result, shadow.result_projects, shadow.project
1025
--WHERE result.result_projects = result_projects.id and type='publication'
1026
-- and result_projects.project = project.id and funding_lvl0='FP7' ;
1027
--
1028
--SELECT count(id) into result_record.FP7_Projects FROM shadow.project WHERE funding_lvl0 = 'FP7';
1029
--  SELECT count(number) into result_record.FP7_SC39_Projects from shadow.project where funding_lvl0='FP7' and sc39='yes';
1030
--
1031
--SELECT count(distinct project.id) into result_record.FP7_SC39_Publications FROM  shadow.result, shadow.result_projects, shadow.project
1032
--  WHERE result_projects.project=project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication';
1033
--
1034
--SELECT count(distinct result_projects.id) into result_record.FP7_SC39_Open_Access  FROM shadow.result, shadow.result_projects, shadow.project
1035
-- WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Open Access' and sc39='yes' and type='publication';
1036
--
1037
--RETURN result_record;
1038
--
1039
--END
1040
--$$ LANGUAGE plpgsql;
1041
--
1042
--
1043
--drop type wt_report_rec cascade;
1044
--
1045
--CREATE TYPE wt_report_rec as
1046
--(WT_Publications varchar(50),
1047
-- WT_Projects varchar(50),
1048
-- WT_Open_Access varchar(50),
1049
-- WT_Restricted_Access varchar(50),
1050
-- WT_Embargo varchar(50));
1051
--
1052
--
1053
--CREATE OR REPLACE FUNCTION shadow.getWTReports()
1054
--  RETURNS   wt_report_rec
1055
--AS
1056
--  $$
1057
--
1058
--DECLARE
1059
--  result_record wt_report_rec;
1060
--
1061
--BEGIN
1062
--
1063
--SELECT count(distinct project.id)  into result_record.WT_Publications  FROM shadow.result, shadow.project, shadow.result_projects
1064
--where result_projects.project = project.id and project.funding_lvl0='WT' and result.result_projects = result_projects.id and type='publication';
1065
--
1066
--SELECT count(id)  into  result_record.WT_Projects FROM project WHERE funding_lvl0 = 'WT';
1067
--
1068
--SELECT count(distinct result_projects.id)   into  result_record.WT_Open_Access  FROM shadow.result, shadow.result_projects, shadow.project WHERE result.result_projects= result_projects.id
1069
--AND result_projects.project = project.id and funding_lvl0 = 'WT' and bestlicense='Open Access' and type='publication';
1070
--
1071
--SELECT count(distinct result_projects.id)  into  result_record.WT_Restricted_Access   FROM shadow.result, shadow.result_projects,
1072
--shadow.project WHERE result.result_projects = result_projects.id AND
1073
--result_projects.project = project.id and funding_lvl0 = 'WT' and
1074
--bestlicense='Restricted' and type='publication';
1075
--
1076
--SELECT count(distinct result_projects.id) into  result_record.WT_Embargo    FROM shadow.result, shadow.result_projects, shadow.project
1077
--WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT'
1078
--and bestlicense='Embargo' and type='publication';
1079
--
1080
--RETURN result_record;
1081
--
1082
--END
1083
--$$ LANGUAGE plpgsql;
1084
--
1085
--
1086
--
1087
--drop type if exists erc_report_rec cascade;
1088
--
1089
--CREATE TYPE erc_report_rec as
1090
--(ERC_Publications varchar(50),
1091
-- ERC_Projects varchar(50),
1092
-- ERC_Open_Access  varchar(50),
1093
-- ERC_Restricted_Access  varchar(50),
1094
-- ERC_Embargo varchar(50));
1095
--
1096
--
1097
--
1098
--CREATE OR REPLACE FUNCTION shadow.getERCReports()
1099
--  RETURNS   erc_report_rec
1100
--AS
1101
--  $$
1102
--
1103
--DECLARE
1104
--  result_record erc_report_rec;
1105
--
1106
--BEGIN
1107
--
1108
--SELECT count(distinct project.id) into result_record.ERC_Publications FROM shadow.result, shadow.project, shadow.result_projects
1109
--where result_projects.project = project.id and project.funding_lvl2='ERC' and result.result_projects = result_projects.id and type='publication';
1110
--
1111
--SELECT count(id)  into result_record.ERC_Projects FROM shadow.project WHERE funding_lvl2 = 'ERC';
1112
--
1113
--
1114
--SELECT count(distinct result_projects.id) into result_record.ERC_Open_Access FROM shadow.result,
1115
--shadow.result_projects, shadow.project WHERE result.result_projects= result_projects.id
1116
--AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Open Access' and type='publication';
1117
--
1118
--
1119
--SELECT count(distinct result_projects.id)  into result_record.ERC_Restricted_Access FROM shadow.result, shadow.result_projects, shadow.project WHERE
1120
-- result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Restricted' and type='publication';
1121
--
1122
--SELECT count(distinct result_projects.id)  into result_record.ERC_Embargo FROM shadow.result, shadow.result_projects, shadow.project
1123
--	WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Embargo' and type='publication';
1124
--
1125
--
1126
--RETURN result_record;
1127
--
1128
--END
1129
--$$ LANGUAGE plpgsql;
1130

    
1131
-- sqoopQL database dump complete
1132
--
(4-4/4)