import { index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"; import { households, users } from "../_core/schema"; export const bangEvents = pgTable( "bang_events", { id: uuid("id").primaryKey().defaultRandom(), householdId: uuid("household_id") .notNull() .references(() => households.id, { onDelete: "cascade" }), recordedBy: uuid("recorded_by").references(() => users.id, { onDelete: "set null" }), occurredOn: text("occurred_on").notNull(), // YYYY-MM-DD, text to avoid timezone confusion createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => [index("bang_events_household_occurred_idx").on(t.householdId, t.occurredOn)], ); export type BangEvent = typeof bangEvents.$inferSelect;