CREATE TABLE IF NOT EXISTS pad_files (
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 pad_id INTEGER NOT NULL,
 filename TEXT NOT NULL,
 url TEXT NOT NULL UNIQUE,
 mime_type TEXT NOT NULL,
 size_bytes INTEGER NOT NULL,
 created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
 is_attached INTEGER NOT NULL DEFAULT 1,
 detached_at TEXT,
 FOREIGN KEY (pad_id) REFERENCES pads(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_pad_files_pad ON pad_files(pad_id, id DESC);
