Project

General

Profile

« Previous | Next » 

Revision 5282

schemas/vegbien.sql: Removed no longer used taxon table. Use taxonconcept instead.

View differences:

schemas/vegbien.my.sql
145 145

  
146 146

  
147 147
--
148
-- Name: taxon_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
149
--
150

  
151

  
152

  
153

  
154
--
155 148
-- Name: taxonconcept_canon_taxonconcept_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
156 149
--
157 150

  
......
2451 2444

  
2452 2445

  
2453 2446
--
2454
-- Name: taxon; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2455
--
2456

  
2457
CREATE TABLE taxon (
2458
    taxon_id int(11) NOT NULL,
2459
    parent_id int(11),
2460
    rank text NOT NULL,
2461
    verbatimrank text,
2462
    taxonname text NOT NULL,
2463
    author_id int(11),
2464
    authority_id int(11),
2465
    description text,
2466
    accessioncode text
2467
);
2468

  
2469

  
2470
--
2471
-- Name: TABLE taxon; Type: COMMENT; Schema: public; Owner: -
2472
--
2473

  
2474

  
2475

  
2476

  
2477
--
2478
-- Name: COLUMN taxon.parent_id; Type: COMMENT; Schema: public; Owner: -
2479
--
2480

  
2481

  
2482

  
2483

  
2484
--
2485
-- Name: COLUMN taxon.rank; Type: COMMENT; Schema: public; Owner: -
2486
--
2487

  
2488

  
2489

  
2490

  
2491
--
2492
-- Name: COLUMN taxon.verbatimrank; Type: COMMENT; Schema: public; Owner: -
2493
--
2494

  
2495

  
2496

  
2497

  
2498
--
2499
-- Name: COLUMN taxon.taxonname; Type: COMMENT; Schema: public; Owner: -
2500
--
2501

  
2502

  
2503

  
2504

  
2505
--
2506
-- Name: COLUMN taxon.author_id; Type: COMMENT; Schema: public; Owner: -
2507
--
2508

  
2509

  
2510

  
2511

  
2512
--
2513
-- Name: COLUMN taxon.authority_id; Type: COMMENT; Schema: public; Owner: -
2514
--
2515

  
2516

  
2517

  
2518

  
2519
--
2520
-- Name: COLUMN taxon.description; Type: COMMENT; Schema: public; Owner: -
2521
--
2522

  
2523

  
2524

  
2525

  
2526
--
2527
-- Name: taxon_ancestor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2528
--
2529

  
2530
CREATE TABLE taxon_ancestor (
2531
    taxon_id int(11) NOT NULL,
2532
    ancestor_id int(11) NOT NULL
2533
);
2534

  
2535

  
2536
--
2537
-- Name: taxon_taxon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
2538
--
2539

  
2540

  
2541

  
2542

  
2543
--
2544
-- Name: taxon_taxon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
2545
--
2546

  
2547

  
2548

  
2549

  
2550
--
2551 2447
-- Name: taxonalt; Type: TABLE; Schema: public; Owner: -; Tablespace: 
2552 2448
--
2553 2449

  
......
3091 2987

  
3092 2988

  
3093 2989
--
3094
-- Name: taxon_id; Type: DEFAULT; Schema: public; Owner: -
3095
--
3096

  
3097

  
3098

  
3099

  
3100
--
3101 2990
-- Name: taxonalt_id; Type: DEFAULT; Schema: public; Owner: -
3102 2991
--
3103 2992

  
......
3642 3531

  
3643 3532

  
3644 3533
--
3645
-- Name: taxon_ancestor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3646
--
3647

  
3648
ALTER TABLE taxon_ancestor
3649
    ADD CONSTRAINT taxon_ancestor_pkey PRIMARY KEY (taxon_id, ancestor_id);
3650

  
3651

  
3652
--
3653
-- Name: taxon_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3654
--
3655

  
3656
ALTER TABLE taxon
3657
    ADD CONSTRAINT taxon_pkey PRIMARY KEY (taxon_id);
3658

  
3659

  
3660
--
3661 3534
-- Name: taxonalt_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3662 3535
--
3663 3536

  
......
4096 3969

  
4097 3970

  
4098 3971
--
4099
-- Name: taxon_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4100
--
4101

  
4102

  
4103

  
4104

  
4105
--
4106 3972
-- Name: taxonconcept_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4107 3973
--
4108 3974

  
......
4208 4074

  
4209 4075

  
4210 4076
--
4211
-- Name: taxon_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
4212
--
4213

  
4214

  
4215

  
4216

  
4217
--
4218 4077
-- Name: taxonconcept_canon_taxonconcept_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
4219 4078
--
4220 4079

  
......
5034 4893

  
5035 4894

  
5036 4895
--
5037
-- Name: taxon_ancestor_ancestor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5038
--
5039

  
5040
ALTER TABLE taxon_ancestor
5041
    ADD CONSTRAINT taxon_ancestor_ancestor_id_fkey FOREIGN KEY (ancestor_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5042

  
5043

  
5044
--
5045
-- Name: taxon_ancestor_taxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5046
--
5047

  
5048
ALTER TABLE taxon_ancestor
5049
    ADD CONSTRAINT taxon_ancestor_taxon_id_fkey FOREIGN KEY (taxon_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5050

  
5051

  
5052
--
5053
-- Name: taxon_author_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5054
--
5055

  
5056

  
5057

  
5058

  
5059
--
5060
-- Name: taxon_authority_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5061
--
5062

  
5063

  
5064

  
5065

  
5066
--
5067
-- Name: taxon_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5068
--
5069

  
5070
ALTER TABLE taxon
5071
    ADD CONSTRAINT taxon_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5072

  
5073

  
5074
--
5075 4896
-- Name: taxonalt_taxonconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5076 4897
--
5077 4898

  
schemas/vegbien.sql
377 377

  
378 378

  
379 379
--
380
-- Name: taxon_update_ancestors(); Type: FUNCTION; Schema: public; Owner: -
381
--
382

  
383
CREATE FUNCTION taxon_update_ancestors() RETURNS trigger
384
    LANGUAGE plpgsql
385
    AS $$
386
BEGIN
387
    -- Delete existing ancestors
388
    DELETE FROM taxon_ancestor WHERE taxon_id = new.taxon_id;
389
    
390
    IF new.parent_id IS NOT NULL THEN
391
        -- Copy parent's ancestors to this node's ancestors
392
        INSERT
393
        INTO taxon_ancestor
394
        (taxon_id, ancestor_id)
395
        SELECT
396
            new.taxon_id, ancestor_id
397
        FROM taxon_ancestor
398
        WHERE taxon_id = new.parent_id
399
        ;
400
    END IF;
401
    
402
    -- Add "ancestor" for this node
403
    /* This is useful for queries, because you don't have to separately test if
404
    the leaf node is the one you're looking for, in addition to that leaf node's
405
    ancestors. */
406
    INSERT
407
    INTO taxon_ancestor
408
    (taxon_id, ancestor_id)
409
    VALUES (new.taxon_id, new.taxon_id)
410
    ;
411
    
412
    -- Tell immediate children to update their ancestors lists, which will
413
    -- recursively tell all descendants
414
    UPDATE taxon
415
    SET taxon_id = taxon_id -- need at least one SET statement
416
    -- Add COALESCE() to enable using taxon_unique index for lookup
417
    WHERE COALESCE(parent_id, 2147483647) = new.taxon_id
418
    ;
419
    
420
    /* Note: We don't need an ON DELETE trigger to update the descendants'
421
    ancestors when a node is deleted, because the taxon.taxon_parent_id
422
    foreign key is set to ON DELETE CASCADE, which just removes all the
423
    descendants anyway. */
424
    
425
    RETURN new;
426
END;
427
$$;
428

  
429

  
430
--
431 380
-- Name: taxonconcept_canon_taxonconcept_id_self_ref(); Type: FUNCTION; Schema: public; Owner: -
432 381
--
433 382

  
......
3101 3050

  
3102 3051

  
3103 3052
--
3104
-- Name: taxon; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3105
--
3106

  
3107
CREATE TABLE taxon (
3108
    taxon_id integer NOT NULL,
3109
    parent_id integer,
3110
    rank taxonrank NOT NULL,
3111
    verbatimrank text,
3112
    taxonname text NOT NULL,
3113
    author_id integer,
3114
    authority_id integer,
3115
    description text,
3116
    accessioncode text
3117
);
3118

  
3119

  
3120
--
3121
-- Name: TABLE taxon; Type: COMMENT; Schema: public; Owner: -
3122
--
3123

  
3124
COMMENT ON TABLE taxon IS 'A formal, named taxon in the tree of life. Can be at any level in the taxonomic hierarchy. Note that the taxon name stores only one rank (e.g. family) of the full taxonomic name. The higher-level ranks are stored in the taxon''s chain of parent_id ancestors.
3125

  
3126
Equivalent to VegBank''s plantConcept and plantName tables, plus plantParent_ID and
3127
plantLevel from plantStatus.';
3128

  
3129

  
3130
--
3131
-- Name: COLUMN taxon.parent_id; Type: COMMENT; Schema: public; Owner: -
3132
--
3133

  
3134
COMMENT ON COLUMN taxon.parent_id IS 'The parent taxon.';
3135

  
3136

  
3137
--
3138
-- Name: COLUMN taxon.rank; Type: COMMENT; Schema: public; Owner: -
3139
--
3140

  
3141
COMMENT ON COLUMN taxon.rank IS 'The taxon''s level in the taxonomic hierarchy, standardized to a closed list. Even if you specify a custom verbatimrank, you must also specify a closest-match rank from the taxonrank closed list.';
3142

  
3143

  
3144
--
3145
-- Name: COLUMN taxon.verbatimrank; Type: COMMENT; Schema: public; Owner: -
3146
--
3147

  
3148
COMMENT ON COLUMN taxon.verbatimrank IS 'The taxon''s verbatim level in the taxonomic hierarchy. Does not need to be in the taxonrank closed list.';
3149

  
3150

  
3151
--
3152
-- Name: COLUMN taxon.taxonname; Type: COMMENT; Schema: public; Owner: -
3153
--
3154

  
3155
COMMENT ON COLUMN taxon.taxonname IS 'The name of the taxon within its parent taxon. Contains only the lowest-rank portion of the taxonomic name. (The higher-level ranks are stored in the taxon''s chain of parent_id ancestors.)';
3156

  
3157

  
3158
--
3159
-- Name: COLUMN taxon.author_id; Type: COMMENT; Schema: public; Owner: -
3160
--
3161

  
3162
COMMENT ON COLUMN taxon.author_id IS 'The author of the taxon name.';
3163

  
3164

  
3165
--
3166
-- Name: COLUMN taxon.authority_id; Type: COMMENT; Schema: public; Owner: -
3167
--
3168

  
3169
COMMENT ON COLUMN taxon.authority_id IS 'The authority which defines the taxon name.';
3170

  
3171

  
3172
--
3173
-- Name: COLUMN taxon.description; Type: COMMENT; Schema: public; Owner: -
3174
--
3175

  
3176
COMMENT ON COLUMN taxon.description IS 'The authority''s description of the taxon.';
3177

  
3178

  
3179
--
3180
-- Name: taxon_ancestor; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3181
--
3182

  
3183
CREATE TABLE taxon_ancestor (
3184
    taxon_id integer NOT NULL,
3185
    ancestor_id integer NOT NULL
3186
);
3187

  
3188

  
3189
--
3190
-- Name: taxon_taxon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
3191
--
3192

  
3193
CREATE SEQUENCE taxon_taxon_id_seq
3194
    START WITH 1
3195
    INCREMENT BY 1
3196
    NO MINVALUE
3197
    NO MAXVALUE
3198
    CACHE 1;
3199

  
3200

  
3201
--
3202
-- Name: taxon_taxon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
3203
--
3204

  
3205
ALTER SEQUENCE taxon_taxon_id_seq OWNED BY taxon.taxon_id;
3206

  
3207

  
3208
--
3209 3053
-- Name: taxonalt; Type: TABLE; Schema: public; Owner: -; Tablespace: 
3210 3054
--
3211 3055

  
......
3789 3633

  
3790 3634

  
3791 3635
--
3792
-- Name: taxon_id; Type: DEFAULT; Schema: public; Owner: -
3793
--
3794

  
3795
ALTER TABLE taxon ALTER COLUMN taxon_id SET DEFAULT nextval('taxon_taxon_id_seq'::regclass);
3796

  
3797

  
3798
--
3799 3636
-- Name: taxonalt_id; Type: DEFAULT; Schema: public; Owner: -
3800 3637
--
3801 3638

  
......
4340 4177

  
4341 4178

  
4342 4179
--
4343
-- Name: taxon_ancestor_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4344
--
4345

  
4346
ALTER TABLE ONLY taxon_ancestor
4347
    ADD CONSTRAINT taxon_ancestor_pkey PRIMARY KEY (taxon_id, ancestor_id);
4348

  
4349

  
4350
--
4351
-- Name: taxon_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4352
--
4353

  
4354
ALTER TABLE ONLY taxon
4355
    ADD CONSTRAINT taxon_pkey PRIMARY KEY (taxon_id);
4356

  
4357

  
4358
--
4359 4180
-- Name: taxonalt_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4360 4181
--
4361 4182

  
......
4794 4615

  
4795 4616

  
4796 4617
--
4797
-- Name: taxon_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4798
--
4799

  
4800
CREATE UNIQUE INDEX taxon_unique ON taxon USING btree ((COALESCE(parent_id, 2147483647)), taxonname, rank, (COALESCE(author_id, 2147483647)), (COALESCE(authority_id, 2147483647)));
4801

  
4802

  
4803
--
4804 4618
-- Name: taxonconcept_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4805 4619
--
4806 4620

  
......
4906 4720

  
4907 4721

  
4908 4722
--
4909
-- Name: taxon_update_ancestors; Type: TRIGGER; Schema: public; Owner: -
4910
--
4911

  
4912
CREATE TRIGGER taxon_update_ancestors AFTER INSERT OR UPDATE ON taxon FOR EACH ROW EXECUTE PROCEDURE taxon_update_ancestors();
4913

  
4914

  
4915
--
4916 4723
-- Name: taxonconcept_canon_taxonconcept_id_self_ref; Type: TRIGGER; Schema: public; Owner: -
4917 4724
--
4918 4725

  
......
5767 5574

  
5768 5575

  
5769 5576
--
5770
-- Name: taxon_ancestor_ancestor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5771
--
5772

  
5773
ALTER TABLE ONLY taxon_ancestor
5774
    ADD CONSTRAINT taxon_ancestor_ancestor_id_fkey FOREIGN KEY (ancestor_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5775

  
5776

  
5777
--
5778
-- Name: taxon_ancestor_taxon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5779
--
5780

  
5781
ALTER TABLE ONLY taxon_ancestor
5782
    ADD CONSTRAINT taxon_ancestor_taxon_id_fkey FOREIGN KEY (taxon_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5783

  
5784

  
5785
--
5786
-- Name: taxon_author_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5787
--
5788

  
5789
ALTER TABLE ONLY taxon
5790
    ADD CONSTRAINT taxon_author_id_fkey FOREIGN KEY (author_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
5791

  
5792

  
5793
--
5794
-- Name: taxon_authority_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5795
--
5796

  
5797
ALTER TABLE ONLY taxon
5798
    ADD CONSTRAINT taxon_authority_id_fkey FOREIGN KEY (authority_id) REFERENCES reference(reference_id) ON UPDATE CASCADE ON DELETE CASCADE;
5799

  
5800

  
5801
--
5802
-- Name: taxon_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5803
--
5804

  
5805
ALTER TABLE ONLY taxon
5806
    ADD CONSTRAINT taxon_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES taxon(taxon_id) ON UPDATE CASCADE ON DELETE CASCADE;
5807

  
5808

  
5809
--
5810 5577
-- Name: taxonalt_taxonconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5811 5578
--
5812 5579

  

Also available in: Unified diff