From cf76edcd2b72344a603110c3b016dc742672a370 Mon Sep 17 00:00:00 2001 From: sh-agents <350651734+sh-agents@users.noreply.github.com> Date: Sun, 1 Nov 2026 15:27:04 +0000 Subject: [PATCH] store: add the drop_taken_codes migration --- .../StoreService/Store/Postgres/Migrations.hs | 26 ++++++++++++++++++- .../StoreService/Store/SQLite/Migrations.hs | 26 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs b/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs index 1f4166e33f..1bc4b1919c 100644 --- a/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs +++ b/apps/simplex-store-service/src/StoreService/Store/Postgres/Migrations.hs @@ -21,7 +21,8 @@ schemaMigrations = ("20260918_badge_group_ops", m20260918_badge_group_ops, Just down_m20260918_badge_group_ops), ("20260925_badge_store_receipts", m20260925_badge_store_receipts, Just down_m20260925_badge_store_receipts), ("20261012_badge_subscriptions", m20261012_badge_subscriptions, Just down_m20261012_badge_subscriptions), - ("20261013_names", m20261013_names, Just down_m20261013_names) + ("20261013_names", m20261013_names, Just down_m20261013_names), + ("20261022_drop_taken_codes", m20261022_drop_taken_codes, Just down_m20261022_drop_taken_codes) ] -- | The client tables share this database, so the service tables are the same names behind a prefix. @@ -450,6 +451,29 @@ DROP TABLE @name_registrations; DROP TABLE @name_prepaid_codes; |] +-- A code_issued order's worth went into its code, which stays a valid prepaid code, so it ends taken with nothing left. +m20261022_drop_taken_codes :: Text +m20261022_drop_taken_codes = + withPrefix + servicePrefix + [r| +UPDATE @name_registrations SET version = version + 1, phase = 'taken', price = 0, live = 0 WHERE phase = 'code_issued'; + +DROP INDEX @idx_name_registrations_issued_code; + +ALTER TABLE @name_registrations DROP COLUMN issued_code_id; +|] + +down_m20261022_drop_taken_codes :: Text +down_m20261022_drop_taken_codes = + withPrefix + servicePrefix + [r| +ALTER TABLE @name_registrations ADD COLUMN issued_code_id BIGINT REFERENCES @name_prepaid_codes; + +CREATE INDEX @idx_name_registrations_issued_code ON @name_registrations(issued_code_id); +|] + {- TODO [badges] deferred with the draft in M20260915_user_badges, service only. ALTER TABLE @payments ADD COLUMN receipt_hash BYTEA; diff --git a/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs b/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs index 600d625a61..895ca181c9 100644 --- a/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs +++ b/apps/simplex-store-service/src/StoreService/Store/SQLite/Migrations.hs @@ -22,7 +22,8 @@ schemaMigrations = ("20260918_badge_group_ops", m20260918_badge_group_ops, Just down_m20260918_badge_group_ops), ("20260925_badge_store_receipts", m20260925_badge_store_receipts, Just down_m20260925_badge_store_receipts), ("20261012_badge_subscriptions", m20261012_badge_subscriptions, Just down_m20261012_badge_subscriptions), - ("20261013_names", m20261013_names, Just down_m20261013_names) + ("20261013_names", m20261013_names, Just down_m20261013_names), + ("20261022_drop_taken_codes", m20261022_drop_taken_codes, Just down_m20261022_drop_taken_codes) ] -- | The client tables share this database, so the service tables are the same names behind a prefix. @@ -452,6 +453,29 @@ DROP TABLE @name_registrations; DROP TABLE @name_prepaid_codes; |] +-- A code_issued order's worth went into its code, which stays a valid prepaid code, so it ends taken with nothing left. +m20261022_drop_taken_codes :: Query +m20261022_drop_taken_codes = + withPrefix + servicePrefix + [sql| +UPDATE @name_registrations SET version = version + 1, phase = 'taken', price = 0, live = 0 WHERE phase = 'code_issued'; + +DROP INDEX @idx_name_registrations_issued_code; + +ALTER TABLE @name_registrations DROP COLUMN issued_code_id; +|] + +down_m20261022_drop_taken_codes :: Query +down_m20261022_drop_taken_codes = + withPrefix + servicePrefix + [sql| +ALTER TABLE @name_registrations ADD COLUMN issued_code_id INTEGER REFERENCES @name_prepaid_codes; + +CREATE INDEX @idx_name_registrations_issued_code ON @name_registrations(issued_code_id); +|] + {- TODO [badges] deferred with the draft in M20260915_user_badges, service only. ALTER TABLE @payments ADD COLUMN receipt_hash BLOB;