43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import {
|
|
pgTable,
|
|
uuid,
|
|
text,
|
|
timestamp,
|
|
boolean,
|
|
integer,
|
|
} from "drizzle-orm/pg-core";
|
|
import { users } from "./users";
|
|
|
|
export const subscriptions = pgTable("subscriptions", {
|
|
id: uuid("id").defaultRandom().primaryKey(),
|
|
userId: uuid("user_id")
|
|
.notNull()
|
|
.unique()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
|
|
// Stripe subscription ID
|
|
stripeSubscriptionId: text("stripe_subscription_id").unique(),
|
|
|
|
// Stripe customer ID
|
|
stripeCustomerId: text("stripe_customer_id"),
|
|
|
|
// Subscription status: "active", "trialing", "past_due", "canceled", "unpaid"
|
|
status: text("status").notNull().default("trialing"),
|
|
|
|
// Current period start/end
|
|
currentPeriodStart: timestamp("current_period_start", { withTimezone: true }),
|
|
currentPeriodEnd: timestamp("current_period_end", { withTimezone: true }),
|
|
|
|
// When subscription was created
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow(),
|
|
|
|
// When subscription was last updated
|
|
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow(),
|
|
|
|
// When subscription was canceled (if applicable)
|
|
canceledAt: timestamp("canceled_at", { withTimezone: true }),
|
|
});
|