feature #3: create table user & citizen and add created_by column to other tables
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
-- Article & Contitution
|
-- Article & Contitution
|
||||||
|
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;
|
||||||
drop table if exists article_in_title;
|
drop table if exists article_in_title;
|
||||||
drop table if exists title;
|
drop table if exists title;
|
||||||
@@ -10,3 +11,11 @@ drop function if exists generate_version_number(regclass, uuid);
|
|||||||
drop trigger if exists generate_version_number_trigger on constitution;
|
drop trigger if exists generate_version_number_trigger on constitution;
|
||||||
drop table if exists constitution;
|
drop table if exists constitution;
|
||||||
drop function if exists set_version_number();
|
drop function if exists set_version_number();
|
||||||
|
|
||||||
|
-- User
|
||||||
|
drop table if exists moderator;
|
||||||
|
drop table if exists citizen_in_workgroup;
|
||||||
|
drop table if exists workgroup;
|
||||||
|
drop table if exists citizen;
|
||||||
|
drop table if exists "user";
|
||||||
|
drop type if exists public."name";
|
||||||
|
|||||||
@@ -1,3 +1,62 @@
|
|||||||
|
-- Users
|
||||||
|
|
||||||
|
create table "user"
|
||||||
|
(
|
||||||
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
|
created_at timestamptz default now() not null,
|
||||||
|
updated_at timestamptz default now() not null,
|
||||||
|
blocked_at timestamptz default null null,
|
||||||
|
username varchar(64) not null,
|
||||||
|
password varchar(258) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
create type "name" as (
|
||||||
|
first_name text,
|
||||||
|
last_name text,
|
||||||
|
civility text
|
||||||
|
);
|
||||||
|
|
||||||
|
create table citizen
|
||||||
|
(
|
||||||
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
|
created_at timestamptz default now() not null,
|
||||||
|
name "name" not null,
|
||||||
|
birthday date not null,
|
||||||
|
user_id uuid not null references "user" (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
create table workgroup
|
||||||
|
(
|
||||||
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
|
created_at timestamptz default now() not null,
|
||||||
|
updated_at timestamptz default now() not null,
|
||||||
|
created_by_id uuid not null references "user" (id),
|
||||||
|
name varchar(128) not null,
|
||||||
|
description text not null,
|
||||||
|
annonymous boolean default false not null,
|
||||||
|
logo text null,
|
||||||
|
owner_id uuid not null references citizen (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
create table citizen_in_workgroup
|
||||||
|
(
|
||||||
|
citizen_id uuid not null references citizen (id),
|
||||||
|
workgroup uuid not null references workgroup (id),
|
||||||
|
created_at timestamptz default now() not null,
|
||||||
|
primary key (citizen_id, workgroup)
|
||||||
|
);
|
||||||
|
|
||||||
|
create table moderator
|
||||||
|
(
|
||||||
|
id uuid default uuid_generate_v4() not null primary key,
|
||||||
|
created_at timestamptz default now() not null,
|
||||||
|
updated_at timestamptz default now() not null,
|
||||||
|
assigned_period tstzrange[] default '{}' not null,
|
||||||
|
user_id uuid not null references "user" (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Article & Contitution
|
||||||
|
|
||||||
create or replace function generate_version_number(tablename regclass, version_id uuid) returns int
|
create or replace function generate_version_number(tablename regclass, version_id uuid) returns int
|
||||||
language plpgsql as
|
language plpgsql as
|
||||||
$$
|
$$
|
||||||
@@ -18,6 +77,7 @@ 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),
|
||||||
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,
|
||||||
@@ -36,6 +96,7 @@ 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),
|
||||||
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,
|
||||||
@@ -51,6 +112,7 @@ 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),
|
||||||
name text not null,
|
name text not null,
|
||||||
rank int not null,
|
rank int not null,
|
||||||
constitution_id uuid not null references constitution (id)
|
constitution_id uuid not null references constitution (id)
|
||||||
@@ -60,6 +122,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),
|
||||||
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),
|
||||||
@@ -81,4 +144,13 @@ $$;
|
|||||||
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
|
||||||
|
(
|
||||||
|
source_id uuid references article,
|
||||||
|
target_id uuid references article check ( source_id != target_id ),
|
||||||
|
created_at timestamptz default now(),
|
||||||
|
created_by_id uuid not null references "user" (id),
|
||||||
|
primary key (source_id, target_id)
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user