mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 18:51:52 +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")
|
||||
}
|
||||
|
||||
enum SubscriptionInterval {
|
||||
day
|
||||
week
|
||||
month
|
||||
year
|
||||
|
||||
@@map("subscription_interval")
|
||||
}
|
||||
|
||||
model UserPaymentData {
|
||||
userId String @id @map("user_id")
|
||||
subscriptionId String @map("subscription_id")
|
||||
|
@ -86,18 +95,19 @@ model UserPaymentData {
|
|||
}
|
||||
|
||||
model Subscription {
|
||||
id String @id
|
||||
priceId String @map("price_id")
|
||||
id String @id
|
||||
priceId String @map("price_id")
|
||||
amount Int
|
||||
status String
|
||||
active Boolean
|
||||
currency String
|
||||
interval String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
periodStart DateTime @map("period_start")
|
||||
periodEnd DateTime @map("period_end")
|
||||
user User?
|
||||
cancelAtPeriodEnd Boolean @default(false) @map("cancel_at_period_end")
|
||||
interval SubscriptionInterval
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
periodStart DateTime @map("period_start")
|
||||
periodEnd DateTime @map("period_end")
|
||||
cancelAtPeriodEnd Boolean @default(false) @map("cancel_at_period_end")
|
||||
|
||||
user User?
|
||||
|
||||
@@map("subscriptions")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue