From 506ca6910bede824c299fdc75d48f9b588b379bf Mon Sep 17 00:00:00 2001 From: Nick <53413353+nickpalladino@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:12:38 -0400 Subject: [PATCH 1/4] Add initial migration with TODO placeholders --- .../V1.24.0__update_species_list.sql | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/resources/db/migration/V1.24.0__update_species_list.sql diff --git a/src/main/resources/db/migration/V1.24.0__update_species_list.sql b/src/main/resources/db/migration/V1.24.0__update_species_list.sql new file mode 100644 index 000000000..0a093621a --- /dev/null +++ b/src/main/resources/db/migration/V1.24.0__update_species_list.sql @@ -0,0 +1,37 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +DO $$ +DECLARE +user_id UUID; +BEGIN + +user_id := (SELECT id FROM bi_user WHERE name = 'system'); + +INSERT INTO species (common_name, description, created_by, updated_by) +VALUES + ('Hydrangea', 'TODO', user_id, user_id), + ('Red Clover', 'TODO', user_id, user_id), + ('Potato', 'TODO', user_id, user_id), + ('Blackberry', 'TODO', user_id, user_id), + ('Raspberry', 'TODO', user_id, user_id), + ('Sugar beet', 'TODO', user_id, user_id), + ('Strawberry', 'TODO', user_id, user_id), + ('Coffee', 'TODO', user_id, user_id), + ('Hop', 'TODO', user_id, user_id) ON CONFLICT DO NOTHING; + +END $$; From a7d4a5be8a4c632c2a11b7711e36861ef79e321f Mon Sep 17 00:00:00 2001 From: Nick <53413353+nickpalladino@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:16:18 -0400 Subject: [PATCH 2/4] Add unique name constraint --- .../resources/db/migration/V1.24.0__update_species_list.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/db/migration/V1.24.0__update_species_list.sql b/src/main/resources/db/migration/V1.24.0__update_species_list.sql index 0a093621a..aa5653427 100644 --- a/src/main/resources/db/migration/V1.24.0__update_species_list.sql +++ b/src/main/resources/db/migration/V1.24.0__update_species_list.sql @@ -22,6 +22,9 @@ BEGIN user_id := (SELECT id FROM bi_user WHERE name = 'system'); +ALTER TABLE species + ADD CONSTRAINT unique_common_name UNIQUE (common_name); + INSERT INTO species (common_name, description, created_by, updated_by) VALUES ('Hydrangea', 'TODO', user_id, user_id), From 21ff9ce6b1f5cde5e21293e42f11d7787c4e2200 Mon Sep 17 00:00:00 2001 From: Nick <53413353+nickpalladino@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:23:46 -0400 Subject: [PATCH 3/4] Move the constraint out of the script --- .../resources/db/migration/V1.24.0__update_species_list.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/db/migration/V1.24.0__update_species_list.sql b/src/main/resources/db/migration/V1.24.0__update_species_list.sql index aa5653427..796518004 100644 --- a/src/main/resources/db/migration/V1.24.0__update_species_list.sql +++ b/src/main/resources/db/migration/V1.24.0__update_species_list.sql @@ -15,6 +15,9 @@ * limitations under the License. */ +ALTER TABLE species + ADD CONSTRAINT unique_common_name UNIQUE (common_name); + DO $$ DECLARE user_id UUID; @@ -22,9 +25,6 @@ BEGIN user_id := (SELECT id FROM bi_user WHERE name = 'system'); -ALTER TABLE species - ADD CONSTRAINT unique_common_name UNIQUE (common_name); - INSERT INTO species (common_name, description, created_by, updated_by) VALUES ('Hydrangea', 'TODO', user_id, user_id), From db001ee838e4db87adcffdd00f34e8d8b7a78409 Mon Sep 17 00:00:00 2001 From: Nick <53413353+nickpalladino@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:40:43 -0400 Subject: [PATCH 4/4] Blank strings for descriptions --- .../V1.24.0__update_species_list.sql | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/resources/db/migration/V1.24.0__update_species_list.sql b/src/main/resources/db/migration/V1.24.0__update_species_list.sql index 796518004..c337815ab 100644 --- a/src/main/resources/db/migration/V1.24.0__update_species_list.sql +++ b/src/main/resources/db/migration/V1.24.0__update_species_list.sql @@ -25,16 +25,17 @@ BEGIN user_id := (SELECT id FROM bi_user WHERE name = 'system'); +-- just putting blank strings in for descriptions until later date, can update if needed INSERT INTO species (common_name, description, created_by, updated_by) VALUES - ('Hydrangea', 'TODO', user_id, user_id), - ('Red Clover', 'TODO', user_id, user_id), - ('Potato', 'TODO', user_id, user_id), - ('Blackberry', 'TODO', user_id, user_id), - ('Raspberry', 'TODO', user_id, user_id), - ('Sugar beet', 'TODO', user_id, user_id), - ('Strawberry', 'TODO', user_id, user_id), - ('Coffee', 'TODO', user_id, user_id), - ('Hop', 'TODO', user_id, user_id) ON CONFLICT DO NOTHING; + ('Hydrangea', '', user_id, user_id), + ('Red Clover', '', user_id, user_id), + ('Potato', '', user_id, user_id), + ('Blackberry', '', user_id, user_id), + ('Raspberry', '', user_id, user_id), + ('Sugar Beet', '', user_id, user_id), + ('Strawberry', '', user_id, user_id), + ('Coffee', '', user_id, user_id), + ('Hop', '', user_id, user_id) ON CONFLICT DO NOTHING; END $$;