feat(db): Drizzle ORM schema and migrations
Schema domains: users/auth, recipes, social, meal-planning, tiers/usage, webhooks. Includes Better Auth tables, audit_logs, site_settings, push_subscriptions, user_model_prefs, user_nutrition_goals. Migrations 0000–0008 applied.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { pgTable, text, boolean, timestamp, integer, jsonb } from "drizzle-orm/pg-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { users } from "./users";
|
||||
|
||||
export const webhooks = pgTable("webhooks", {
|
||||
id: text("id").primaryKey(),
|
||||
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
url: text("url").notNull(),
|
||||
events: text("events").array().notNull().default([]),
|
||||
secret: text("secret").notNull(),
|
||||
active: boolean("active").notNull().default(true),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const webhookDeliveries = pgTable("webhook_deliveries", {
|
||||
id: text("id").primaryKey(),
|
||||
webhookId: text("webhook_id").notNull().references(() => webhooks.id, { onDelete: "cascade" }),
|
||||
event: text("event").notNull(),
|
||||
payload: jsonb("payload"),
|
||||
statusCode: integer("status_code"),
|
||||
success: boolean("success").notNull().default(false),
|
||||
attempts: integer("attempts").notNull().default(0),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const webhooksRelations = relations(webhooks, ({ one, many }) => ({
|
||||
user: one(users, { fields: [webhooks.userId], references: [users.id] }),
|
||||
deliveries: many(webhookDeliveries),
|
||||
}));
|
||||
|
||||
export const webhookDeliveriesRelations = relations(webhookDeliveries, ({ one }) => ({
|
||||
webhook: one(webhooks, { fields: [webhookDeliveries.webhookId], references: [webhooks.id] }),
|
||||
}));
|
||||
Reference in New Issue
Block a user