Skip to main content

Overview

Deltalytix supports three types of subscriptions:
  1. Subscription - Individual user subscriptions
  2. BusinessSubscription - Subscriptions for business accounts
  3. TeamSubscription - Subscriptions for team accounts
All three models share similar fields but are linked to different entity types.

Subscription Model

Individual user subscription with trial support and billing management.

Schema Fields

id
String
required
Unique identifier for the subscription
  • Constraint: Primary key, unique
  • Default: Auto-generated UUID
email
String
required
Email address associated with the subscription
  • Constraint: Unique
  • Indexed: Yes (performance optimization)
  • Used for billing notifications
plan
String
required
Subscription plan identifier
  • Examples: “PRO”, “PREMIUM”, “BASIC”
createdAt
DateTime
required
Timestamp when the subscription was created
  • Default: Current timestamp
userId
String
required
ID of the user who owns this subscription
  • Constraint: Unique (one subscription per user)
  • Foreign Key: References User.id with cascade delete
endDate
DateTime
Subscription end date
  • null for active subscriptions without end date
  • Set when subscription is cancelled or expires
status
String
required
Current subscription status
  • Default: “ACTIVE”
  • Common values: “ACTIVE”, “CANCELLED”, “EXPIRED”, “PAST_DUE”
trialEndsAt
DateTime
Trial period end date
  • null if no trial or trial has ended
  • Used to determine when billing starts
interval
String
Billing interval
  • Common values: “MONTHLY”, “YEARLY”

Indexes

  • email - Fast lookup by email for billing operations

Relationships

user
User
required
The user who owns this subscription
  • Foreign Key: userIdUser.id
  • Delete Behavior: Cascade (subscription deleted when user is deleted)

Unique Constraints

  • email must be unique across all individual subscriptions
  • userId must be unique (one subscription per user)

BusinessSubscription Model

Subscription for business accounts with multi-user access.

Schema Fields

id
String
required
Unique identifier for the business subscription
  • Constraint: Primary key, unique
  • Default: Auto-generated UUID
email
String
required
Email address for billing notifications
  • Constraint: Unique
  • Indexed: Yes
plan
String
required
Business subscription plan
  • Examples: “BUSINESS_PRO”, “BUSINESS_PREMIUM”
createdAt
DateTime
required
Timestamp when the subscription was created
  • Default: Current timestamp
userId
String
required
ID of the user who owns this subscription
  • Constraint: Unique (one business subscription per user)
  • Foreign Key: References User.id with cascade delete
  • Indexed: Yes
businessId
String
required
ID of the business this subscription is for
  • Constraint: Unique (one subscription per business)
  • Foreign Key: References Business.id with cascade delete
  • Indexed: Yes
endDate
DateTime
Subscription end date
  • null for active subscriptions
status
String
required
Current subscription status
  • Default: “ACTIVE”
  • Common values: “ACTIVE”, “CANCELLED”, “EXPIRED”, “PAST_DUE”
trialEndsAt
DateTime
Trial period end date
  • null if no trial or trial has ended
interval
String
Billing interval
  • Common values: “MONTHLY”, “YEARLY”

Indexes

  • email - Fast lookup by email
  • userId - Filter subscriptions by user
  • businessId - Query subscriptions by business

Relationships

user
User
required
The user who owns this subscription
  • Foreign Key: userIdUser.id
  • Delete Behavior: Cascade
business
Business
required
The business this subscription is for
  • Foreign Key: businessIdBusiness.id
  • Delete Behavior: Cascade

Unique Constraints

  • email must be unique across all business subscriptions
  • userId must be unique
  • businessId must be unique

TeamSubscription Model

Subscription for team accounts enabling collaborative features.

Schema Fields

id
String
required
Unique identifier for the team subscription
  • Constraint: Primary key, unique
  • Default: Auto-generated UUID
email
String
required
Email address for billing notifications
  • Constraint: Unique
  • Indexed: Yes
plan
String
required
Team subscription plan
  • Examples: “TEAM_PRO”, “TEAM_PREMIUM”
createdAt
DateTime
required
Timestamp when the subscription was created
  • Default: Current timestamp
userId
String
required
ID of the user who owns this subscription
  • Constraint: Unique (one team subscription per user)
  • Foreign Key: References User.id with cascade delete
  • Indexed: Yes
teamId
String
required
ID of the team this subscription is for
  • Constraint: Unique (one subscription per team)
  • Foreign Key: References Team.id with cascade delete
  • Indexed: Yes
endDate
DateTime
Subscription end date
  • null for active subscriptions
status
String
required
Current subscription status
  • Default: “ACTIVE”
  • Common values: “ACTIVE”, “CANCELLED”, “EXPIRED”, “PAST_DUE”
trialEndsAt
DateTime
Trial period end date
  • null if no trial or trial has ended
interval
String
Billing interval
  • Common values: “MONTHLY”, “YEARLY”

Indexes

  • email - Fast lookup by email
  • userId - Filter subscriptions by user
  • teamId - Query subscriptions by team

Relationships

user
User
required
The user who owns this subscription
  • Foreign Key: userIdUser.id
  • Delete Behavior: Cascade
team
Team
required
The team this subscription is for
  • Foreign Key: teamIdTeam.id
  • Delete Behavior: Cascade

Unique Constraints

  • email must be unique across all team subscriptions
  • userId must be unique
  • teamId must be unique

SubscriptionFeedback Model

Captures user feedback during subscription lifecycle events (cancellations, renewals).

Schema Fields

id
String
required
Unique identifier for the feedback
  • Constraint: Primary key
  • Default: Auto-generated UUID
email
String
required
Email of the user providing feedback
  • Indexed: Yes
event
String
required
Subscription event that triggered feedback
  • Examples: “CANCELLATION”, “DOWNGRADE”, “PAUSE”
createdAt
DateTime
required
Timestamp when the feedback was submitted
  • Default: Current timestamp
cancellationReason
String
Reason for cancellation (if applicable)
  • Optional structured reason code
feedback
String
Additional feedback text from the user
  • Optional free-form feedback

Indexes

  • email - Group feedback by user email

Team Model

Teams enable collaborative trading analysis and management.
id
String
required
Unique team identifier (UUID)
name
String
required
Team name (unique per user)
userId
String
required
Team owner’s user ID
traderIds
String[]
required
Array of trader IDs in the team (default: empty array)
createdAt
DateTime
required
Team creation timestamp
updatedAt
DateTime
required
Last update timestamp (auto-updated)

Business Model

Businesses enable multi-trader management and analytics.
id
String
required
Unique business identifier (UUID)
name
String
required
Business name (unique per user)
userId
String
required
Business owner’s user ID
traderIds
String[]
required
Array of trader IDs in the business (default: empty array)
createdAt
DateTime
required
Business creation timestamp
updatedAt
DateTime
required
Last update timestamp (auto-updated)

Common Subscription Patterns

Checking Active Subscription

const activeSubscription = await prisma.subscription.findFirst({
  where: {
    userId: 'user_123',
    status: 'ACTIVE',
    OR: [
      { endDate: null },
      { endDate: { gt: new Date() } }
    ]
  }
});

Creating Trial Subscription

const subscription = await prisma.subscription.create({
  data: {
    email: '[email protected]',
    plan: 'PRO',
    userId: 'user_123',
    status: 'ACTIVE',
    interval: 'MONTHLY',
    trialEndsAt: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000) // 14 days
  }
});

Cancelling Subscription

const cancelled = await prisma.subscription.update({
  where: { userId: 'user_123' },
  data: {
    status: 'CANCELLED',
    endDate: new Date()
  }
});

Build docs developers (and LLMs) love