Project

General

Profile

« Previous | Next » 

Revision 5242

schemas/vegbien.sql: Renamed datasource_id to creator_id so it can apply generally to any entity (such as a person), not just an aggregated datasource. This also enables taxonconcept.datasource_id to merge with creator_id, which now serves the same purpose.

View differences:

vegbien.sql
270 270

  
271 271

  
272 272
--
273
-- Name: party_datasource_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
273
-- Name: party_creator_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
274 274
--
275 275

  
276
CREATE FUNCTION party_datasource_id_self_ref() RETURNS trigger
276
CREATE FUNCTION party_creator_id_self_ref() RETURNS trigger
277 277
    LANGUAGE plpgsql
278 278
    AS $$
279 279
BEGIN
280 280
    IF new.party_id IS NULL THEN -- prepopulate party_id
281 281
        new.party_id = nextval('party_party_id_seq'::regclass);
282 282
    END IF;
283
    IF new.datasource_id = 0 THEN -- make self-reference
284
        new.datasource_id = new.party_id;
283
    IF new.creator_id = 0 THEN -- make self-reference
284
        new.creator_id = new.party_id;
285 285
    END IF;
286 286
    RETURN new;
287 287
END;
......
505 505

  
506 506
CREATE TABLE aggregateoccurrence (
507 507
    aggregateoccurrence_id integer NOT NULL,
508
    datasource_id integer NOT NULL,
508
    creator_id integer NOT NULL,
509 509
    sourceaccessioncode text,
510 510
    taxonoccurrence_id integer NOT NULL,
511 511
    collectiondate timestamp with time zone,
......
570 570

  
571 571
CREATE TABLE location (
572 572
    location_id integer NOT NULL,
573
    datasource_id integer NOT NULL,
573
    creator_id integer NOT NULL,
574 574
    sourceaccessioncode text,
575 575
    parent_id integer,
576 576
    authorlocationcode text,
......
665 665

  
666 666
CREATE TABLE locationevent (
667 667
    locationevent_id integer NOT NULL,
668
    datasource_id integer NOT NULL,
668
    creator_id integer NOT NULL,
669 669
    sourceaccessioncode text,
670 670
    parent_id integer,
671 671
    location_id integer,
......
965 965

  
966 966
CREATE TABLE party (
967 967
    party_id integer NOT NULL,
968
    datasource_id integer NOT NULL,
968
    creator_id integer NOT NULL,
969 969
    salutation text,
970 970
    givenname text,
971 971
    middlename text,
......
983 983

  
984 984

  
985 985
--
986
-- Name: COLUMN party.datasource_id; Type: COMMENT; Schema: public; Owner: -
986
-- Name: COLUMN party.creator_id; Type: COMMENT; Schema: public; Owner: -
987 987
--
988 988

  
989
COMMENT ON COLUMN party.datasource_id IS 'A datasource should point to itself in this field. This will happen automatically by setting it to the special value 0.';
989
COMMENT ON COLUMN party.creator_id IS 'A datasource should point to itself in this field. This will happen automatically by setting it to the special value 0.';
990 990

  
991 991

  
992 992
--
......
995 995

  
996 996
CREATE TABLE placepath (
997 997
    placepath_id integer NOT NULL,
998
    datasource_id integer NOT NULL,
998
    creator_id integer NOT NULL,
999 999
    placecode text,
1000 1000
    canon_placepath_id integer,
1001 1001
    place_id integer,
......
1041 1041

  
1042 1042
CREATE TABLE plantobservation (
1043 1043
    plantobservation_id integer NOT NULL,
1044
    datasource_id integer NOT NULL,
1044
    creator_id integer NOT NULL,
1045 1045
    sourceaccessioncode text,
1046 1046
    aggregateoccurrence_id integer NOT NULL,
1047 1047
    overallheight_m double precision,
......
1073 1073

  
1074 1074
CREATE TABLE specimenreplicate (
1075 1075
    specimenreplicate_id integer NOT NULL,
1076
    datasource_id integer NOT NULL,
1076
    creator_id integer NOT NULL,
1077 1077
    sourceaccessioncode text,
1078 1078
    plantobservation_id integer,
1079 1079
    institution_id integer,
......
1113 1113

  
1114 1114
CREATE TABLE taxonconcept (
1115 1115
    taxonconcept_id integer NOT NULL,
1116
    datasource_id integer NOT NULL,
1117
    creator_id integer,
1116
    creator_id integer NOT NULL,
1118 1117
    identifyingtaxonomicname text,
1119 1118
    canon_taxonconcept_id integer,
1120 1119
    taxon_id integer,
......
1346 1345

  
1347 1346
CREATE TABLE taxonoccurrence (
1348 1347
    taxonoccurrence_id integer NOT NULL,
1349
    datasource_id integer NOT NULL,
1348
    creator_id integer NOT NULL,
1350 1349
    sourceaccessioncode text,
1351 1350
    locationevent_id integer,
1352 1351
    authortaxoncode text,
......
1392 1391
--
1393 1392

  
1394 1393
CREATE VIEW analytical_db_view AS
1395
    SELECT datasource.organizationname AS "dataSourceName", taxonconcept.family, taxonconcept.genus, taxonconcept.species, COALESCE(taxonconcept.taxonomicnamewithauthor, taxonconcept.taxonomicname) AS taxon, taxonconcept.author AS "taxonAuthor", taxonconcept.variety AS "taxonMorphospecies", placepath.country, placepath.stateprovince AS "stateProvince", placepath.county AS "countyParish", taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS "collectionNumber", array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text) AS "identifiedBy", aggregateoccurrence.collectiondate AS "observationDate", location.authorlocationcode AS "plotCode", functions._m2_to_ha(location.area_m2) AS "plotAreaHa", method.name AS "plotMethod", locationcoords.latitude_deg AS latitude, locationcoords.longitude_deg AS longitude, location.elevation_m, taxonoccurrence.iscultivated AS "isCultivated", taxonoccurrence.cultivatedbasis AS "isCultivatedReason", functions._fraction_to_percent(aggregateoccurrence.cover_fraction) AS "pctCover" FROM (((((((((((((location JOIN party datasource ON (((datasource.party_id = location.datasource_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN placepath USING (placepath_id)) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonconcept USING (taxonconcept_id)) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
1394
    SELECT datasource.organizationname AS "dataSourceName", taxonconcept.family, taxonconcept.genus, taxonconcept.species, COALESCE(taxonconcept.taxonomicnamewithauthor, taxonconcept.taxonomicname) AS taxon, taxonconcept.author AS "taxonAuthor", taxonconcept.variety AS "taxonMorphospecies", placepath.country, placepath.stateprovince AS "stateProvince", placepath.county AS "countyParish", taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS "collectionNumber", array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text) AS "identifiedBy", aggregateoccurrence.collectiondate AS "observationDate", location.authorlocationcode AS "plotCode", functions._m2_to_ha(location.area_m2) AS "plotAreaHa", method.name AS "plotMethod", locationcoords.latitude_deg AS latitude, locationcoords.longitude_deg AS longitude, location.elevation_m, taxonoccurrence.iscultivated AS "isCultivated", taxonoccurrence.cultivatedbasis AS "isCultivatedReason", functions._fraction_to_percent(aggregateoccurrence.cover_fraction) AS "pctCover" FROM (((((((((((((location JOIN party datasource ON (((datasource.party_id = location.creator_id) AND (datasource.organizationname IS NOT NULL)))) LEFT JOIN locationcoords USING (location_id)) LEFT JOIN locationplace USING (location_id)) LEFT JOIN placepath USING (placepath_id)) JOIN locationevent USING (location_id)) LEFT JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonconcept USING (taxonconcept_id)) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
1396 1395

  
1397 1396

  
1398 1397
--
......
2518 2517

  
2519 2518
CREATE TABLE project (
2520 2519
    project_id integer NOT NULL,
2521
    datasource_id integer NOT NULL,
2520
    creator_id integer NOT NULL,
2522 2521
    sourceaccessioncode text,
2523 2522
    projectname text,
2524 2523
    projectdescription text,
......
2950 2949

  
2951 2950
CREATE TABLE stemobservation (
2952 2951
    stemobservation_id integer NOT NULL,
2953
    datasource_id integer NOT NULL,
2952
    creator_id integer NOT NULL,
2954 2953
    sourceaccessioncode text,
2955 2954
    plantobservation_id integer NOT NULL,
2956 2955
    authorstemcode text,
......
4152 4151
--
4153 4152

  
4154 4153
ALTER TABLE ONLY project
4155
    ADD CONSTRAINT project_unique UNIQUE (datasource_id, projectname);
4154
    ADD CONSTRAINT project_unique UNIQUE (creator_id, projectname);
4156 4155

  
4157 4156

  
4158 4157
--
......
4378 4377

  
4379 4378

  
4380 4379
--
4381
-- Name: aggregateoccurrence_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4380
-- Name: aggregateoccurrence_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4382 4381
--
4383 4382

  
4384
CREATE UNIQUE INDEX aggregateoccurrence_unique_within_datasource ON aggregateoccurrence USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4383
CREATE UNIQUE INDEX aggregateoccurrence_unique_within_creator ON aggregateoccurrence USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4385 4384

  
4386 4385

  
4387 4386
--
......
4434 4433

  
4435 4434

  
4436 4435
--
4437
-- Name: location_unique_within_datasource_by_authorlocationcode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4436
-- Name: location_unique_within_creator_by_authorlocationcode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4438 4437
--
4439 4438

  
4440
CREATE UNIQUE INDEX location_unique_within_datasource_by_authorlocationcode ON location USING btree (datasource_id, (COALESCE(authorlocationcode, '\\N'::text))) WHERE (((authorlocationcode IS NOT NULL) AND (parent_id IS NULL)) AND (sourceaccessioncode IS NULL));
4439
CREATE UNIQUE INDEX location_unique_within_creator_by_authorlocationcode ON location USING btree (creator_id, (COALESCE(authorlocationcode, '\\N'::text))) WHERE (((authorlocationcode IS NOT NULL) AND (parent_id IS NULL)) AND (sourceaccessioncode IS NULL));
4441 4440

  
4442 4441

  
4443 4442
--
4444
-- Name: location_unique_within_datasource_by_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4443
-- Name: location_unique_within_creator_by_sourceaccessioncode; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4445 4444
--
4446 4445

  
4447
CREATE UNIQUE INDEX location_unique_within_datasource_by_sourceaccessioncode ON location USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4446
CREATE UNIQUE INDEX location_unique_within_creator_by_sourceaccessioncode ON location USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4448 4447

  
4449 4448

  
4450 4449
--
......
4476 4475

  
4477 4476

  
4478 4477
--
4479
-- Name: locationevent_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4478
-- Name: locationevent_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4480 4479
--
4481 4480

  
4482
CREATE UNIQUE INDEX locationevent_unique_within_datasource ON locationevent USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4481
CREATE UNIQUE INDEX locationevent_unique_within_creator ON locationevent USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4483 4482

  
4484 4483

  
4485 4484
--
......
4556 4555
-- Name: party_unique_root; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4557 4556
--
4558 4557

  
4559
CREATE UNIQUE INDEX party_unique_root ON party USING btree ((COALESCE(organizationname, '\\N'::text))) WHERE (datasource_id = party_id);
4558
CREATE UNIQUE INDEX party_unique_root ON party USING btree ((COALESCE(organizationname, '\\N'::text))) WHERE (creator_id = party_id);
4560 4559

  
4561 4560

  
4562 4561
--
4563
-- Name: party_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4562
-- Name: party_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4564 4563
--
4565 4564

  
4566
CREATE UNIQUE INDEX party_unique_within_datasource ON party USING btree (datasource_id, (COALESCE(organizationname, '\\N'::text)), (COALESCE(surname, '\\N'::text)), (COALESCE(givenname, '\\N'::text)), (COALESCE(middlename, '\\N'::text)));
4565
CREATE UNIQUE INDEX party_unique_within_creator ON party USING btree (creator_id, (COALESCE(organizationname, '\\N'::text)), (COALESCE(surname, '\\N'::text)), (COALESCE(givenname, '\\N'::text)), (COALESCE(middlename, '\\N'::text)));
4567 4566

  
4568 4567

  
4569 4568
--
......
4581 4580

  
4582 4581

  
4583 4582
--
4584
-- Name: placepath_unique_within_datasource_by_code; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4583
-- Name: placepath_unique_within_creator_by_code; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4585 4584
--
4586 4585

  
4587
CREATE UNIQUE INDEX placepath_unique_within_datasource_by_code ON placepath USING btree (datasource_id, (COALESCE(placecode, '\\N'::text))) WHERE (placecode IS NOT NULL);
4586
CREATE UNIQUE INDEX placepath_unique_within_creator_by_code ON placepath USING btree (creator_id, (COALESCE(placecode, '\\N'::text))) WHERE (placecode IS NOT NULL);
4588 4587

  
4589 4588

  
4590 4589
--
4591
-- Name: placepath_unique_within_datasource_by_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4590
-- Name: placepath_unique_within_creator_by_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4592 4591
--
4593 4592

  
4594
CREATE UNIQUE INDEX placepath_unique_within_datasource_by_name ON placepath USING btree (datasource_id, (COALESCE(continent, '\\N'::text)), (COALESCE(country, '\\N'::text)), (COALESCE(stateprovince, '\\N'::text)), (COALESCE(county, '\\N'::text)), (COALESCE(municipality, '\\N'::text)), (COALESCE(site, '\\N'::text)), (COALESCE(otherranks, ARRAY[]::rankedplacename[]))) WHERE (placecode IS NULL);
4593
CREATE UNIQUE INDEX placepath_unique_within_creator_by_name ON placepath USING btree (creator_id, (COALESCE(continent, '\\N'::text)), (COALESCE(country, '\\N'::text)), (COALESCE(stateprovince, '\\N'::text)), (COALESCE(county, '\\N'::text)), (COALESCE(municipality, '\\N'::text)), (COALESCE(site, '\\N'::text)), (COALESCE(otherranks, ARRAY[]::rankedplacename[]))) WHERE (placecode IS NULL);
4595 4594

  
4596 4595

  
4597 4596
--
......
4602 4601

  
4603 4602

  
4604 4603
--
4605
-- Name: plantobservation_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4604
-- Name: plantobservation_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4606 4605
--
4607 4606

  
4608
CREATE UNIQUE INDEX plantobservation_unique_within_datasource ON plantobservation USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4607
CREATE UNIQUE INDEX plantobservation_unique_within_creator ON plantobservation USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4609 4608

  
4610 4609

  
4611 4610
--
......
4626 4625
-- Name: project_unique_name_date; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4627 4626
--
4628 4627

  
4629
CREATE UNIQUE INDEX project_unique_name_date ON project USING btree (datasource_id, (COALESCE(projectname, '\\N'::text)), (COALESCE(startdate, 'infinity'::timestamp with time zone))) WHERE (sourceaccessioncode IS NULL);
4628
CREATE UNIQUE INDEX project_unique_name_date ON project USING btree (creator_id, (COALESCE(projectname, '\\N'::text)), (COALESCE(startdate, 'infinity'::timestamp with time zone))) WHERE (sourceaccessioncode IS NULL);
4630 4629

  
4631 4630

  
4632 4631
--
4633
-- Name: project_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4632
-- Name: project_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4634 4633
--
4635 4634

  
4636
CREATE UNIQUE INDEX project_unique_within_datasource ON project USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4635
CREATE UNIQUE INDEX project_unique_within_creator ON project USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4637 4636

  
4638 4637

  
4639 4638
--
......
4682 4681
-- Name: specimenreplicate_unique_catalognumber; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4683 4682
--
4684 4683

  
4685
CREATE UNIQUE INDEX specimenreplicate_unique_catalognumber ON specimenreplicate USING btree (datasource_id, (COALESCE(institution_id, 2147483647)), (COALESCE(collectioncode_dwc, '\\N'::text)), (COALESCE(catalognumber_dwc, '\\N'::text)), (COALESCE(plantobservation_id, 2147483647))) WHERE ((catalognumber_dwc IS NOT NULL) AND (sourceaccessioncode IS NULL));
4684
CREATE UNIQUE INDEX specimenreplicate_unique_catalognumber ON specimenreplicate USING btree (creator_id, (COALESCE(institution_id, 2147483647)), (COALESCE(collectioncode_dwc, '\\N'::text)), (COALESCE(catalognumber_dwc, '\\N'::text)), (COALESCE(plantobservation_id, 2147483647))) WHERE ((catalognumber_dwc IS NOT NULL) AND (sourceaccessioncode IS NULL));
4686 4685

  
4687 4686

  
4688 4687
--
4689
-- Name: specimenreplicate_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4688
-- Name: specimenreplicate_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4690 4689
--
4691 4690

  
4692
CREATE UNIQUE INDEX specimenreplicate_unique_within_datasource ON specimenreplicate USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4691
CREATE UNIQUE INDEX specimenreplicate_unique_within_creator ON specimenreplicate USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4693 4692

  
4694 4693

  
4695 4694
--
......
4700 4699

  
4701 4700

  
4702 4701
--
4703
-- Name: stemobservation_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4702
-- Name: stemobservation_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4704 4703
--
4705 4704

  
4706
CREATE UNIQUE INDEX stemobservation_unique_within_datasource ON stemobservation USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4705
CREATE UNIQUE INDEX stemobservation_unique_within_creator ON stemobservation USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4707 4706

  
4708 4707

  
4709 4708
--
......
4728 4727

  
4729 4728

  
4730 4729
--
4731
-- Name: taxonconcept_unique_within_datasource_by_identifying_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4730
-- Name: taxonconcept_unique_within_creator_by_identifying_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4732 4731
--
4733 4732

  
4734
CREATE UNIQUE INDEX taxonconcept_unique_within_datasource_by_identifying_name ON taxonconcept USING btree (datasource_id, (COALESCE(identifyingtaxonomicname, '\\N'::text))) WHERE (identifyingtaxonomicname IS NOT NULL);
4733
CREATE UNIQUE INDEX taxonconcept_unique_within_creator_by_identifying_name ON taxonconcept USING btree (creator_id, (COALESCE(identifyingtaxonomicname, '\\N'::text))) WHERE (identifyingtaxonomicname IS NOT NULL);
4735 4734

  
4736 4735

  
4737 4736
--
4738
-- Name: taxonconcept_unique_within_datasource_by_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4737
-- Name: taxonconcept_unique_within_creator_by_name; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4739 4738
--
4740 4739

  
4741
CREATE UNIQUE INDEX taxonconcept_unique_within_datasource_by_name ON taxonconcept USING btree (datasource_id, (COALESCE(creator_id, 2147483647)), (COALESCE(taxonomicname, '\\N'::text)), (COALESCE(author, '\\N'::text)), (COALESCE(taxonomicnamewithauthor, '\\N'::text)), (COALESCE(domain, '\\N'::text)), (COALESCE(kingdom, '\\N'::text)), (COALESCE(phylum, '\\N'::text)), (COALESCE(class, '\\N'::text)), (COALESCE("order", '\\N'::text)), (COALESCE(family, '\\N'::text)), (COALESCE(genus, '\\N'::text)), (COALESCE(species, '\\N'::text)), (COALESCE(subspecies, '\\N'::text)), (COALESCE(variety, '\\N'::text)), (COALESCE(forma, '\\N'::text)), (COALESCE(cultivar, '\\N'::text)), (COALESCE(morphospecies, '\\N'::text)), (COALESCE(otherranks, ARRAY[]::rankedtaxonname[]))) WHERE (identifyingtaxonomicname IS NULL);
4740
CREATE UNIQUE INDEX taxonconcept_unique_within_creator_by_name ON taxonconcept USING btree (creator_id, (COALESCE(creator_id, 2147483647)), (COALESCE(taxonomicname, '\\N'::text)), (COALESCE(author, '\\N'::text)), (COALESCE(taxonomicnamewithauthor, '\\N'::text)), (COALESCE(domain, '\\N'::text)), (COALESCE(kingdom, '\\N'::text)), (COALESCE(phylum, '\\N'::text)), (COALESCE(class, '\\N'::text)), (COALESCE("order", '\\N'::text)), (COALESCE(family, '\\N'::text)), (COALESCE(genus, '\\N'::text)), (COALESCE(species, '\\N'::text)), (COALESCE(subspecies, '\\N'::text)), (COALESCE(variety, '\\N'::text)), (COALESCE(forma, '\\N'::text)), (COALESCE(cultivar, '\\N'::text)), (COALESCE(morphospecies, '\\N'::text)), (COALESCE(otherranks, ARRAY[]::rankedtaxonname[]))) WHERE (identifyingtaxonomicname IS NULL);
4742 4741

  
4743 4742

  
4744 4743
--
......
4770 4769

  
4771 4770

  
4772 4771
--
4773
-- Name: taxonoccurrence_unique_within_datasource; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4772
-- Name: taxonoccurrence_unique_within_creator; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4774 4773
--
4775 4774

  
4776
CREATE UNIQUE INDEX taxonoccurrence_unique_within_datasource ON taxonoccurrence USING btree (datasource_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4775
CREATE UNIQUE INDEX taxonoccurrence_unique_within_creator ON taxonoccurrence USING btree (creator_id, (COALESCE(sourceaccessioncode, '\\N'::text))) WHERE (sourceaccessioncode IS NOT NULL);
4777 4776

  
4778 4777

  
4779 4778
--
......
4791 4790

  
4792 4791

  
4793 4792
--
4794
-- Name: party_datasource_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
4793
-- Name: party_creator_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
4795 4794
--
4796 4795

  
4797
CREATE TRIGGER party_datasource_id_self_ref BEFORE INSERT OR UPDATE ON party FOR EACH ROW EXECUTE PROCEDURE party_datasource_id_self_ref();
4796
CREATE TRIGGER party_creator_id_self_ref BEFORE INSERT OR UPDATE ON party FOR EACH ROW EXECUTE PROCEDURE party_creator_id_self_ref();
4798 4797

  
4799 4798

  
4800 4799
--
......
4857 4856

  
4858 4857

  
4859 4858
--
4860
-- Name: aggregateoccurrence_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4859
-- Name: aggregateoccurrence_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4861 4860
--
4862 4861

  
4863 4862
ALTER TABLE ONLY aggregateoccurrence
4864
    ADD CONSTRAINT aggregateoccurrence_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
4863
    ADD CONSTRAINT aggregateoccurrence_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
4865 4864

  
4866 4865

  
4867 4866
--
......
5105 5104

  
5106 5105

  
5107 5106
--
5108
-- Name: location_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5107
-- Name: location_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5109 5108
--
5110 5109

  
5111 5110
ALTER TABLE ONLY location
5112
    ADD CONSTRAINT location_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5111
    ADD CONSTRAINT location_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5113 5112

  
5114 5113

  
5115 5114
--
......
5137 5136

  
5138 5137

  
5139 5138
--
5140
-- Name: locationevent_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5139
-- Name: locationevent_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5141 5140
--
5142 5141

  
5143 5142
ALTER TABLE ONLY locationevent
5144
    ADD CONSTRAINT locationevent_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5143
    ADD CONSTRAINT locationevent_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5145 5144

  
5146 5145

  
5147 5146
--
......
5321 5320

  
5322 5321

  
5323 5322
--
5324
-- Name: party_currentname_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5323
-- Name: party_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5325 5324
--
5326 5325

  
5327 5326
ALTER TABLE ONLY party
5328
    ADD CONSTRAINT party_currentname_id_fkey FOREIGN KEY (currentname_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5327
    ADD CONSTRAINT party_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5329 5328

  
5330 5329

  
5331 5330
--
5332
-- Name: party_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5331
-- Name: party_currentname_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5333 5332
--
5334 5333

  
5335 5334
ALTER TABLE ONLY party
5336
    ADD CONSTRAINT party_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5335
    ADD CONSTRAINT party_currentname_id_fkey FOREIGN KEY (currentname_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5337 5336

  
5338 5337

  
5339 5338
--
......
5401 5400

  
5402 5401

  
5403 5402
--
5404
-- Name: placepath_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5403
-- Name: placepath_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5405 5404
--
5406 5405

  
5407 5406
ALTER TABLE ONLY placepath
5408
    ADD CONSTRAINT placepath_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5407
    ADD CONSTRAINT placepath_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5409 5408

  
5410 5409

  
5411 5410
--
......
5457 5456

  
5458 5457

  
5459 5458
--
5460
-- Name: plantobservation_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5459
-- Name: plantobservation_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5461 5460
--
5462 5461

  
5463 5462
ALTER TABLE ONLY plantobservation
5464
    ADD CONSTRAINT plantobservation_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5463
    ADD CONSTRAINT plantobservation_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5465 5464

  
5466 5465

  
5467 5466
--
......
5529 5528

  
5530 5529

  
5531 5530
--
5532
-- Name: project_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5531
-- Name: project_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5533 5532
--
5534 5533

  
5535 5534
ALTER TABLE ONLY project
5536
    ADD CONSTRAINT project_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5535
    ADD CONSTRAINT project_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5537 5536

  
5538 5537

  
5539 5538
--
......
5617 5616

  
5618 5617

  
5619 5618
--
5620
-- Name: specimenreplicate_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5619
-- Name: specimenreplicate_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5621 5620
--
5622 5621

  
5623 5622
ALTER TABLE ONLY specimenreplicate
5624
    ADD CONSTRAINT specimenreplicate_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5623
    ADD CONSTRAINT specimenreplicate_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5625 5624

  
5626 5625

  
5627 5626
--
......
5649 5648

  
5650 5649

  
5651 5650
--
5652
-- Name: stemobservation_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5651
-- Name: stemobservation_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5653 5652
--
5654 5653

  
5655 5654
ALTER TABLE ONLY stemobservation
5656
    ADD CONSTRAINT stemobservation_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5655
    ADD CONSTRAINT stemobservation_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5657 5656

  
5658 5657

  
5659 5658
--
......
5753 5752

  
5754 5753

  
5755 5754
--
5756
-- Name: taxonconcept_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5757
--
5758

  
5759
ALTER TABLE ONLY taxonconcept
5760
    ADD CONSTRAINT taxonconcept_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5761

  
5762

  
5763
--
5764 5755
-- Name: taxonconcept_taxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5765 5756
--
5766 5757

  
......
5801 5792

  
5802 5793

  
5803 5794
--
5804
-- Name: taxonoccurrence_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5795
-- Name: taxonoccurrence_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5805 5796
--
5806 5797

  
5807 5798
ALTER TABLE ONLY taxonoccurrence
5808
    ADD CONSTRAINT taxonoccurrence_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5799
    ADD CONSTRAINT taxonoccurrence_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5809 5800

  
5810 5801

  
5811 5802
--

Also available in: Unified diff