changeset 5106:13fff84c2b70 queued-stage-done

Fix database migration
author Tom Gottfried <tom@intevation.de>
date Tue, 24 Mar 2020 19:14:06 +0100
parents 4e85cf143c4a
children b0d29f0aae3b
files schema/updates/1431/01.add_state.sql
diffstat 1 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/schema/updates/1431/01.add_state.sql	Tue Mar 24 18:23:24 2020 +0100
+++ b/schema/updates/1431/01.add_state.sql	Tue Mar 24 19:14:06 2020 +0100
@@ -1,1 +1,19 @@
-ALTER TYPE import_state ADD VALUE 'reviewed';
+-- DROP and re-CREATE type because adding a value isn't possible in transaction
+-- https://www.postgresql.org/docs/11/sql-altertype.html#id-1.9.3.42.7
+
+ALTER TABLE import.imports
+    ALTER COLUMN state DROP DEFAULT,
+    ALTER COLUMN state TYPE varchar;
+
+DROP TYPE import_state;
+
+CREATE TYPE import_state AS ENUM (
+    'queued',
+    'running',
+    'failed', 'unchanged', 'pending',
+    'accepted', 'declined', 'reviewed'
+);
+
+ALTER TABLE import.imports
+    ALTER COLUMN state TYPE import_state USING CAST(state AS import_state),
+    ALTER COLUMN state SET DEFAULT 'queued';