Revision 5234
Added by Aaron Marcuse-Kubitza over 12 years ago
vegbien.sql | ||
---|---|---|
270 | 270 |
|
271 | 271 |
|
272 | 272 |
-- |
273 |
-- Name: party_datasource_id_self_ref(); Type: FUNCTION; Schema: public; Owner: - |
|
274 |
-- |
|
275 |
|
|
276 |
CREATE FUNCTION party_datasource_id_self_ref() RETURNS trigger |
|
277 |
LANGUAGE plpgsql |
|
278 |
AS $$ |
|
279 |
BEGIN |
|
280 |
IF new.party_id IS NULL THEN -- prepopulate party_id |
|
281 |
new.party_id = nextval('party_party_id_seq'::regclass); |
|
282 |
END IF; |
|
283 |
IF new.datasource_id = 0 THEN -- make self-reference |
|
284 |
new.datasource_id = new.party_id; |
|
285 |
END IF; |
|
286 |
RETURN new; |
|
287 |
END; |
|
288 |
$$; |
|
289 |
|
|
290 |
|
|
291 |
-- |
|
273 | 292 |
-- Name: place_update_ancestors(); Type: FUNCTION; Schema: public; Owner: - |
274 | 293 |
-- |
275 | 294 |
|
... | ... | |
946 | 965 |
|
947 | 966 |
CREATE TABLE party ( |
948 | 967 |
party_id integer NOT NULL, |
968 |
datasource_id integer NOT NULL, |
|
949 | 969 |
salutation text, |
950 | 970 |
givenname text, |
951 | 971 |
middlename text, |
... | ... | |
963 | 983 |
|
964 | 984 |
|
965 | 985 |
-- |
986 |
-- Name: COLUMN party.datasource_id; Type: COMMENT; Schema: public; Owner: - |
|
987 |
-- |
|
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.'; |
|
990 |
|
|
991 |
|
|
992 |
-- |
|
966 | 993 |
-- Name: placepath; Type: TABLE; Schema: public; Owner: -; Tablespace: |
967 | 994 |
-- |
968 | 995 |
|
... | ... | |
4529 | 4556 |
-- Name: party_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: |
4530 | 4557 |
-- |
4531 | 4558 |
|
4532 |
CREATE UNIQUE INDEX party_unique ON party USING btree ((COALESCE(organizationname, '\\N'::text)), (COALESCE(surname, '\\N'::text)), (COALESCE(givenname, '\\N'::text)), (COALESCE(middlename, '\\N'::text))); |
|
4559 |
CREATE UNIQUE INDEX party_unique ON party USING btree (datasource_id, (COALESCE(organizationname, '\\N'::text)), (COALESCE(surname, '\\N'::text)), (COALESCE(givenname, '\\N'::text)), (COALESCE(middlename, '\\N'::text)));
|
|
4533 | 4560 |
|
4534 | 4561 |
|
4535 | 4562 |
-- |
... | ... | |
4757 | 4784 |
|
4758 | 4785 |
|
4759 | 4786 |
-- |
4787 |
-- Name: party_datasource_id_self_ref; Type: TRIGGER; Schema: public; Owner: - |
|
4788 |
-- |
|
4789 |
|
|
4790 |
CREATE TRIGGER party_datasource_id_self_ref BEFORE INSERT OR UPDATE ON party FOR EACH ROW EXECUTE PROCEDURE party_datasource_id_self_ref(); |
|
4791 |
|
|
4792 |
|
|
4793 |
-- |
|
4760 | 4794 |
-- Name: place_update_ancestors; Type: TRIGGER; Schema: public; Owner: - |
4761 | 4795 |
-- |
4762 | 4796 |
|
... | ... | |
5288 | 5322 |
|
5289 | 5323 |
|
5290 | 5324 |
-- |
5325 |
-- Name: party_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - |
|
5326 |
-- |
|
5327 |
|
|
5328 |
ALTER TABLE ONLY party |
|
5329 |
ADD CONSTRAINT party_datasource_id_fkey FOREIGN KEY (datasource_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE; |
|
5330 |
|
|
5331 |
|
|
5332 |
-- |
|
5291 | 5333 |
-- Name: partymember_childparty_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - |
5292 | 5334 |
-- |
5293 | 5335 |
|
Also available in: Unified diff
schemas/vegbien.sql: party: Made it datasource-scoped. Since this creates a recursive fkey, a datasource (a root party) should point to itself in this field, which will happen automatically by setting it to the special value 0.