cms/apps/polls/dblayout.sql
BEGIN;
CREATE TABLE polls (
id serial PRIMARY KEY,
label varchar(20) NOT NULL, -- used by the template and possibly by the URL
release_date timestamp with time zone NOT NULL,
expire_date timestamp with time zone NOT NULL,
question varchar(255) NOT NULL
);
CREATE INDEX polls_label ON polls (label);
CREATE TABLE poll_choices (
id serial PRIMARY KEY,
polls_id integer REFERENCES polls(id),
choice varchar(255) NOT NULL,
votes integer NOT NULL DEFAULT 0
);
CREATE TABLE poll_logged_votes (
poll_id integer NOT NULL REFERENCES polls(id),
choice_id integer NOT NULL REFERENCES poll_choices(id),
ip_address inet NOT NULL,
vote_time timestamp with time zone NOT NULL,
PRIMARY KEY (poll_id, ip_address, vote_time)
);
CREATE TABLE polls_sites (
polls_id integer NOT NULL REFERENCES polls(id),
sites_id integer NOT NULL REFERENCES sites(id),
PRIMARY KEY (polls_id, sites_id)
);
COMMIT;