Revision 5603
Added by Aaron Marcuse-Kubitza about 12 years ago
schemas/vegbien.my.sql | ||
---|---|---|
2377 | 2377 |
-- |
2378 | 2378 |
|
2379 | 2379 |
CREATE TABLE taxonconcept_ancestor ( |
2380 |
taxonconcept_id int(11) NOT NULL,
|
|
2380 |
descendant_id int(11) NOT NULL,
|
|
2381 | 2381 |
ancestor_id int(11) NOT NULL |
2382 | 2382 |
); |
2383 | 2383 |
|
... | ... | |
3527 | 3527 |
-- |
3528 | 3528 |
|
3529 | 3529 |
ALTER TABLE taxonconcept_ancestor |
3530 |
ADD CONSTRAINT taxonconcept_ancestor_pkey PRIMARY KEY (taxonconcept_id, ancestor_id);
|
|
3530 |
ADD CONSTRAINT taxonconcept_ancestor_pkey PRIMARY KEY (descendant_id, ancestor_id);
|
|
3531 | 3531 |
|
3532 | 3532 |
|
3533 | 3533 |
-- |
... | ... | |
4010 | 4010 |
-- Name: taxonconcept_ancestor_descendants; Type: INDEX; Schema: public; Owner: -; Tablespace: |
4011 | 4011 |
-- |
4012 | 4012 |
|
4013 |
CREATE INDEX taxonconcept_ancestor_descendants ON taxonconcept_ancestor (ancestor_id, taxonconcept_id);
|
|
4013 |
CREATE INDEX taxonconcept_ancestor_descendants ON taxonconcept_ancestor (ancestor_id, descendant_id);
|
|
4014 | 4014 |
|
4015 | 4015 |
|
4016 | 4016 |
-- |
... | ... | |
4916 | 4916 |
|
4917 | 4917 |
|
4918 | 4918 |
-- |
4919 |
-- Name: taxonconcept_ancestor_taxonconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
4919 |
-- Name: taxonconcept_ancestor_descendant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
4920 | 4920 |
-- |
4921 | 4921 |
|
4922 | 4922 |
ALTER TABLE taxonconcept_ancestor |
4923 |
ADD CONSTRAINT taxonconcept_ancestor_taxonconcept_id_fkey FOREIGN KEY (taxonconcept_id) REFERENCES taxonconcept(taxonconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
4923 |
ADD CONSTRAINT taxonconcept_ancestor_descendant_id_fkey FOREIGN KEY (descendant_id) REFERENCES taxonconcept(taxonconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
4924 | 4924 |
|
4925 | 4925 |
|
4926 | 4926 |
-- |
schemas/vegbien.sql | ||
---|---|---|
685 | 685 |
-- These include the parent itself |
686 | 686 |
old_ancestors integer[] := ( |
687 | 687 |
SELECT array_agg(ancestor_id) FROM taxonconcept_ancestor |
688 |
WHERE taxonconcept_id = old_parent_id
|
|
688 |
WHERE descendant_id = old_parent_id
|
|
689 | 689 |
); |
690 | 690 |
new_ancestors integer[] := ( |
691 | 691 |
SELECT array_agg(ancestor_id) FROM taxonconcept_ancestor |
692 |
WHERE taxonconcept_id = parent_id_
|
|
692 |
WHERE descendant_id = parent_id_
|
|
693 | 693 |
); |
694 |
descendant_id integer; |
|
694 |
descendant_id_ integer;
|
|
695 | 695 |
BEGIN |
696 |
FOR descendant_id IN -- also includes self |
|
697 |
SELECT taxonconcept_id
|
|
696 |
FOR descendant_id_ IN -- also includes self
|
|
697 |
SELECT descendant_id
|
|
698 | 698 |
FROM taxonconcept_ancestor |
699 | 699 |
WHERE ancestor_id = new.taxonconcept_id |
700 | 700 |
LOOP |
701 | 701 |
-- Delete old parent's ancestors |
702 | 702 |
DELETE FROM taxonconcept_ancestor |
703 |
WHERE taxonconcept_id = descendant_id
|
|
703 |
WHERE descendant_id = descendant_id_
|
|
704 | 704 |
AND ancestor_id = ANY (old_ancestors) |
705 | 705 |
; |
706 | 706 |
|
707 | 707 |
-- Add new parent's ancestors |
708 | 708 |
INSERT INTO taxonconcept_ancestor |
709 |
(taxonconcept_id, ancestor_id)
|
|
710 |
SELECT descendant_id, unnest(new_ancestors) |
|
709 |
(descendant_id, ancestor_id)
|
|
710 |
SELECT descendant_id_, unnest(new_ancestors)
|
|
711 | 711 |
; |
712 | 712 |
END LOOP; |
713 | 713 |
END; |
... | ... | |
733 | 733 |
for, in addition to that leaf node's ancestors. */ |
734 | 734 |
INSERT |
735 | 735 |
INTO taxonconcept_ancestor |
736 |
(taxonconcept_id, ancestor_id)
|
|
736 |
(descendant_id, ancestor_id)
|
|
737 | 737 |
VALUES (new.taxonconcept_id, new.taxonconcept_id) |
738 | 738 |
; |
739 | 739 |
|
... | ... | |
3057 | 3057 |
-- |
3058 | 3058 |
|
3059 | 3059 |
CREATE TABLE taxonconcept_ancestor ( |
3060 |
taxonconcept_id integer NOT NULL,
|
|
3060 |
descendant_id integer NOT NULL,
|
|
3061 | 3061 |
ancestor_id integer NOT NULL |
3062 | 3062 |
); |
3063 | 3063 |
|
... | ... | |
4262 | 4262 |
-- |
4263 | 4263 |
|
4264 | 4264 |
ALTER TABLE ONLY taxonconcept_ancestor |
4265 |
ADD CONSTRAINT taxonconcept_ancestor_pkey PRIMARY KEY (taxonconcept_id, ancestor_id);
|
|
4265 |
ADD CONSTRAINT taxonconcept_ancestor_pkey PRIMARY KEY (descendant_id, ancestor_id);
|
|
4266 | 4266 |
|
4267 | 4267 |
|
4268 | 4268 |
-- |
... | ... | |
4745 | 4745 |
-- Name: taxonconcept_ancestor_descendants; Type: INDEX; Schema: public; Owner: -; Tablespace: |
4746 | 4746 |
-- |
4747 | 4747 |
|
4748 |
CREATE INDEX taxonconcept_ancestor_descendants ON taxonconcept_ancestor USING btree (ancestor_id, taxonconcept_id);
|
|
4748 |
CREATE INDEX taxonconcept_ancestor_descendants ON taxonconcept_ancestor USING btree (ancestor_id, descendant_id);
|
|
4749 | 4749 |
|
4750 | 4750 |
|
4751 | 4751 |
-- |
... | ... | |
5681 | 5681 |
|
5682 | 5682 |
|
5683 | 5683 |
-- |
5684 |
-- Name: taxonconcept_ancestor_taxonconcept_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
5684 |
-- Name: taxonconcept_ancestor_descendant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
|
5685 | 5685 |
-- |
5686 | 5686 |
|
5687 | 5687 |
ALTER TABLE ONLY taxonconcept_ancestor |
5688 |
ADD CONSTRAINT taxonconcept_ancestor_taxonconcept_id_fkey FOREIGN KEY (taxonconcept_id) REFERENCES taxonconcept(taxonconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
5688 |
ADD CONSTRAINT taxonconcept_ancestor_descendant_id_fkey FOREIGN KEY (descendant_id) REFERENCES taxonconcept(taxonconcept_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
5689 | 5689 |
|
5690 | 5690 |
|
5691 | 5691 |
-- |
Also available in: Unified diff
schemas/vegbien.sql: taxonconcept_ancestor: Renamed taxonconcept_id to descendant_id to emphasize the direction of the relationship between the two taxonconcepts