-- ═══════════════════════════════════════════════════════════════ -- 028 MEDIA: UPLOADED IMAGES -- -- One row per file in UPLOADS_DIR (/var/lib/ngu/uploads in -- production, outside the deployed app so an rsync can't touch -- it). nginx serves the directory at /uploads/; the API only -- writes and deletes. -- -- An image field stores the file's public path, '/uploads/', -- not this row's id. That keeps every image column a plain TEXT -- that also takes a filename in public/ or a full URL, as before, -- and means media.ts needs no lookup. The cost is no foreign key: -- deleting a file a record still names leaves that record showing -- nothing (the and fallbacks already handle a missing -- file), so the Media page warns before a delete. -- -- filename the stored name: random, so it can't collide or -- be guessed from the original. '3f9c…e1.webp' -- original_name what the uploader's file was called, for the -- library's search and display -- processed 1 when resized and converted to WebP, 0 when -- kept as uploaded -- width, height null for an SVG, which has no pixel size -- -- PRAGMA user_version; -- reads 27 before this file -- ═══════════════════════════════════════════════════════════════ CREATE TABLE media ( id INTEGER PRIMARY KEY AUTOINCREMENT, filename TEXT NOT NULL UNIQUE, original_name TEXT NOT NULL, content_type TEXT NOT NULL, bytes INTEGER NOT NULL CHECK (bytes >= 0), width INTEGER, height INTEGER, processed INTEGER NOT NULL DEFAULT 1 CHECK (processed IN (0, 1)), uploaded_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL, created_at TEXT NOT NULL DEFAULT (datetime('now')) ) STRICT; CREATE INDEX media_created_idx ON media (created_at DESC);