diff --git a/migrations/000108_create_voucher_tables.up.sql b/migrations/000108_create_voucher_tables.up.sql index 4590178..27c23e4 100644 --- a/migrations/000108_create_voucher_tables.up.sql +++ b/migrations/000108_create_voucher_tables.up.sql @@ -2,6 +2,21 @@ -- which budget (docs/rfc-enakgame.md ยง5.7, D5). Replaces the unused rewards table for -- EnakGame; rewards itself stays. +-- Some databases still have the vouchers table of the reverted Voucher Undian feature +-- (commit cfe690a). Keep its data under another name; its primary key index is renamed +-- too, or vouchers_pkey below would clash. +DO $$ +BEGIN + IF EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = current_schema() AND table_name = 'vouchers' AND column_name = 'winner_number' + ) THEN + ALTER TABLE vouchers RENAME TO vouchers_undian_legacy; + ALTER INDEX IF EXISTS vouchers_pkey RENAME TO vouchers_undian_legacy_pkey; + ALTER INDEX IF EXISTS vouchers_voucher_code_key RENAME TO vouchers_undian_legacy_voucher_code_key; + END IF; +END $$; + CREATE TABLE vouchers ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), organization_id UUID NOT NULL,