255 lines
9.4 KiB
Plaintext
255 lines
9.4 KiB
Plaintext
model SubscriptionProduct {
|
|
id String @id @default(cuid())
|
|
billingProviderId String
|
|
code String?
|
|
lagoPlanCode String?
|
|
order Int
|
|
title String
|
|
active Boolean
|
|
model Int
|
|
public Boolean
|
|
groupTitle String?
|
|
groupDescription String?
|
|
description String?
|
|
badge String?
|
|
billingAddressCollection String @default("auto")
|
|
hasQuantity Boolean @default(false)
|
|
canBuyAgain Boolean @default(false)
|
|
prices SubscriptionPrice[]
|
|
features SubscriptionFeature[]
|
|
tenantProducts TenantSubscriptionProduct[]
|
|
usageBasedPrices SubscriptionUsageBasedPrice[]
|
|
assignsTenantTypes TenantType[]
|
|
|
|
@@index([code])
|
|
@@index([lagoPlanCode])
|
|
}
|
|
|
|
model SubscriptionPrice {
|
|
id String @id @default(cuid())
|
|
subscriptionProductId String
|
|
subscriptionProduct SubscriptionProduct @relation(fields: [subscriptionProductId], references: [id], onDelete: Cascade)
|
|
billingProviderId String
|
|
lagoFeeCode String?
|
|
molliePriceReference String?
|
|
type Int
|
|
billingPeriod Int
|
|
price Decimal
|
|
currency String
|
|
trialDays Int
|
|
active Boolean
|
|
tenantProductPrices TenantSubscriptionProductPrice[]
|
|
|
|
@@index([lagoFeeCode])
|
|
@@index([molliePriceReference])
|
|
}
|
|
|
|
model SubscriptionUsageBasedPrice {
|
|
id String @id @default(cuid())
|
|
subscriptionProductId String
|
|
subscriptionProduct SubscriptionProduct @relation(fields: [subscriptionProductId], references: [id], onDelete: Cascade)
|
|
billingProviderId String
|
|
billingPeriod Int
|
|
currency String
|
|
unit String
|
|
unitTitle String
|
|
unitTitlePlural String
|
|
usageType String
|
|
aggregateUsage String
|
|
tiersMode String
|
|
billingScheme String
|
|
tiers SubscriptionUsageBasedTier[]
|
|
tenantProductPrices TenantSubscriptionProductPrice[]
|
|
}
|
|
|
|
model SubscriptionUsageBasedTier {
|
|
id String @id @default(cuid())
|
|
subscriptionUsageBasedPriceId String
|
|
subscriptionUsageBasedPrice SubscriptionUsageBasedPrice @relation(fields: [subscriptionUsageBasedPriceId], references: [id], onDelete: Cascade)
|
|
from Int
|
|
to Int?
|
|
perUnitPrice Decimal?
|
|
flatFeePrice Decimal?
|
|
}
|
|
|
|
model SubscriptionFeature {
|
|
id String @id @default(cuid())
|
|
subscriptionProductId String
|
|
order Int
|
|
title String
|
|
name String
|
|
code String?
|
|
type Int
|
|
value Int
|
|
quotaValue Json?
|
|
href String?
|
|
badge String?
|
|
accumulate Boolean @default(false)
|
|
subscriptionProduct SubscriptionProduct @relation(fields: [subscriptionProductId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([code])
|
|
}
|
|
|
|
model TenantSubscription {
|
|
id String @id @default(cuid())
|
|
tenantId String @unique
|
|
billingProviderCustomerId String?
|
|
lagoCustomerId String?
|
|
mollieCustomerId String?
|
|
planCode String?
|
|
seatQuantity Int @default(1)
|
|
lastInvoiceExternalId String?
|
|
lastPaymentExternalId String?
|
|
status String @default("trial")
|
|
trialStartsAt DateTime?
|
|
trialEndsAt DateTime?
|
|
pastDueSince DateTime?
|
|
frozenAt DateTime?
|
|
cancelledAt DateTime?
|
|
dunningAttemptCount Int @default(0)
|
|
lastDunningSentAt DateTime?
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
products TenantSubscriptionProduct[]
|
|
usageRecords TenantSubscriptionUsageRecord[]
|
|
|
|
@@index([status])
|
|
@@index([planCode])
|
|
@@index([lagoCustomerId])
|
|
@@index([mollieCustomerId])
|
|
@@index([trialEndsAt])
|
|
@@index([pastDueSince])
|
|
@@index([frozenAt])
|
|
}
|
|
|
|
model TenantSubscriptionProduct {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
tenantSubscriptionId String
|
|
subscriptionProductId String
|
|
customEntitlementPlanId String?
|
|
cancelledAt DateTime?
|
|
endsAt DateTime?
|
|
billingProviderSubscriptionId String?
|
|
lagoSubscriptionId String?
|
|
planCode String?
|
|
seatQuantity Int?
|
|
quantity Int?
|
|
fromCheckoutSessionId String?
|
|
currentPeriodStart DateTime?
|
|
currentPeriodEnd DateTime?
|
|
tenantSubscription TenantSubscription @relation(fields: [tenantSubscriptionId], references: [id], onDelete: Cascade)
|
|
subscriptionProduct SubscriptionProduct @relation(fields: [subscriptionProductId], references: [id])
|
|
prices TenantSubscriptionProductPrice[]
|
|
|
|
@@index([lagoSubscriptionId])
|
|
@@index([planCode])
|
|
}
|
|
|
|
model TenantSubscriptionProductPrice {
|
|
id String @id @default(cuid())
|
|
tenantSubscriptionProductId String
|
|
tenantSubscriptionProduct TenantSubscriptionProduct @relation(fields: [tenantSubscriptionProductId], references: [id], onDelete: Cascade)
|
|
subscriptionPriceId String?
|
|
subscriptionPrice SubscriptionPrice? @relation(fields: [subscriptionPriceId], references: [id])
|
|
subscriptionUsageBasedPriceId String?
|
|
subscriptionUsageBasedPrice SubscriptionUsageBasedPrice? @relation(fields: [subscriptionUsageBasedPriceId], references: [id])
|
|
quantity Int @default(1)
|
|
isMetered Boolean @default(false)
|
|
}
|
|
|
|
model TenantSubscriptionUsageRecord {
|
|
id String @id @default(cuid())
|
|
tenantId String
|
|
tenantSubscriptionId String
|
|
tenantSubscriptionProductPriceId String
|
|
tenantSubscription TenantSubscription @relation(fields: [tenantSubscriptionId], references: [id], onDelete: Cascade)
|
|
metricCode String @default("legacy")
|
|
timestamp Int
|
|
quantity Int
|
|
idempotencyKey String?
|
|
billingProviderSubscriptionItemId String?
|
|
|
|
@@unique([tenantId, metricCode, idempotencyKey])
|
|
@@index([tenantId, metricCode, timestamp])
|
|
}
|
|
|
|
model TenantProductConfiguration {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
tenantId String @unique
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
blueprintId String @default("crm-saas")
|
|
notes String?
|
|
}
|
|
|
|
model TenantFeatureOverride {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
tenantId String
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
featureKey String
|
|
override String
|
|
reason String?
|
|
|
|
@@unique([tenantId, featureKey])
|
|
@@index([featureKey, override])
|
|
}
|
|
|
|
model CheckoutSessionStatus {
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
id String @unique
|
|
pending Boolean @default(true) // has not added products to tenant
|
|
email String
|
|
fromUrl String
|
|
fromUserId String?
|
|
fromTenantId String?
|
|
createdUserId String?
|
|
createdTenantId String?
|
|
provider String?
|
|
providerPaymentId String?
|
|
invoiceExternalId String?
|
|
subscriptionProductId String?
|
|
subscriptionPriceId String?
|
|
lagoSubscriptionId String?
|
|
planCode String?
|
|
quantity Int @default(1)
|
|
amountCents Int?
|
|
currency String?
|
|
checkoutUrl String?
|
|
status String @default("open")
|
|
|
|
@@index([providerPaymentId])
|
|
@@index([fromTenantId, pending])
|
|
}
|
|
|
|
model BillingWebhookLog {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
providerEventId String @unique
|
|
eventType String
|
|
processedAt DateTime?
|
|
relatedTenantId String?
|
|
error String?
|
|
|
|
@@index([eventType, createdAt])
|
|
@@index([relatedTenantId, createdAt])
|
|
}
|
|
|
|
model Credit {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
tenantId String
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
userId String?
|
|
user User? @relation(fields: [userId], references: [id])
|
|
amount Int
|
|
type String
|
|
objectId String?
|
|
|
|
@@index([tenantId, userId])
|
|
@@index([tenantId, createdAt])
|
|
}
|