22 lines
930 B
TypeScript
22 lines
930 B
TypeScript
import { pgTable, uuid, varchar, timestamp } from 'drizzle-orm/pg-core';
|
|
import { planEnum, subscriptionStatusEnum } from './enums.js';
|
|
import { users } from './users.js';
|
|
|
|
export const subscriptions = pgTable('subscriptions', {
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
userId: uuid('user_id')
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: 'cascade' })
|
|
.unique(),
|
|
plan: planEnum('plan').notNull(),
|
|
status: subscriptionStatusEnum('status').notNull(),
|
|
startedAt: timestamp('started_at', { withTimezone: true }).notNull(),
|
|
expiresAt: timestamp('expires_at', { withTimezone: true }),
|
|
cancelledAt: timestamp('cancelled_at', { withTimezone: true }),
|
|
paymentProvider: varchar('payment_provider', { length: 50 }),
|
|
externalId: varchar('external_id', { length: 255 }),
|
|
});
|
|
|
|
export type Subscription = typeof subscriptions.$inferSelect;
|
|
export type NewSubscription = typeof subscriptions.$inferInsert;
|