From ef4f1625fba9258725523e61d8294e820fd816ba Mon Sep 17 00:00:00 2001 From: Kashif Date: Fri, 3 Jan 2025 14:21:50 +0530 Subject: [PATCH 1/2] chore: add migrations for Currency type in DB --- .../2025-01-03-084904_add_currencies/down.sql | 1 + migrations/2025-01-03-084904_add_currencies/up.sql | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 migrations/2025-01-03-084904_add_currencies/down.sql create mode 100644 migrations/2025-01-03-084904_add_currencies/up.sql diff --git a/migrations/2025-01-03-084904_add_currencies/down.sql b/migrations/2025-01-03-084904_add_currencies/down.sql new file mode 100644 index 000000000000..e0ac49d1ecfb --- /dev/null +++ b/migrations/2025-01-03-084904_add_currencies/down.sql @@ -0,0 +1 @@ +SELECT 1; diff --git a/migrations/2025-01-03-084904_add_currencies/up.sql b/migrations/2025-01-03-084904_add_currencies/up.sql new file mode 100644 index 000000000000..601772dfc345 --- /dev/null +++ b/migrations/2025-01-03-084904_add_currencies/up.sql @@ -0,0 +1,13 @@ +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'AFN'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'BTN'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'CDF'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ERN'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'IRR'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ISK'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'KPW'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'SDG'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'SYP'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'TJS'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'TMT'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ZMW'; +ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ZWL'; From 94d022804268c8b783174486c06d24565122e861 Mon Sep 17 00:00:00 2001 From: Kashif Date: Fri, 3 Jan 2025 14:54:47 +0530 Subject: [PATCH 2/2] chore: update migration query --- .../2025-01-03-084904_add_currencies/up.sql | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/migrations/2025-01-03-084904_add_currencies/up.sql b/migrations/2025-01-03-084904_add_currencies/up.sql index 601772dfc345..14167a32cfcb 100644 --- a/migrations/2025-01-03-084904_add_currencies/up.sql +++ b/migrations/2025-01-03-084904_add_currencies/up.sql @@ -1,13 +1,18 @@ -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'AFN'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'BTN'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'CDF'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ERN'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'IRR'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ISK'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'KPW'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'SDG'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'SYP'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'TJS'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'TMT'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ZMW'; -ALTER TYPE "Currency" ADD VALUE IF NOT EXISTS 'ZWL'; +DO $$ + DECLARE currency TEXT; + BEGIN + FOR currency IN + SELECT + unnest( + ARRAY ['AFN', 'BTN', 'CDF', 'ERN', 'IRR', 'ISK', 'KPW', 'SDG', 'SYP', 'TJS', 'TMT', 'ZWL'] + ) AS currency + LOOP + IF NOT EXISTS ( + SELECT 1 + FROM pg_enum + WHERE enumlabel = currency + AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'Currency') + ) THEN EXECUTE format('ALTER TYPE "Currency" ADD VALUE %L', currency); + END IF; + END LOOP; +END $$; \ No newline at end of file