PR for #3 #17
6
.idea/codeStyles/Project.xml
generated
6
.idea/codeStyles/Project.xml
generated
@@ -3,6 +3,12 @@
|
|||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
|
<PostgresCodeStyleSettings version="2">
|
||||||
|
<option name="ALIAS_CASE" value="1" />
|
||||||
|
<option name="KEYWORD_CASE" value="1" />
|
||||||
|
<option name="TYPE_CASE" value="1" />
|
||||||
|
<option name="IDENTIFIER_CASE" value="1" />
|
||||||
|
</PostgresCodeStyleSettings>
|
||||||
<codeStyleSettings language="kotlin">
|
<codeStyleSettings language="kotlin">
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
|
|||||||
@@ -1,3 +1,21 @@
|
|||||||
|
-- Extra resources
|
||||||
|
drop table if exists follow_article;
|
||||||
|
drop table if exists follow_constitution;
|
||||||
|
drop table if exists follow_citizen;
|
||||||
|
drop table if exists follow;
|
||||||
|
|
||||||
|
drop table if exists vote_for_article;
|
||||||
|
drop table if exists vote_for_constitution;
|
||||||
|
drop table if exists vote_for_comment_on_article;
|
||||||
|
drop table if exists vote_for_comment_on_constitution;
|
||||||
|
drop table if exists vote;
|
||||||
|
|
||||||
|
drop table if exists comment_on_article;
|
||||||
|
drop table if exists comment_on_constitution;
|
||||||
|
drop table if exists comment;
|
||||||
|
|
||||||
|
drop table if exists extra;
|
||||||
|
|
||||||
-- Article & Contitution
|
-- Article & Contitution
|
||||||
drop table if exists article_relations;
|
drop table if exists article_relations;
|
||||||
drop trigger if exists set_constitution_link_trigger on article_on_title;
|
drop trigger if exists set_constitution_link_trigger on article_on_title;
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
-- Users
|
-- Users
|
||||||
|
create extension if not exists pgcrypto;
|
||||||
|
-- select *
|
||||||
|
-- from "user"
|
||||||
|
-- where username = lower('nick@example.com')
|
||||||
|
-- and password = crypt('12346', password);
|
||||||
|
|
||||||
create table "user"
|
create table "user"
|
||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
updated_at timestamptz default now() not null,
|
updated_at timestamptz default now() not null check ( updated_at >= created_at ),
|
||||||
blocked_at timestamptz default null null,
|
blocked_at timestamptz default null null,
|
||||||
username varchar(64) not null,
|
username varchar(64) not null check ( username != '' and lower(username) = username) unique,
|
||||||
password varchar(258) not null
|
password text not null check ( password != '' )
|
||||||
);
|
);
|
||||||
|
|
||||||
create type "name" as (
|
create type "name" as (
|
||||||
@@ -18,21 +23,23 @@ create type "name" as (
|
|||||||
|
|
||||||
create table citizen
|
create table citizen
|
||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
name "name" not null,
|
name "name" not null check ( name != '' ),
|
||||||
birthday date not null,
|
birthday date not null,
|
||||||
user_id uuid not null references "user" (id)
|
user_id uuid not null references "user" (id),
|
||||||
|
vote_annonymous boolean default true not null,
|
||||||
|
follow_annonymous boolean default true not null
|
||||||
);
|
);
|
||||||
|
|
||||||
create table workgroup
|
create table workgroup
|
||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
updated_at timestamptz default now() not null,
|
updated_at timestamptz default now() not null check ( updated_at >= created_at ),
|
||||||
created_by_id uuid not null references "user" (id),
|
created_by_id uuid not null references citizen (id),
|
||||||
name varchar(128) not null,
|
name varchar(128) not null,
|
||||||
description text not null,
|
description text null,
|
||||||
annonymous boolean default false not null,
|
annonymous boolean default false not null,
|
||||||
logo text null,
|
logo text null,
|
||||||
owner_id uuid not null references citizen (id)
|
owner_id uuid not null references citizen (id)
|
||||||
@@ -50,7 +57,7 @@ create table moderator
|
|||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
updated_at timestamptz default now() not null,
|
updated_at timestamptz default now() not null check ( updated_at >= created_at ),
|
||||||
assigned_period tstzrange[] default '{}' not null,
|
assigned_period tstzrange[] default '{}' not null,
|
||||||
user_id uuid not null references "user" (id)
|
user_id uuid not null references "user" (id)
|
||||||
);
|
);
|
||||||
@@ -69,7 +76,7 @@ create or replace function set_version_number() returns trigger
|
|||||||
language plpgsql as
|
language plpgsql as
|
||||||
$$
|
$$
|
||||||
begin
|
begin
|
||||||
new.version_number = generate_version_number(TG_TABLE_NAME::regclass, new.version_id);
|
new.version_number = generate_version_number(tg_table_name::regclass, new.version_id);
|
||||||
end;
|
end;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
@@ -77,43 +84,43 @@ create table article
|
|||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
created_by_id uuid not null references "user" (id),
|
created_by_id uuid not null references citizen (id),
|
||||||
version_id uuid default uuid_generate_v4() not null,
|
version_id uuid default uuid_generate_v4() not null,
|
||||||
version_number int not null,
|
version_number int not null unique,
|
||||||
title text not null,
|
title text not null,
|
||||||
annonymous boolean default false not null,
|
annonymous boolean default false not null,
|
||||||
content text not null,
|
content text not null check ( content != '' ),
|
||||||
description text,
|
description text,
|
||||||
tags varchar(32)[] default '{}' not null
|
tags varchar(32)[] default '{}' not null
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TRIGGER generate_version_number_trigger
|
create trigger generate_version_number_trigger
|
||||||
BEFORE INSERT
|
before insert
|
||||||
ON article
|
on article
|
||||||
EXECUTE PROCEDURE set_version_number();
|
execute procedure set_version_number();
|
||||||
|
|
||||||
create table constitution
|
create table constitution
|
||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
created_by_id uuid not null references "user" (id),
|
created_by_id uuid not null references citizen (id),
|
||||||
version_id uuid default uuid_generate_v4() not null,
|
version_id uuid default uuid_generate_v4() not null,
|
||||||
version_number int not null,
|
version_number int not null,
|
||||||
title text not null,
|
title text not null,
|
||||||
annonymous boolean default false not null
|
annonymous boolean default false not null
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TRIGGER generate_version_number_trigger
|
create trigger generate_version_number_trigger
|
||||||
BEFORE INSERT
|
before insert
|
||||||
ON constitution
|
on constitution
|
||||||
EXECUTE PROCEDURE set_version_number();
|
execute procedure set_version_number();
|
||||||
|
|
||||||
create table title
|
create table title
|
||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
created_by_id uuid not null references "user" (id),
|
created_by_id uuid not null references citizen (id),
|
||||||
name text not null,
|
name text not null check ( name != '' ),
|
||||||
rank int not null,
|
rank int not null,
|
||||||
constitution_id uuid not null references constitution (id)
|
constitution_id uuid not null references constitution (id)
|
||||||
);
|
);
|
||||||
@@ -122,7 +129,7 @@ create table article_in_title
|
|||||||
(
|
(
|
||||||
id uuid default uuid_generate_v4() not null primary key,
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
created_at timestamptz default now() not null,
|
created_at timestamptz default now() not null,
|
||||||
created_by_id uuid not null references "user" (id),
|
created_by_id uuid not null references citizen (id),
|
||||||
rank int not null,
|
rank int not null,
|
||||||
title_id uuid not null references title (id),
|
title_id uuid not null references title (id),
|
||||||
article_id uuid not null references article (id),
|
article_id uuid not null references article (id),
|
||||||
@@ -141,16 +148,119 @@ begin
|
|||||||
end;
|
end;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
CREATE TRIGGER set_constitution_link_trigger
|
create trigger set_constitution_link_trigger
|
||||||
BEFORE INSERT
|
before insert
|
||||||
ON article_in_title
|
on article_in_title
|
||||||
EXECUTE PROCEDURE set_constitution_link();
|
execute procedure set_constitution_link();
|
||||||
|
|
||||||
create table article_relations
|
create table article_relations
|
||||||
(
|
(
|
||||||
source_id uuid references article,
|
source_id uuid references article,
|
||||||
target_id uuid references article check ( source_id != target_id ),
|
target_id uuid references article check ( source_id != target_id ),
|
||||||
created_at timestamptz default now(),
|
created_at timestamptz default now(),
|
||||||
created_by_id uuid not null references "user" (id),
|
created_by_id uuid not null references citizen (id),
|
||||||
primary key (source_id, target_id)
|
primary key (source_id, target_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Extra resources
|
||||||
|
|
||||||
|
create table extra
|
||||||
|
(
|
||||||
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
|
created_at timestamptz default now() not null,
|
||||||
|
citizen_id uuid not null references citizen (id),
|
||||||
|
target_id uuid not null,
|
||||||
|
target_reference regclass not null
|
||||||
|
);
|
||||||
|
|
||||||
|
create table follow
|
||||||
|
(
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (extra);
|
||||||
|
|
||||||
|
create table follow_article
|
||||||
|
(
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
foreign key (target_id) references article (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (follow);
|
||||||
|
|
||||||
|
create table follow_constitution
|
||||||
|
(
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
foreign key (target_id) references constitution (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (follow);
|
||||||
|
|
||||||
|
create table follow_citizen
|
||||||
|
(
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
foreign key (target_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (follow);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
create table comment
|
||||||
|
(
|
||||||
|
updated_at timestamptz default now() not null check ( updated_at >= created_at ),
|
||||||
|
"content" text not null check ( content != '' ),
|
||||||
|
parent_id uuid null references comment (id),
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (extra);
|
||||||
|
|
||||||
|
create table comment_on_article
|
||||||
|
(
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
foreign key (target_id) references article (id),
|
||||||
|
foreign key (parent_id) references comment_on_article (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (comment);
|
||||||
|
|
||||||
|
create table comment_on_constitution
|
||||||
|
(
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
foreign key (target_id) references constitution (id),
|
||||||
|
foreign key (parent_id) references comment_on_constitution (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (comment);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
create table vote
|
||||||
|
(
|
||||||
|
anonymous boolean default true not null,
|
||||||
|
note int not null check ( note >= -1 and note <= 1 ),
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (extra);
|
||||||
|
|
||||||
|
create table vote_for_article
|
||||||
|
(
|
||||||
|
foreign key (target_id) references article (id),
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (vote);
|
||||||
|
|
||||||
|
create table vote_for_constitution
|
||||||
|
(
|
||||||
|
foreign key (target_id) references constitution (id),
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (vote);
|
||||||
|
|
||||||
|
create table vote_for_comment_on_article
|
||||||
|
(
|
||||||
|
foreign key (target_id) references comment_on_article (id),
|
||||||
|
foreign key (citizen_id) references citizen (id),
|
||||||
|
primary key (id)
|
||||||
|
) inherits (vote);
|
||||||
|
|
||||||
|
create table vote_for_comment_on_constitution
|
||||||
|
(
|
||||||
|
primary key (id),
|
||||||
|
foreign key (target_id) references comment_on_constitution (id),
|
||||||
|
foreign key (target_id) references citizen (id)
|
||||||
|
) inherits (vote);
|
||||||
|
|||||||
Reference in New Issue
Block a user