Project

General

Profile

« Previous | Next » 

Revision 6497

schemas/vegbien.sql: Added darwin_core_view

View differences:

vegbien.sql
917 917

  
918 918

  
919 919
--
920
-- Name: sync_darwin_core_to_view(); Type: FUNCTION; Schema: public; Owner: -
921
--
922

  
923
CREATE FUNCTION sync_darwin_core_to_view() RETURNS void
924
    LANGUAGE sql
925
    AS $$
926
DROP TABLE IF EXISTS darwin_core;
927
CREATE TABLE darwin_core AS SELECT * FROM darwin_core_view;
928

  
929
CREATE INDEX ON darwin_core ("institutionCode", "projectID", "plotName", "dateCollected" );
930
CREATE INDEX ON darwin_core ("institutionCode", "occurrenceID" );
931
CREATE INDEX ON darwin_core ("institutionCode", "subInstitutionCode", "collectionCode", "catalogNumber" );
932
CREATE INDEX ON darwin_core ("institutionCode", "catalogNumber" );
933
$$;
934

  
935

  
936
--
920 937
-- Name: sync_geoscrub_input_to_view(); Type: FUNCTION; Schema: public; Owner: -
921 938
--
922 939

  
......
2713 2730

  
2714 2731

  
2715 2732
--
2733
-- Name: darwin_core; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2734
--
2735

  
2736
CREATE TABLE darwin_core (
2737
    "institutionCode" text,
2738
    "subInstitutionCode" text,
2739
    "collectionCode" text,
2740
    "catalogNumber" text,
2741
    "occurrenceID" text,
2742
    country text,
2743
    "stateProvince" text,
2744
    county text,
2745
    "decimalLatitude" double precision,
2746
    "decimalLongitude" double precision,
2747
    "coordinateUncertaintyInMeters" double precision,
2748
    geovalid boolean,
2749
    "isNewWorld" boolean,
2750
    "projectID" integer,
2751
    "plotName" text,
2752
    "elevationInMeters" double precision,
2753
    "plotArea_ha" double precision,
2754
    "samplingProtocol" text,
2755
    "dateCollected" date,
2756
    "higherPlantGroup" higher_plant_group,
2757
    family text,
2758
    genus text,
2759
    "speciesBinomial" text,
2760
    "scientificName" text,
2761
    "scientificNameAuthorship" text,
2762
    "speciesBinomialWithMorphospecies" text,
2763
    "scientificNameWithMorphospecies" text,
2764
    threatened boolean,
2765
    "identifiedBy" text,
2766
    "growthForm" growthform,
2767
    cultivated boolean,
2768
    "cultivatedBasis" text,
2769
    "recordedBy" text,
2770
    "recordNumber" text,
2771
    "coverPercent" double precision,
2772
    "diameterBreastHeight_cm" double precision,
2773
    height_m double precision,
2774
    tag text,
2775
    "organismX_m" double precision,
2776
    "organismY_m" double precision,
2777
    "taxonOccurrenceID" text,
2778
    "authorTaxonCode" text,
2779
    "individualID" text,
2780
    "authorStemCode" text
2781
);
2782

  
2783

  
2784
--
2785
-- Name: project; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2786
--
2787

  
2788
CREATE TABLE project (
2789
    project_id integer NOT NULL,
2790
    source_id integer NOT NULL,
2791
    sourceaccessioncode text,
2792
    projectname text,
2793
    projectdescription text,
2794
    startdate date,
2795
    stopdate date,
2796
    accessioncode text,
2797
    CONSTRAINT project_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (projectname IS NOT NULL)))
2798
);
2799

  
2800

  
2801
--
2802
-- Name: sourcename; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2803
--
2804

  
2805
CREATE TABLE sourcename (
2806
    sourcename_id integer NOT NULL,
2807
    source_id integer NOT NULL,
2808
    system text,
2809
    name text NOT NULL,
2810
    matched_source_id integer
2811
);
2812

  
2813

  
2814
--
2815
-- Name: specimenreplicate; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2816
--
2817

  
2818
CREATE TABLE specimenreplicate (
2819
    specimenreplicate_id integer NOT NULL,
2820
    source_id integer NOT NULL,
2821
    sourceaccessioncode text,
2822
    plantobservation_id integer,
2823
    institution_id integer,
2824
    collectioncode_dwc text,
2825
    catalognumber_dwc text,
2826
    description text,
2827
    specimen_id integer,
2828
    accessioncode text,
2829
    CONSTRAINT specimenreplicate_required_key CHECK ((((plantobservation_id IS NOT NULL) OR (sourceaccessioncode IS NOT NULL)) OR (catalognumber_dwc IS NOT NULL)))
2830
);
2831

  
2832

  
2833
--
2834
-- Name: TABLE specimenreplicate; Type: COMMENT; Schema: public; Owner: -
2835
--
2836

  
2837
COMMENT ON TABLE specimenreplicate IS 'A herbarium''s replicate of a specimen. Contains Darwin Core specimen data.';
2838

  
2839

  
2840
--
2841
-- Name: COLUMN specimenreplicate.institution_id; Type: COMMENT; Schema: public; Owner: -
2842
--
2843

  
2844
COMMENT ON COLUMN specimenreplicate.institution_id IS 'The institution (such as a museum) that the specimenreplicate is from.';
2845

  
2846

  
2847
--
2848
-- Name: COLUMN specimenreplicate.collectioncode_dwc; Type: COMMENT; Schema: public; Owner: -
2849
--
2850

  
2851
COMMENT ON COLUMN specimenreplicate.collectioncode_dwc IS 'The code for the collection that the specimenreplicate is from.';
2852

  
2853

  
2854
--
2855
-- Name: darwin_core_view; Type: VIEW; Schema: public; Owner: -
2856
--
2857

  
2858
CREATE VIEW darwin_core_view AS
2859
    SELECT source.shortname AS "institutionCode", sourcename.name AS "subInstitutionCode", specimenreplicate.collectioncode_dwc AS "collectionCode", specimenreplicate.catalognumber_dwc AS "catalogNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, coordinates.latitude_deg AS "decimalLatitude", coordinates.longitude_deg AS "decimalLongitude", coordinates.coordsaccuracy_m AS "coordinateUncertaintyInMeters", canon_place.geovalid, "newWorldCountries"."isNewWorld", locationevent.project_id AS "projectID", COALESCE(location.sourceaccessioncode, location.authorlocationcode) AS "plotName", location.elevation_m AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.obsstartdate, aggregateoccurrence.collectiondate) AS "dateCollected", family_higher_plant_group.higher_plant_group AS "higherPlantGroup", accepted_taxonverbatim.family, accepted_taxonverbatim.genus, ((accepted_taxonverbatim.genus || ' '::text) || accepted_taxonverbatim.specific_epithet) AS "speciesBinomial", COALESCE(accepted_taxonverbatim.taxonomicname, accepted_taxonverbatim.taxonname) AS "scientificName", accepted_taxonverbatim.author AS "scientificNameAuthorship", NULLIF(array_to_string(ARRAY[COALESCE(accepted_taxonverbatim.genus, accepted_taxonverbatim.family), COALESCE(accepted_taxonverbatim.specific_epithet, parsed_taxonverbatim.morphospecies)], ' '::text), ''::text) AS "speciesBinomialWithMorphospecies", NULLIF(array_to_string(ARRAY[accepted_taxonverbatim.taxonomicname, parsed_taxonverbatim.morphospecies], ' '::text), ''::text) AS "scientificNameWithMorphospecies", (threatened_taxonlabel.taxonlabel_id IS NOT NULL) AS threatened, identifiedby.fullname AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", ((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, location.iscultivated)) AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis", collector.fullname AS "recordedBy", plantobservation.collectionnumber AS "recordNumber", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "coverPercent", _m_to_cm(stemobservation.diameterbreastheight_m) AS "diameterBreastHeight_cm", stemobservation.height_m, stemobservation.tag, stemobservation.xposition_m AS "organismX_m", stemobservation.yposition_m AS "organismY_m", taxonoccurrence.sourceaccessioncode AS "taxonOccurrenceID", taxonoccurrence.authortaxoncode AS "authorTaxonCode", plantobservation.sourceaccessioncode AS "individualID", stemobservation.authorstemcode AS "authorStemCode" FROM ((((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN place datasource_place USING (place_id)) LEFT JOIN place canon_place ON ((canon_place.place_id = datasource_place.canon_place_id))) LEFT JOIN coordinates ON ((coordinates.coordinates_id = canon_place.coordinates_id))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON ((("newWorldCountries"."isoCode")::text = iso_code_gadm."2-digit iso code"))) LEFT JOIN locationevent USING (location_id)) LEFT JOIN project USING (project_id)) LEFT JOIN method USING (method_id)) LEFT JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim datasource_taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel datasource_taxonlabel USING (taxonlabel_id)) LEFT JOIN taxonlabel parsed_taxonlabel ON ((parsed_taxonlabel.taxonlabel_id = datasource_taxonlabel.matched_label_id))) LEFT JOIN taxonverbatim parsed_taxonverbatim ON ((parsed_taxonverbatim.taxonlabel_id = parsed_taxonlabel.taxonlabel_id))) LEFT JOIN taxonlabel accepted_taxonlabel ON ((accepted_taxonlabel.taxonlabel_id = datasource_taxonlabel.canon_label_id))) LEFT JOIN taxonverbatim accepted_taxonverbatim ON ((accepted_taxonverbatim.taxonlabel_id = accepted_taxonlabel.taxonlabel_id))) LEFT JOIN threatened_taxonlabel ON ((threatened_taxonlabel.taxonlabel_id = accepted_taxonlabel.taxonlabel_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = accepted_taxonverbatim.family))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = accepted_taxonverbatim.family) AND (cultivated_family_locations.country = canon_place.country)))) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcename ON ((sourcename.sourcename_id = specimenreplicate.institution_id))) WHERE (taxondetermination.iscurrent AND (COALESCE(locationevent.obsstartdate, aggregateoccurrence.collectiondate) IS NOT NULL));
2860

  
2861

  
2862
--
2716 2863
-- Name: dba_preassignacccode_dba_requestnumber_seq; Type: SEQUENCE; Schema: public; Owner: -
2717 2864
--
2718 2865

  
......
3448 3595

  
3449 3596

  
3450 3597
--
3451
-- Name: project; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3452
--
3453

  
3454
CREATE TABLE project (
3455
    project_id integer NOT NULL,
3456
    source_id integer NOT NULL,
3457
    sourceaccessioncode text,
3458
    projectname text,
3459
    projectdescription text,
3460
    startdate date,
3461
    stopdate date,
3462
    accessioncode text,
3463
    CONSTRAINT project_required_key CHECK (((sourceaccessioncode IS NOT NULL) OR (projectname IS NOT NULL)))
3464
);
3465

  
3466

  
3467
--
3468 3598
-- Name: project_project_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3469 3599
--
3470 3600

  
......
3729 3859

  
3730 3860

  
3731 3861
--
3732
-- Name: sourcename; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3733
--
3734

  
3735
CREATE TABLE sourcename (
3736
    sourcename_id integer NOT NULL,
3737
    source_id integer NOT NULL,
3738
    system text,
3739
    name text NOT NULL,
3740
    matched_source_id integer
3741
);
3742

  
3743

  
3744
--
3745 3862
-- Name: sourcename_sourcename_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3746 3863
--
3747 3864

  
......
3808 3925

  
3809 3926

  
3810 3927
--
3811
-- Name: specimenreplicate; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3812
--
3813

  
3814
CREATE TABLE specimenreplicate (
3815
    specimenreplicate_id integer NOT NULL,
3816
    source_id integer NOT NULL,
3817
    sourceaccessioncode text,
3818
    plantobservation_id integer,
3819
    institution_id integer,
3820
    collectioncode_dwc text,
3821
    catalognumber_dwc text,
3822
    description text,
3823
    specimen_id integer,
3824
    accessioncode text,
3825
    CONSTRAINT specimenreplicate_required_key CHECK ((((plantobservation_id IS NOT NULL) OR (sourceaccessioncode IS NOT NULL)) OR (catalognumber_dwc IS NOT NULL)))
3826
);
3827

  
3828

  
3829
--
3830
-- Name: TABLE specimenreplicate; Type: COMMENT; Schema: public; Owner: -
3831
--
3832

  
3833
COMMENT ON TABLE specimenreplicate IS 'A herbarium''s replicate of a specimen. Contains Darwin Core specimen data.';
3834

  
3835

  
3836
--
3837
-- Name: COLUMN specimenreplicate.institution_id; Type: COMMENT; Schema: public; Owner: -
3838
--
3839

  
3840
COMMENT ON COLUMN specimenreplicate.institution_id IS 'The institution (such as a museum) that the specimenreplicate is from.';
3841

  
3842

  
3843
--
3844
-- Name: COLUMN specimenreplicate.collectioncode_dwc; Type: COMMENT; Schema: public; Owner: -
3845
--
3846

  
3847
COMMENT ON COLUMN specimenreplicate.collectioncode_dwc IS 'The code for the collection that the specimenreplicate is from.';
3848

  
3849

  
3850
--
3851 3928
-- Name: specimenreplicate_specimenreplicate_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3852 3929
--
3853 3930

  
......
4997 5074

  
4998 5075

  
4999 5076
--
5077
-- Data for Name: darwin_core; Type: TABLE DATA; Schema: public; Owner: -
5078
--
5079

  
5080

  
5081

  
5082
--
5000 5083
-- Data for Name: definedvalue; Type: TABLE DATA; Schema: public; Owner: -
5001 5084
--
5002 5085

  
......
5987 6070

  
5988 6071

  
5989 6072
--
6073
-- Name: darwin_core_institutionCode_catalogNumber_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6074
--
6075

  
6076
CREATE INDEX "darwin_core_institutionCode_catalogNumber_idx" ON darwin_core USING btree ("institutionCode", "catalogNumber");
6077

  
6078

  
6079
--
6080
-- Name: darwin_core_institutionCode_occurrenceID_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6081
--
6082

  
6083
CREATE INDEX "darwin_core_institutionCode_occurrenceID_idx" ON darwin_core USING btree ("institutionCode", "occurrenceID");
6084

  
6085

  
6086
--
6087
-- Name: darwin_core_institutionCode_projectID_plotName_dateCollecte_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6088
--
6089

  
6090
CREATE INDEX "darwin_core_institutionCode_projectID_plotName_dateCollecte_idx" ON darwin_core USING btree ("institutionCode", "projectID", "plotName", "dateCollected");
6091

  
6092

  
6093
--
6094
-- Name: darwin_core_institutionCode_subInstitutionCode_collectionCo_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
6095
--
6096

  
6097
CREATE INDEX "darwin_core_institutionCode_subInstitutionCode_collectionCo_idx" ON darwin_core USING btree ("institutionCode", "subInstitutionCode", "collectionCode", "catalogNumber");
6098

  
6099

  
6100
--
5990 6101
-- Name: graphic_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5991 6102
--
5992 6103

  
......
7840 7951

  
7841 7952

  
7842 7953
--
7954
-- Name: project; Type: ACL; Schema: public; Owner: -
7955
--
7956

  
7957
REVOKE ALL ON TABLE project FROM PUBLIC;
7958
REVOKE ALL ON TABLE project FROM bien;
7959
GRANT ALL ON TABLE project TO bien;
7960
GRANT SELECT ON TABLE project TO bien_read;
7961

  
7962

  
7963
--
7964
-- Name: sourcename; Type: ACL; Schema: public; Owner: -
7965
--
7966

  
7967
REVOKE ALL ON TABLE sourcename FROM PUBLIC;
7968
REVOKE ALL ON TABLE sourcename FROM bien;
7969
GRANT ALL ON TABLE sourcename TO bien;
7970
GRANT SELECT ON TABLE sourcename TO bien_read;
7971

  
7972

  
7973
--
7974
-- Name: specimenreplicate; Type: ACL; Schema: public; Owner: -
7975
--
7976

  
7977
REVOKE ALL ON TABLE specimenreplicate FROM PUBLIC;
7978
REVOKE ALL ON TABLE specimenreplicate FROM bien;
7979
GRANT ALL ON TABLE specimenreplicate TO bien;
7980
GRANT SELECT ON TABLE specimenreplicate TO bien_read;
7981

  
7982

  
7983
--
7843 7984
-- Name: definedvalue; Type: ACL; Schema: public; Owner: -
7844 7985
--
7845 7986

  
......
8000 8141

  
8001 8142

  
8002 8143
--
8003
-- Name: project; Type: ACL; Schema: public; Owner: -
8004
--
8005

  
8006
REVOKE ALL ON TABLE project FROM PUBLIC;
8007
REVOKE ALL ON TABLE project FROM bien;
8008
GRANT ALL ON TABLE project TO bien;
8009
GRANT SELECT ON TABLE project TO bien_read;
8010

  
8011

  
8012
--
8013 8144
-- Name: projectcontributor; Type: ACL; Schema: public; Owner: -
8014 8145
--
8015 8146

  
......
8060 8191

  
8061 8192

  
8062 8193
--
8063
-- Name: sourcename; Type: ACL; Schema: public; Owner: -
8064
--
8065

  
8066
REVOKE ALL ON TABLE sourcename FROM PUBLIC;
8067
REVOKE ALL ON TABLE sourcename FROM bien;
8068
GRANT ALL ON TABLE sourcename TO bien;
8069
GRANT SELECT ON TABLE sourcename TO bien_read;
8070

  
8071

  
8072
--
8073 8194
-- Name: specimen; Type: ACL; Schema: public; Owner: -
8074 8195
--
8075 8196

  
......
8080 8201

  
8081 8202

  
8082 8203
--
8083
-- Name: specimenreplicate; Type: ACL; Schema: public; Owner: -
8084
--
8085

  
8086
REVOKE ALL ON TABLE specimenreplicate FROM PUBLIC;
8087
REVOKE ALL ON TABLE specimenreplicate FROM bien;
8088
GRANT ALL ON TABLE specimenreplicate TO bien;
8089
GRANT SELECT ON TABLE specimenreplicate TO bien_read;
8090

  
8091

  
8092
--
8093 8204
-- Name: stratum; Type: ACL; Schema: public; Owner: -
8094 8205
--
8095 8206

  

Also available in: Unified diff