From b405cadf2288b72ad184163fad50ab0277cfc031 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 18 Aug 2022 13:25:17 +0200 Subject: [PATCH] Migrate protocol names from linked protocols in inventory if empty [SCI-7110] --- ...pty_protocol_names_for_linked_task_protocols.rb | 14 ++++++++++++++ db/structure.sql | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220818094636_fill_empty_protocol_names_for_linked_task_protocols.rb diff --git a/db/migrate/20220818094636_fill_empty_protocol_names_for_linked_task_protocols.rb b/db/migrate/20220818094636_fill_empty_protocol_names_for_linked_task_protocols.rb new file mode 100644 index 000000000..22c62fc66 --- /dev/null +++ b/db/migrate/20220818094636_fill_empty_protocol_names_for_linked_task_protocols.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class FillEmptyProtocolNamesForLinkedTaskProtocols < ActiveRecord::Migration[6.1] + def up + execute( + "UPDATE protocols " \ + "SET name = parent_protocols.name "\ + "FROM protocols parent_protocols "\ + "WHERE \"parent_protocols\".\"id\" = \"protocols\".\"parent_id\" "\ + "AND \"protocols\".\"protocol_type\" = #{Protocol.protocol_types['linked']} "\ + "AND \"protocols\".\"name\" IS NULL;" + ) + end +end diff --git a/db/structure.sql b/db/structure.sql index ea7f62b76..68cfef0c4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -8516,6 +8516,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220429083335'), ('20220530144300'), ('20220602120714'), -('20220705091621'); +('20220705091621'), +('20220818094636');