Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/main/resources/db/migration/V1.24.0__update_species_list.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

ALTER TABLE species
ADD CONSTRAINT unique_common_name UNIQUE (common_name);
Comment on lines +18 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check qa-test and rel-test for duplicates as well as production?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did, they don't have duplicates


DO $$
DECLARE
user_id UUID;
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', '', 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;
Comment on lines +29 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will this do if, for example, Hydrangea exists in the database but the others do not? Will it do a partial insert or just abort the whole statement? Might be better to do one insert per species.

There's a chance one or more of these species will be manually added to production before the next major release if there is an urgent need for it, so it would be best to account for that and assume that at least one of these species will already exist in the database.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I saw it's supposed to continue on if one fails and do the rest, I can test and make sure that's the case and change it if not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working as expected when Hydrangea exists in the database prior to the migration, all the rest are added.


END $$;