]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Postgres/090.schema.action.sql
field name adjustments
[Evergreen.git] / Open-ILS / src / sql / Postgres / 090.schema.action.sql
1 DROP SCHEMA action CASCADE;
2
3 BEGIN;
4
5 CREATE SCHEMA action;
6
7 CREATE TABLE action.survey (
8         id              SERIAL  PRIMARY KEY,
9         owner           INT     NOT NULL REFERENCES actor.org_unit (id),
10         name            TEXT    NOT NULL,
11         description     TEXT    NOT NULL,
12         start_date      DATE    NOT NULL DEFAULT NOW(),
13         end_date        DATE    NOT NULL DEFAULT NOW() + '10 years'::INTERVAL,
14         usr_summary     BOOL    NOT NULL DEFAULT FALSE,
15         opac            BOOL    NOT NULL DEFAULT FALSE,
16         poll            BOOL    NOT NULL DEFAULT FALSE,
17         required        BOOL    NOT NULL DEFAULT FALSE
18 );
19 CREATE UNIQUE INDEX asv_once_per_owner_idx ON action.survey (owner,name);
20
21 CREATE TABLE action.survey_question (
22         id              SERIAL  PRIMARY KEY,
23         survey          INT     NOT NULL REFERENCES action.survey,
24         question        TEXT    NOT NULL
25 );
26
27 CREATE TABLE action.survey_answer (
28         id              SERIAL  PRIMARY KEY,
29         question        INT     NOT NULL REFERENCES action.survey_question,
30         answer          TEXT    NOT NULL
31 );
32
33 CREATE SEQUENCE action.survey_response_group_id_seq;
34
35 CREATE TABLE action.survey_response (
36         id              BIGSERIAL       PRIMARY KEY,
37         response_group_id       INT,
38         usr             INT, -- REFERENCES actor.usr
39         survey          INT             NOT NULL REFERENCES action.survey,
40         question        INT             NOT NULL REFERENCES action.survey_question,
41         answer          INT             NOT NULL REFERENCES action.survey_answer,
42         answer_date     TIMESTAMP WITH TIME ZONE,
43         effective_date  TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
44 );
45 CREATE OR REPLACE FUNCTION action.survey_response_answer_date_fixup () RETURNS TRIGGER AS '
46 BEGIN
47         NEW.answer_date := NOW();
48         RETURN NEW;
49 END;
50 ' LANGUAGE 'plpgsql';
51 CREATE TRIGGER action_survey_response_answer_date_fixup_tgr
52         BEFORE INSERT ON action.survey_response
53         FOR EACH ROW
54         EXECUTE PROCEDURE action.survey_response_answer_date_fixup ();
55
56
57 CREATE TABLE action.circulation (
58         target_copy             BIGINT          NOT NULL, -- asset.copy.id
59         circ_lib                INT             NOT NULL, -- actor.org_unit.id
60         duration_rule           TEXT            NOT NULL, -- name of "circ duration" rule
61         duration                INTERVAL        NOT NULL, -- derived from "circ duration" rule
62         renewal_remaining       INT             NOT NULL, -- derived from "circ duration" rule
63         recuring_fine_rule      TEXT            NOT NULL, -- name of "circ fine" rule
64         recuring_fine           NUMERIC(6,2)    NOT NULL, -- derived from "circ fine" rule
65         max_fine_rule           TEXT            NOT NULL, -- name of "max fine" rule
66         max_fine                NUMERIC(6,2)    NOT NULL, -- derived from "max fine" rule
67         fine_interval           INTERVAL        NOT NULL DEFAULT '1 day'::INTERVAL, -- derived from "circ fine" rule
68         stop_fines              TEXT            CHECK (stop_fines IN ('CHECKIN','CLAIMSRETURNED','LOST','MAXFINES'))
69 ) INHERITS (money.billable_xact);
70 CREATE INDEX circ_open_xacts_idx ON action.circulation (usr) WHERE xact_finish IS NULL;
71
72
73 COMMIT;
74