mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-09-22 10:33:27 +00:00
6461aafd16
Adds the schema groundwork for inline images and file uploads — see DOC-865 (Attachments — architecture & migration design). - migrations/047_attachments.sql — SQLite migration. Table + 4 indexes (workspace, item, hash, parent). Partial indexes on workspace/item/parent match the items table convention. The hash index is full (not partial) so dedupe can resurrect a soft-deleted blob if the same bytes are re-uploaded without writing a duplicate. - pgmigrations/026_attachments.sql — Postgres mirror with BIGINT for size_bytes; same partial-index pattern. - internal/models/attachment.go — Go model with all columns. Uses pointer types for nullable columns (item_id, width, height, parent_id, variant, deleted_at) so JSON omitempty works correctly. No call sites yet — purely schema groundwork. Verified the migration runs cleanly on a fresh install and on the live dev DB. Parent: PLAN-866.
26 lines
1.0 KiB
SQL
26 lines
1.0 KiB
SQL
-- Postgres mirror of migrations/047_attachments.sql (TASK-869).
|
|
-- See [[Attachments — architecture & migration design]] (DOC-865) for context.
|
|
|
|
CREATE TABLE IF NOT EXISTS attachments (
|
|
id TEXT PRIMARY KEY,
|
|
workspace_id TEXT NOT NULL,
|
|
item_id TEXT,
|
|
uploaded_by TEXT NOT NULL,
|
|
storage_key TEXT NOT NULL,
|
|
content_hash TEXT NOT NULL,
|
|
mime_type TEXT NOT NULL,
|
|
size_bytes BIGINT NOT NULL,
|
|
filename TEXT NOT NULL,
|
|
width INTEGER,
|
|
height INTEGER,
|
|
parent_id TEXT,
|
|
variant TEXT,
|
|
created_at TEXT NOT NULL,
|
|
deleted_at TEXT
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_attach_workspace ON attachments(workspace_id) WHERE deleted_at IS NULL;
|
|
CREATE INDEX IF NOT EXISTS idx_attach_item ON attachments(item_id) WHERE deleted_at IS NULL;
|
|
CREATE INDEX IF NOT EXISTS idx_attach_hash ON attachments(content_hash);
|
|
CREATE INDEX IF NOT EXISTS idx_attach_parent ON attachments(parent_id) WHERE parent_id IS NOT NULL;
|