68 lines
3.6 KiB
SQL
68 lines
3.6 KiB
SQL
-- create table for categories
|
|
create table candymat_data.category
|
|
(
|
|
row_id serial primary key,
|
|
title character varying(300) UNIQUE NOT NULL check ( title <> '' ),
|
|
description character varying(15000)
|
|
);
|
|
grant select on table candymat_data.category to candymat_person;
|
|
-- the following line is only necessary as long as the candymat should be publicly accessible
|
|
grant select on table candymat_data.category to candymat_anonymous;
|
|
grant insert, update, delete on table candymat_data.category to candymat_editor;
|
|
grant usage on sequence candymat_data.category_row_id_seq to candymat_editor;
|
|
|
|
-- create table for questions
|
|
create table candymat_data.question
|
|
(
|
|
row_id serial primary key,
|
|
category_row_id integer REFERENCES candymat_data.category (row_id) ON UPDATE CASCADE ON DELETE SET NULL,
|
|
title character varying(3000) UNIQUE NOT NULL check ( title <> '' ),
|
|
description character varying(15000)
|
|
);
|
|
grant select on table candymat_data.question to candymat_person;
|
|
-- the following line is only necessary as long as the candymat should be publicly accessible
|
|
grant select on table candymat_data.question to candymat_anonymous;
|
|
grant insert, update, delete on table candymat_data.question to candymat_editor;
|
|
grant usage on sequence candymat_data.question_row_id_seq to candymat_editor;
|
|
|
|
-- create table for answers
|
|
create table candymat_data.answer
|
|
(
|
|
question_row_id integer REFERENCES candymat_data.question (row_id) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
person_row_id integer REFERENCES candymat_data.person (row_id) ON UPDATE CASCADE ON DELETE CASCADE,
|
|
position integer NOT NULL check (position between 0 and 3),
|
|
text character varying(15000),
|
|
created_at timestamp default now(),
|
|
primary key (question_row_id, person_row_id)
|
|
);
|
|
grant select on table candymat_data.answer to candymat_person;
|
|
-- the following line is only necessary as long as the candymat should be publicly accessible
|
|
grant select on table candymat_data.answer to candymat_anonymous;
|
|
grant insert, update, delete on table candymat_data.answer to candymat_candidate;
|
|
|
|
alter table candymat_data.answer
|
|
enable row level security;
|
|
create policy change_answer on candymat_data.answer to candymat_candidate
|
|
using (person_row_id = nullif(current_setting('jwt.claims.person_row_id', true), '')::integer);
|
|
create policy select_answer
|
|
on candymat_data.answer
|
|
for select
|
|
to candymat_anonymous, candymat_person -- maybe change to candymat_person only in the future
|
|
using (true);
|
|
|
|
drop table if exists candymat_data.user_app_info;
|
|
create table candymat_data.user_app_info
|
|
(
|
|
row_id character varying(50) primary key,
|
|
title character varying(300) NOT NULL,
|
|
content character varying(15000)
|
|
);
|
|
grant select on table candymat_data.user_app_info to candymat_anonymous, candymat_person;
|
|
grant insert, update, delete on table candymat_data.user_app_info to candymat_editor;
|
|
delete from candymat_data.user_app_info where row_id = 'about_page';
|
|
delete from candymat_data.user_app_info where row_id = 'legal_page';
|
|
insert into candymat_data.user_app_info (row_id, title, content) values
|
|
('about_page', 'About Candymat', '<h1>Wer steckt eigentlich hinter dem Kandimat?</h1><p>Der Kandimat wurde von den ehrenamtlichen Mitgliedern des Netzbegrünung e.V. entwickelt. Eure Geschäftsstelle und die Kandidat*innen haben die redaktionelle Arbeit für die Inhalte des Kandimats geleistet.</p>');
|
|
insert into candymat_data.user_app_info (row_id, title, content) values
|
|
('legal_page', 'Legal Candymat', '<h1>Impressum</h1><p>Impressum Infos</p>');
|