import { boolean, index, jsonb, pgTable, smallint, text, timestamp, uuid, } from "drizzle-orm/pg-core"; import { households, users } from "../_core/schema"; export const journalEntries = pgTable( "journal_entries", { id: uuid("id").primaryKey().defaultRandom(), householdId: uuid("household_id") .notNull() .references(() => households.id, { onDelete: "cascade" }), userId: uuid("user_id") .notNull() .references(() => users.id, { onDelete: "cascade" }), recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull(), title: text("title"), body: text("body").notNull().default(""), moods: jsonb("moods").$type().notNull().default([]), stress: smallint("stress"), pillsTaken: boolean("pills_taken"), createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => [ index("journal_entries_user_recorded_idx").on(t.userId, t.recordedAt), index("journal_entries_household_idx").on(t.householdId), ], ); export type JournalEntry = typeof journalEntries.$inferSelect;