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