BEGIN; ALTER TABLE posts ADD COLUMN edited_at timestamptz; -- Code-authored Wiki pages retain their public IDs; saved edits outlive deployments. CREATE TABLE note_edits ( page_id text PRIMARY KEY CHECK(page_id ~ '^[0-9a-f]{24}$'), title text NOT NULL CHECK(length(btrim(title))>0), description text NOT NULL DEFAULT '', markdown text NOT NULL DEFAULT '', updated_at timestamptz NOT NULL DEFAULT now() ); CREATE TABLE note_edit_tags ( page_id text NOT NULL REFERENCES note_edits(page_id) ON DELETE CASCADE, tag_id uuid NOT NULL REFERENCES tags(id) ON DELETE RESTRICT, PRIMARY KEY(page_id,tag_id) ); INSERT INTO schema_migrations(version) VALUES('005_note_editing'); COMMIT;