🗃️ Add subscription interval enum (#1568)

This commit is contained in:
Luke Vella 2025-02-21 11:52:07 +00:00 committed by GitHub
parent 0e964ee168
commit 5e356afab6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 8 deletions

View file

@ -0,0 +1,22 @@
-- Create the enum type
CREATE TYPE subscription_interval AS ENUM ('day', 'week', 'month', 'year');
-- Add the new column
ALTER TABLE subscriptions ADD COLUMN interval_enum subscription_interval;
-- Populate the new column
UPDATE subscriptions
SET interval_enum = CASE
WHEN interval = 'month' THEN 'month'::subscription_interval
WHEN interval = 'year' THEN 'year'::subscription_interval
ELSE NULL
END;
-- Make the new column required
ALTER TABLE subscriptions ALTER COLUMN interval_enum SET NOT NULL;
-- Drop the old column
ALTER TABLE subscriptions DROP COLUMN interval;
-- Rename the new column to interval
ALTER TABLE subscriptions RENAME COLUMN interval_enum TO interval;