mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-09 06:01:49 +02:00
🗃️ Add subscription interval enum (#1568)
This commit is contained in:
parent
0e964ee168
commit
5e356afab6
2 changed files with 40 additions and 8 deletions
|
@ -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;
|
|
@ -73,6 +73,15 @@ enum SubscriptionStatus {
|
||||||
@@map("subscription_status")
|
@@map("subscription_status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SubscriptionInterval {
|
||||||
|
day
|
||||||
|
week
|
||||||
|
month
|
||||||
|
year
|
||||||
|
|
||||||
|
@@map("subscription_interval")
|
||||||
|
}
|
||||||
|
|
||||||
model UserPaymentData {
|
model UserPaymentData {
|
||||||
userId String @id @map("user_id")
|
userId String @id @map("user_id")
|
||||||
subscriptionId String @map("subscription_id")
|
subscriptionId String @map("subscription_id")
|
||||||
|
@ -92,13 +101,14 @@ model Subscription {
|
||||||
status String
|
status String
|
||||||
active Boolean
|
active Boolean
|
||||||
currency String
|
currency String
|
||||||
interval String
|
interval SubscriptionInterval
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
periodStart DateTime @map("period_start")
|
periodStart DateTime @map("period_start")
|
||||||
periodEnd DateTime @map("period_end")
|
periodEnd DateTime @map("period_end")
|
||||||
user User?
|
|
||||||
cancelAtPeriodEnd Boolean @default(false) @map("cancel_at_period_end")
|
cancelAtPeriodEnd Boolean @default(false) @map("cancel_at_period_end")
|
||||||
|
|
||||||
|
user User?
|
||||||
|
|
||||||
@@map("subscriptions")
|
@@map("subscriptions")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue