Database
TSKit uses PostgreSQL with Drizzle ORM for database access. The database layer handles schema definitions, migrations, and seeding.
Connection
Section titled “Connection”The Drizzle client is created in database/index.ts and reads the DATABASE_URL environment variable. All services import the client from here.
Schemas
Section titled “Schemas”Table definitions live in database/schemas/, organized by domain:
| File | Tables |
|---|---|
auth.ts | users, sessions, accounts, verifications, twoFactors, organizations, members, invitations |
billing.ts | plans, planPrices, customers, subscriptions, usage, webhookEvents |
settings.ts | userSettings |
audit.ts | auditLogs |
The auth schema is generated by Better Auth CLI. If you modify the auth config (add plugins, change fields), regenerate it with:
bun run auth:generateFor other schemas, you define tables using Drizzle’s schema builder:
export const plans = pgTable('plans', { id: uuid('id').default(sql`gen_random_uuid()`).primaryKey(), slug: text('slug').notNull().unique(), name: text('name').notNull(), price: integer('price').default(0).notNull(), entitlements: jsonb('entitlements') .$type<Record<string, boolean | number>>() .default({}) .notNull(), active: boolean('active').default(true).notNull(), createdAt: timestamp('created_at').defaultNow().notNull(),})Migrations
Section titled “Migrations”After changing a schema file, generate a migration:
bun run db:generateThis creates a new SQL migration file in database/migrations/. Review the generated SQL, then apply it:
bun run db:migrateMigrations run in order based on their filename. Never edit an already-applied migration - create a new one instead.
Seeding
Section titled “Seeding”The seed script at database/seed.ts populates the database with sample data for development. Run it with:
bun run db:seedThis creates sample users, teams, plans, and subscriptions so you can test features without setting up everything manually.
Key files
Section titled “Key files”| File | Purpose |
|---|---|
database/index.ts | Drizzle client |
database/schemas/auth.ts | Auth tables (generated by Better Auth CLI) |
database/schemas/billing.ts | Billing tables (plans, subscriptions, usage) |
database/schemas/settings.ts | User settings |
database/schemas/audit.ts | Audit log table |
database/seed.ts | Development seed script |
database/migrations/ | SQL migration files |