tia/src/db/schema/media.ts
Mannu c2cabc01d3 feat(g1-g4): design system, memories pipeline, medical tracking, AI brain
G1 — Design System: 14 UI primitives (Button, Card, Modal, Sheet, Input,
Textarea, Select, EmptyState, LoadingShimmer, ConfirmDialog, WashiTape,
Badge, Avatar, Tabs), PageTransition with Framer Motion, sun/moon CSS vars,
Caveat font, /dev/components visual showcase.

G2 — Memories Pipeline: R2 presigned uploads, Sharp thumbnail generation,
LiteLLM vision captions + pgvector embeddings, CSS masonry gallery with
infinite scroll, private toggle, semantic search fallback to ILIKE.

G3 — Medical: dose log + correction audit trail, IAP vaccine bulk import,
emergency escalation page, pediatrician phone in settings.

G4 — AI Brain: keyword guardrail → LLM classifier → structured DB tool-use
(7 tools) → memory search → general parenting handler; ai_usage table;
22-case medical bypass safety test suite.

DB migrations: 0011_memories, 0012_medical_doses, 0013_ai_usage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 17:48:34 +05:30

64 lines
2 KiB
TypeScript

import {
pgTable,
text,
timestamp,
uuid,
boolean,
integer,
index,
} from "drizzle-orm/pg-core";
// Processing states for background jobs
export type ProcessingStatus = "uploading" | "processing" | "ready" | "failed";
export const memories = pgTable(
"memories",
{
id: uuid("id").primaryKey().defaultRandom(),
familyId: uuid("family_id").notNull(),
childId: uuid("child_id"),
title: text("title"),
description: text("description"),
takenAt: timestamp("taken_at"),
r2Key: text("r2_key").notNull(),
r2ThumbnailKey: text("r2_thumbnail_key"),
mimeType: text("mime_type"),
sizeBytes: integer("size_bytes"),
width: integer("width"),
height: integer("height"),
visionCaption: text("vision_caption"),
// vision_tags is text[] in DB — handled with raw SQL
// vision_embedding is vector(1536) in DB — handled with raw SQL
isPrivate: boolean("is_private").default(false).notNull(),
processingStatus: text("processing_status").$type<ProcessingStatus>().default("uploading").notNull(),
uploadedBy: uuid("uploaded_by"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
},
(table) => [
index("memories_family_idx").on(table.familyId),
index("memories_child_idx").on(table.childId),
]
);
export const attachments = pgTable(
"attachments",
{
id: uuid("id").primaryKey().defaultRandom(),
familyId: uuid("family_id").notNull(),
logEntryId: uuid("log_entry_id"),
r2Key: text("r2_key").notNull(),
r2ThumbnailKey: text("r2_thumbnail_key"),
mimeType: text("mime_type"),
sizeBytes: integer("size_bytes"),
uploadedBy: uuid("uploaded_by"),
createdAt: timestamp("created_at").defaultNow().notNull(),
},
(table) => [
index("attachments_family_idx").on(table.familyId),
]
);
export type Memory = typeof memories.$inferSelect;
export type NewMemory = typeof memories.$inferInsert;
export type Attachment = typeof attachments.$inferSelect;