PR for #3 #17
@@ -1,6 +1,12 @@
|
||||
drop trigger generate_version_number_trigger on article;
|
||||
drop table article;
|
||||
drop function generate_version_number(regclass, uuid);
|
||||
drop function set_version_number();
|
||||
drop trigger generate_version_number_trigger on constitution;
|
||||
drop table constitution;
|
||||
-- Article & Contitution
|
||||
drop trigger if exists set_constitution_link_trigger on article_on_title;
|
||||
drop table if exists article_in_title;
|
||||
drop table if exists title;
|
||||
drop function if exists set_constitution_link();
|
||||
|
||||
drop trigger if exists generate_version_number_trigger on article;
|
||||
drop table if exists article;
|
||||
drop function if exists generate_version_number(regclass, uuid);
|
||||
drop trigger if exists generate_version_number_trigger on constitution;
|
||||
drop table if exists constitution;
|
||||
drop function if exists set_version_number();
|
||||
|
||||
@@ -16,7 +16,7 @@ $$;
|
||||
|
||||
create table article
|
||||
(
|
||||
id uuid default uuid_generate_v4() not null,
|
||||
id uuid default uuid_generate_v4() not null primary key,
|
||||
created_at timestamptz default now() not null,
|
||||
version_id uuid default uuid_generate_v4() not null,
|
||||
version_number int not null,
|
||||
@@ -34,7 +34,7 @@ EXECUTE PROCEDURE set_version_number();
|
||||
|
||||
create table constitution
|
||||
(
|
||||
id uuid default uuid_generate_v4() not null,
|
||||
id uuid default uuid_generate_v4() not null primary key,
|
||||
created_at timestamptz default now() not null,
|
||||
version_id uuid default uuid_generate_v4() not null,
|
||||
version_number int not null,
|
||||
@@ -46,3 +46,39 @@ CREATE TRIGGER generate_version_number_trigger
|
||||
BEFORE INSERT
|
||||
ON constitution
|
||||
EXECUTE PROCEDURE set_version_number();
|
||||
|
||||
create table title
|
||||
(
|
||||
id uuid default uuid_generate_v4() not null primary key,
|
||||
created_at timestamptz default now() not null,
|
||||
name text not null,
|
||||
rank int not null,
|
||||
constitution_id uuid not null references constitution (id)
|
||||
);
|
||||
|
||||
create table article_in_title
|
||||
(
|
||||
id uuid default uuid_generate_v4() not null primary key,
|
||||
created_at timestamptz default now() not null,
|
||||
rank int not null,
|
||||
title_id uuid not null references title (id),
|
||||
article_id uuid not null references article (id),
|
||||
constitution_id uuid not null references constitution (id)
|
||||
);
|
||||
|
||||
create or replace function set_constitution_link() returns trigger
|
||||
language plpgsql as
|
||||
$$
|
||||
begin
|
||||
new.constitution_id = (
|
||||
select t.constitution_id
|
||||
from title as t
|
||||
where t.id = new.title_id
|
||||
);
|
||||
end;
|
||||
$$;
|
||||
|
||||
CREATE TRIGGER set_constitution_link_trigger
|
||||
BEFORE INSERT
|
||||
ON article_in_title
|
||||
EXECUTE PROCEDURE set_constitution_link();
|
||||
Reference in New Issue
Block a user