fix migration with function upsert_article
This commit is contained in:
@@ -141,7 +141,7 @@ paths:
|
|||||||
$ref: '#/components/schemas/ArticleResponse'
|
$ref: '#/components/schemas/ArticleResponse'
|
||||||
/articles/{article}:
|
/articles/{article}:
|
||||||
get:
|
get:
|
||||||
summary: Get all articles
|
summary: Get one article
|
||||||
tags:
|
tags:
|
||||||
- article
|
- article
|
||||||
operationId: getArticle
|
operationId: getArticle
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ $$
|
|||||||
declare
|
declare
|
||||||
new_id uuid;
|
new_id uuid;
|
||||||
_id_exist boolean;
|
_id_exist boolean;
|
||||||
_existing_draft article = (
|
_existing_draft_id uuid = (
|
||||||
select a from article a
|
select a.id from article a
|
||||||
where a.version_id = (resource->>'version_id')::uuid
|
where a.version_id = (resource->>'version_id')::uuid
|
||||||
and a.draft = true
|
and a.draft = true
|
||||||
);
|
);
|
||||||
@@ -17,7 +17,7 @@ begin
|
|||||||
where (resource->>'id')::uuid is not null
|
where (resource->>'id')::uuid is not null
|
||||||
and id = (resource->>'id')::uuid;
|
and id = (resource->>'id')::uuid;
|
||||||
|
|
||||||
if (_existing_draft.id is not null) then
|
if (_existing_draft_id is not null) then
|
||||||
update article a2 set
|
update article a2 set
|
||||||
title = a.title,
|
title = a.title,
|
||||||
anonymous = a.anonymous,
|
anonymous = a.anonymous,
|
||||||
@@ -26,7 +26,7 @@ begin
|
|||||||
tags = a.tags,
|
tags = a.tags,
|
||||||
draft = a.draft
|
draft = a.draft
|
||||||
from json_populate_record(null::article, resource) a
|
from json_populate_record(null::article, resource) a
|
||||||
where a2.id = (_existing_draft.id)::uuid
|
where a2.id = (_existing_draft_id)::uuid
|
||||||
returning a2.id into new_id;
|
returning a2.id into new_id;
|
||||||
else
|
else
|
||||||
insert into article (id, version_id, created_by_id, title, anonymous, content, description, tags, draft)
|
insert into article (id, version_id, created_by_id, title, anonymous, content, description, tags, draft)
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ declare
|
|||||||
_citizen_id uuid = (resource#>>'{created_by, id}')::uuid;
|
_citizen_id uuid = (resource#>>'{created_by, id}')::uuid;
|
||||||
new_id uuid;
|
new_id uuid;
|
||||||
_id_exist boolean;
|
_id_exist boolean;
|
||||||
_existing_draft constitution = (
|
_existing_draft_id uuid = (
|
||||||
select c from constitution c
|
select c.id from constitution c
|
||||||
where c.version_id = (resource->>'version_id')::uuid
|
where c.version_id = (resource->>'version_id')::uuid
|
||||||
and c.draft = true
|
and c.draft = true
|
||||||
);
|
);
|
||||||
@@ -20,14 +20,14 @@ begin
|
|||||||
where (resource->>'id')::uuid is not null
|
where (resource->>'id')::uuid is not null
|
||||||
and id = (resource->>'id')::uuid;
|
and id = (resource->>'id')::uuid;
|
||||||
|
|
||||||
if (_existing_draft.id is not null) then
|
if (_existing_draft_id is not null) then
|
||||||
update constitution c2 set
|
update constitution c2 set
|
||||||
title = c.title,
|
title = c.title,
|
||||||
anonymous = c.anonymous,
|
anonymous = c.anonymous,
|
||||||
intro = c.intro,
|
intro = c.intro,
|
||||||
draft = c.draft
|
draft = c.draft
|
||||||
from json_populate_record(null::constitution, resource) c
|
from json_populate_record(null::constitution, resource) c
|
||||||
where c2.id = (_existing_draft.id)::uuid
|
where c2.id = (_existing_draft_id)::uuid
|
||||||
returning c2.id into new_id;
|
returning c2.id into new_id;
|
||||||
else
|
else
|
||||||
insert into constitution (id, version_id, created_by_id, title, intro, anonymous)
|
insert into constitution (id, version_id, created_by_id, title, intro, anonymous)
|
||||||
|
|||||||
Reference in New Issue
Block a user