From 68acd3b075e632ad69da7c9e756121caef09f31c Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Wed, 18 Sep 2019 01:07:37 +0200 Subject: [PATCH] fix migration with function upsert_article --- src/main/resources/openApi.yaml | 2 +- .../resources/sql/functions/article/upsert_article.sql | 8 ++++---- .../sql/functions/constitution/upsert_constitution.sql | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/resources/openApi.yaml b/src/main/resources/openApi.yaml index fde5d8c..1017151 100644 --- a/src/main/resources/openApi.yaml +++ b/src/main/resources/openApi.yaml @@ -141,7 +141,7 @@ paths: $ref: '#/components/schemas/ArticleResponse' /articles/{article}: get: - summary: Get all articles + summary: Get one article tags: - article operationId: getArticle diff --git a/src/main/resources/sql/functions/article/upsert_article.sql b/src/main/resources/sql/functions/article/upsert_article.sql index e4db6ee..42e38f9 100644 --- a/src/main/resources/sql/functions/article/upsert_article.sql +++ b/src/main/resources/sql/functions/article/upsert_article.sql @@ -4,8 +4,8 @@ $$ declare new_id uuid; _id_exist boolean; - _existing_draft article = ( - select a from article a + _existing_draft_id uuid = ( + select a.id from article a where a.version_id = (resource->>'version_id')::uuid and a.draft = true ); @@ -17,7 +17,7 @@ begin where (resource->>'id')::uuid is not null 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 title = a.title, anonymous = a.anonymous, @@ -26,7 +26,7 @@ begin tags = a.tags, draft = a.draft 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; else insert into article (id, version_id, created_by_id, title, anonymous, content, description, tags, draft) diff --git a/src/main/resources/sql/functions/constitution/upsert_constitution.sql b/src/main/resources/sql/functions/constitution/upsert_constitution.sql index 0f21b5a..0c88219 100644 --- a/src/main/resources/sql/functions/constitution/upsert_constitution.sql +++ b/src/main/resources/sql/functions/constitution/upsert_constitution.sql @@ -7,8 +7,8 @@ declare _citizen_id uuid = (resource#>>'{created_by, id}')::uuid; new_id uuid; _id_exist boolean; - _existing_draft constitution = ( - select c from constitution c + _existing_draft_id uuid = ( + select c.id from constitution c where c.version_id = (resource->>'version_id')::uuid and c.draft = true ); @@ -20,14 +20,14 @@ begin where (resource->>'id')::uuid is not null 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 title = c.title, anonymous = c.anonymous, intro = c.intro, draft = c.draft 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; else insert into constitution (id, version_id, created_by_id, title, intro, anonymous)