Files
famapp/src/modules/journal/schema.ts
T
ginnoir 04ae809e07 feat(journal): add per-user mood journal module (task 86)
Ship journal entries with mood tracking, insights, and Recharts charts.

Adds v1 API endpoints per ADR 0005 and migration 0020_journal_entries.
2026-07-04 19:41:15 -05:00

39 lines
1.2 KiB
TypeScript

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<string[]>().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;