Split Entities for remove nullable variables

This commit is contained in:
2020-01-28 11:08:43 +01:00
parent 3cdd1f3a46
commit 813d6857e9
52 changed files with 569 additions and 287 deletions

View File

@@ -17,20 +17,18 @@ begin
now() + (row_number() over () * interval '7 minute 3 second')
from citizen z;
insert into title (id, created_by_id, name, rank, constitution_id)
insert into title (id, name, rank, constitution_id)
select
uuid_in(md5('constitution_title'||row_number() over ())::cstring),
c.created_by_id,
'name' || row_number() over (),
row_number() over (),
c.id
from constitution c,
lateral generate_series(1, 5) g;
insert into article_in_title (id, created_by_id, rank, title_id, article_id, constitution_id)
insert into article_in_title (id, rank, title_id, article_id, constitution_id)
select
uuid_in(md5('article_in_title'||row_number() over ())::cstring),
ti.created_by_id,
row_number() over (),
ti.id,
a.id,

View File

@@ -6,7 +6,8 @@ begin
select to_json(t) into resource
from (
select
z.*
z.*,
find_user_by_id(z.user_id) as "user"
from citizen as z
where z.id = _id
) as t;

View File

@@ -7,9 +7,8 @@ begin
from (
select
z.*,
u as "user"
find_user_by_id(z.user_id) as "user"
from citizen as z
join "user" u on z.user_id = u.id
where z.id = _id
) as t;
end;

View File

@@ -13,7 +13,8 @@ begin
into resource, total
from (
select
z.*
z.*,
json_build_object('id', z.user_id) as "user"
from citizen as z
where "search" is null or (
(name->'first_name')::text ilike '%'||"search"||'%' or

View File

@@ -4,12 +4,10 @@ $$
declare
_title alias for title;
_constitution_id uuid = coalesce(constitution_id, (title#>>'{constitution_id}')::uuid);
_author_id uuid = (title#>>'{created_by, id}')::uuid;
new_id uuid;
begin
insert into title (created_by_id, name, rank, constitution_id)
insert into title (name, rank, constitution_id)
select
_author_id,
ti.name,
row_number() OVER (),
_constitution_id
@@ -17,9 +15,8 @@ begin
returning id into new_id;
if (_title->'articles' is not null) then
insert into article_in_title (created_by_id, rank, title_id, article_id, constitution_id)
insert into article_in_title (rank, title_id, article_id, constitution_id)
select
_author_id,
row_number() over (),
new_id,
id,

View File

@@ -46,10 +46,6 @@ begin
titles := (resource->>'titles');
for _title in select json_array_elements(titles) loop
if _title#>>'{created_by, id}' is null then
_title := jsonb_set(_title::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
end if;
perform create_title_in_constitution(_title, new_id);
end loop;

View File

@@ -274,7 +274,6 @@ create table title
(
id uuid default uuid_generate_v4() not null primary key,
created_at timestamptz default now() not null,
created_by_id uuid not null references citizen (id),
name text not null check ( name != '' ),
rank int not null check ( rank >= 0 ),
constitution_id uuid not null references constitution (id)
@@ -284,7 +283,6 @@ create table article_in_title
(
id uuid default uuid_generate_v4() not null primary key,
created_at timestamptz default now() not null,
created_by_id uuid not null references citizen (id),
rank int not null check ( rank >= 0 ),
title_id uuid not null references title (id),
article_id uuid not null references article (id),