Overview
The application uses Drizzle ORM to manage the PostgreSQL database hosted on Supabase. This guide explains the database schema and how to push it to your Supabase project.Prerequisites
- Supabase project created (see Supabase Setup)
DATABASE_URLconfigured in your.env.localfile- Dependencies installed (
npm install,pnpm install, orbun install)
Database Schema
The application uses three main tables:users, subscriptions, and payments.
Users Table
Stores user account information and links to Dodo Payments customer records.supabaseUserId: Links to Supabase Auth userdodoCustomerId: Links to Dodo Payments customer IDcurrentSubscriptionId: Reference to the user’s active subscription
Subscriptions Table
Stores all subscription data synchronized from Dodo Payments webhooks.status: Subscription state (active, cancelled, expired, on_hold, etc.)nextBillingDate: When the next payment will be chargedproductId: Links to the Dodo Payments productmetadata: Custom data from Dodo Payments (includes features array)billing: Customer billing address and information
Payments Table
Stores all payment transactions and their details.status: Payment status (succeeded, failed, processing, cancelled)totalAmount: Total payment amount including taxsubscriptionId: Links to the related subscriptionwebhookData: Complete webhook payload for debuggingcardLastFour: Last 4 digits of the payment card
Database Relations
Push Schema to Supabase
Run the migration command
Push the schema to your Supabase database:This command uses Drizzle Kit to create the tables directly in your database without generating migration files.
Drizzle Configuration
The database configuration is defined indrizzle.config.ts:
Additional Drizzle Commands
Generate Migration Files
If you prefer to use migration files instead of direct schema push:lib/drizzle/migrations/.
Apply Migrations
Apply generated migration files:Drizzle Studio
Open Drizzle Studio to visually browse and edit your database:https://local.drizzle.studio.
Schema Location
The complete schema definition is located at:db:push again to update your database.
Next Steps
Webhooks
Deploy webhook handlers to sync payment data
Google OAuth
Configure user authentication
