// The tables of the notes module. Two, both project-owned. // // `notes_note` is the note. `notes_attachment` links a note to a row of the files module: the file // id is an opaque id and never a foreign key (spec ยง4.4), and the bytes, the size, the digest and // the object in the Blob store stay the files module's, so there is one canonical copy of a file. import { defineEntity, idSchema } from "@conusai-kit/data" import { z } from "zod" export const notes = defineEntity({ name: "note", table: "notes_note", tenancy: "project", fields: { title: z.string().min(1).max(200), body: z.string().max(20_000), createdBy: idSchema, }, indexes: [["createdBy"]], }) export const attachments = defineEntity({ name: "attachment", table: "notes_attachment", tenancy: "project", fields: { noteId: idSchema, fileId: idSchema, attachedBy: idSchema, }, // A file is attached to a note once; attaching it again is the call it already answered. unique: [["noteId", "fileId"]], // The file's own index: deleting a file looks its attachments up by it. indexes: [["noteId"], ["fileId"]], }) /** Every table this module owns, in the order a migration creates them. */ export const NOTES_ENTITIES = Object.freeze([notes, attachments])