Skip to content

Commit b7b9b7d

Browse files
committed
conditional INSERT of dataset type #10517
1 parent 373005a commit b7b9b7d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/resources/db/migration/V6.3.0.3.sql

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
-- Dataset types have been added. See #10517 and #10694
22
--
3-
-- Insert the default dataset type: dataset.
4-
INSERT INTO datasettype (name) VALUES ('dataset');
3+
-- Insert the default dataset type: dataset (if not present).
4+
-- Inspired by https://stackoverflow.com/questions/4069718/postgres-insert-if-does-not-exist-already/13342031#13342031
5+
INSERT INTO datasettype
6+
(name)
7+
SELECT 'dataset'
8+
WHERE
9+
NOT EXISTS (
10+
SELECT name FROM datasettype WHERE name = 'dataset'
11+
);
512
--
613
-- Add the new column (if it doesn't exist).
714
ALTER TABLE dataset ADD COLUMN IF NOT EXISTS datasettype_id bigint;

0 commit comments

Comments
 (0)