mirror of
https://github.com/nearai/ironclaw.git
synced 2026-09-03 08:06:01 +08:00
* fix(db): resolve V15 migration numbering conflict between user_identities and conversation_source_channel A merge conflict left two PostgreSQL migrations at V15. This renumbers them (V15=user_identities, V16=conversation_source_channel, V17=document_versions) to match the libSQL incremental ordering. Adds user_identities, document_versions, and source_channel to the libSQL base schema so fresh databases get all tables. Includes a one-time repair for existing databases where V15 was mis-recorded. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * style: fix rustfmt formatting in repair_misnumbered_v15 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(db): address PR review — proper error handling and tighter repair condition - Replace .ok().flatten() with explicit error propagation via .map_err()? so DB errors during V15 repair are surfaced, not silently swallowed - Tighten repair condition from `!= "user_identities"` to `== "document_versions"` to only fix the specific known-bad case from the merge conflict Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
25 lines
980 B
SQL
25 lines
980 B
SQL
-- Document version history for workspace files.
|
|
-- Every content update saves the previous content as a version,
|
|
-- enabling rollback and audit trails.
|
|
|
|
CREATE TABLE memory_document_versions (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
document_id UUID NOT NULL REFERENCES memory_documents(id) ON DELETE CASCADE,
|
|
version INTEGER NOT NULL,
|
|
content TEXT NOT NULL,
|
|
content_hash TEXT NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
changed_by TEXT,
|
|
UNIQUE(document_id, version)
|
|
);
|
|
|
|
CREATE INDEX idx_doc_versions_lookup
|
|
ON memory_document_versions(document_id, version DESC);
|
|
|
|
-- GIN index on metadata for future JSON containment queries
|
|
-- (e.g., WHERE metadata @> '{"hygiene": {"enabled": true}}').
|
|
-- Not used by current queries (which use path LIKE) but enables
|
|
-- efficient metadata-based filtering without a full table scan.
|
|
CREATE INDEX idx_memory_documents_metadata
|
|
ON memory_documents USING GIN (metadata jsonb_path_ops);
|