From c61cf1360d9cef60f59a0c934b47a21051322607 Mon Sep 17 00:00:00 2001 From: Piotr Heilman Date: Tue, 3 Dec 2024 13:29:08 +0100 Subject: [PATCH] Fix down migration 16. --- schemas/database/016_remove_recovery.down.sql | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/schemas/database/016_remove_recovery.down.sql b/schemas/database/016_remove_recovery.down.sql index db41d4f2..2cb1137c 100644 --- a/schemas/database/016_remove_recovery.down.sql +++ b/schemas/database/016_remove_recovery.down.sql @@ -3,13 +3,24 @@ CREATE TABLE recoveries ( new_commitment BYTEA NOT NULL UNIQUE ); +-- It may look strange but this way we restore the order of columns. The order is important +-- as we use 'SELECT * FROM' in application code and then get data based on that order. +ALTER TABLE unprocessed_identities + RENAME COLUMN created_at TO created_at_old; + ALTER TABLE unprocessed_identities - ADD COLUMN eligibility TIMESTAMPTZ, ADD COLUMN status VARCHAR(50), + ADD COLUMN created_at TIMESTAMPTZ, ADD COLUMN processed_at TIMESTAMPTZ, - ADD COLUMN error_message TEXT; + ADD COLUMN error_message TEXT, + ADD COLUMN eligibility TIMESTAMPTZ; +UPDATE unprocessed_identities SET created_at = created_at_old; UPDATE unprocessed_identities SET status = 'new', eligibility = CURRENT_TIMESTAMP WHERE status IS NULL; +ALTER TABLE unprocessed_identities + ALTER COLUMN created_at SET NOT NULL; ALTER TABLE unprocessed_identities ALTER COLUMN status SET NOT NULL; +ALTER TABLE unprocessed_identities + DROP COLUMN created_at_old;