Change migration of protocol templates - do not publish unlinked protocols [SCI-8062] (#5062)

This commit is contained in:
Alex Kriuchykhin 2023-03-03 10:24:14 +01:00 committed by GitHub
parent 8b1bc51950
commit 3a60a0aacd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 17 deletions

View file

@ -13,26 +13,38 @@ class AddProtocolVersioning < ActiveRecord::Migration[6.1]
t.references :published_by, index: true, foreign_key: { to_table: :users }
end
execute(
'UPDATE "protocols" SET "protocol_type" = 3, "archived" = TRUE WHERE "protocols"."protocol_type" = 4;'
)
execute(
'UPDATE "protocols" SET "visibility" = 1 WHERE "protocols"."protocol_type" = 3;'
)
execute(
'UPDATE "protocols" SET "protocol_type" = 2 ' \
'WHERE "id" IN (' \
'SELECT DISTINCT "protocols"."id" FROM "protocols" ' \
'JOIN "protocols" "linked_children" ON "linked_children"."parent_id" = "protocols"."id" ' \
'WHERE "protocols"."protocol_type" IN (2, 3)' \
');'
)
execute(
'UPDATE "protocols" SET "protocol_type" = 3 ' \
'WHERE "id" IN (' \
'SELECT DISTINCT "protocols"."id" FROM "protocols" ' \
'LEFT OUTER JOIN "protocols" "linked_children" ON "linked_children"."parent_id" = "protocols"."id" ' \
'WHERE "protocols"."protocol_type" IN (2, 3) AND "linked_children"."id" IS NULL' \
');'
)
execute(
'UPDATE "protocols" SET "published_on" = "created_at", "published_by_id" = "added_by_id" ' \
'WHERE "protocols"."protocol_type" IN (2, 4) ' \
'WHERE "protocols"."protocol_type" = 2 ' \
'AND "protocols"."published_on" IS NULL;'
)
execute(
'UPDATE "protocols" SET "published_by_id" = "added_by_id", "visibility" = 1 ' \
'WHERE "protocols"."protocol_type" = 3;'
)
execute(
'UPDATE "protocols" SET "archived" = TRUE WHERE "protocols"."protocol_type" = 4;'
)
execute(
'UPDATE "protocols" SET "protocol_type" = 2 WHERE "protocols"."protocol_type" IN (3, 4);'
)
end
def down
execute(
'UPDATE "protocols" SET "protocol_type" = 4 WHERE "protocols"."protocol_type" = 2 AND ' \
'UPDATE "protocols" SET "protocol_type" = 4 WHERE "protocols"."protocol_type" IN (2, 3, 4) AND ' \
'"protocols"."archived" = TRUE;'
)
change_table :protocols, bulk: true do |t|

View file

@ -1380,7 +1380,8 @@ CREATE TABLE public.protocols (
default_public_user_role_id bigint,
previous_version_id bigint,
last_modified_by_id bigint,
published_by_id bigint
published_by_id bigint,
linked_at timestamp without time zone
);
@ -5646,17 +5647,17 @@ CREATE INDEX index_protocols_on_parent_id ON public.protocols USING btree (paren
--
<<<<<<< HEAD
-- Name: index_protocols_on_previous_version_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_protocols_on_previous_version_id ON public.protocols USING btree (previous_version_id);
=======
--
-- Name: index_protocols_on_protocol_code; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_protocols_on_protocol_code ON public.protocols USING gin ((('PT'::text || id)) public.gin_trgm_ops);
>>>>>>> develop
--
@ -8683,6 +8684,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20221125133611'),
('20221222123021'),
('20230120141017'),
('20230206095817');
('20230206095817'),
('20230223142119'),
('20230227131215');