import { boolean, json, pgTable, serial, text, timestamp, varchar, } from "drizzle-orm/pg-core"; import { user } from "./better.auth.schema"; import { relations } from "drizzle-orm"; export const notifications = pgTable("notifications", { id: serial("id").primaryKey(), title: text("title").notNull(), body: text("body").notNull(), priority: varchar("priority", { length: 12 }).default("normal").notNull(), // "low", "normal", "high", "urgent" type: varchar("type", { length: 12 }).notNull(), category: varchar("category", { length: 64 }), isRead: boolean("is_read").default(false).notNull(), isArchived: boolean("is_archived").default(false).notNull(), actionUrl: text("action_url"), // URL to navigate to when clicked actionType: varchar("action_type", { length: 16 }), // Type of action ("link", "function", etc.) actionData: json("action_data"), // Any additional data for the action icon: varchar("icon", { length: 64 }), // Optional icon identifier userId: text("user_id") .notNull() .references(() => user.id, { onDelete: "cascade" }), // Lifecycle management sentAt: timestamp("sent_at").notNull(), readAt: timestamp("read_at"), expiresAt: timestamp("expires_at"), createdAt: timestamp("created_at").notNull(), updatedAt: timestamp("updated_at").notNull(), }); export const notificationsRelations = relations(notifications, ({ one }) => ({ userAccount: one(user, { fields: [notifications.userId], references: [user.id], }), }));