-- Version history for document workspace / NAS edits

CREATE TABLE IF NOT EXISTS document_versions (
    id SERIAL PRIMARY KEY,
    storage_path TEXT NOT NULL,
    content TEXT NOT NULL DEFAULT '',
    source_format VARCHAR(32) DEFAULT 'markdown',
    version_label VARCHAR(128) DEFAULT '',
    nas_mtime TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_document_versions_path_created
    ON document_versions (storage_path, created_at DESC);
