Repository navigation
refactor(schema): promote provider-meta fields to canonical columns (#864) - #884
Conversation
…864) Schema v9→v10: add working_directories_json, git_branch, git_repository_url to conversations. Add provider_attachment_id, provider_file_id, provider_drive_id to attachments and attachment_refs. Replace 8 JSON expression indexes with plain B-tree indexes on the new canonical columns. Drop the generated source_name column in favor of a real TEXT column. Slice 1 (DDL only): parsers and materialization follow in Slice 2. Co-Authored-By: Claude Opus 4.7 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
When SCHEMA_VERSION is 10 and an existing archive is at user_version=9, decide_schema_bootstrap never selects build_v9_to_v10_upgrade_plan; after the current_version == 8 branch it falls straight into version_mismatch. In that environment, all v9 databases are rejected instead of migrated, which blocks normal upgrades for existing users.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Schema v9→v10 (DDL-only “slice 1”) to promote several frequently-queried provider_meta fields into first-class SQLite columns and replace JSON expression indexes with plain indexes.
Changes:
- Bump SQLite archive
SCHEMA_VERSIONto 10. - Update archive DDL to add canonical columns on
conversations,attachments, andattachment_refs, and replace JSON expression indexes with provider-id indexes. - Add a v9→v10 upgrade plan (ALTER TABLE + index replacement) and update file-size budget exceptions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| polylogue/storage/sqlite/schema_ddl.py | Bumps schema version constant to v10. |
| polylogue/storage/sqlite/schema_ddl_archive.py | Updates fresh-schema DDL: new canonical columns + new indexes. |
| polylogue/storage/sqlite/schema_bootstrap.py | Adds v9→v10 upgrade plan DDL and wires tail-upgrade statements. |
| polylogue/storage/runtime/archive/records.py | Extends record models with new canonical fields (conversation + attachment IDs). |
| docs/plans/file-size-budgets.yaml | Raises budget ceiling for schema_bootstrap due to new migration logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| action: Literal[ | ||
| "create_fresh", | ||
| "apply_current_extensions", | ||
| "upgrade_v2_to_current", | ||
| "upgrade_v3_to_v4", | ||
| "upgrade_v4_to_v5", | ||
| "upgrade_v4_to_v6", | ||
| "upgrade_v5_to_v6", | ||
| "upgrade_v6_to_v7", | ||
| "upgrade_v7_to_v8", | ||
| "upgrade_v8_to_v9", | ||
| "upgrade_v9_to_v10", | ||
| "version_mismatch", | ||
| ] |
| CREATE TABLE IF NOT EXISTS conversations ( | ||
| conversation_id TEXT PRIMARY KEY, | ||
| provider_name TEXT NOT NULL, | ||
| provider_conversation_id TEXT NOT NULL, | ||
| title TEXT, | ||
| created_at TEXT, | ||
| updated_at TEXT, | ||
| sort_key REAL, | ||
| content_hash TEXT NOT NULL DEFAULT '', | ||
| provider_meta TEXT, | ||
| metadata TEXT DEFAULT '{}', | ||
| source_name TEXT GENERATED ALWAYS AS (json_extract(provider_meta, '$.source')) STORED, | ||
| source_name TEXT NOT NULL DEFAULT '', | ||
| working_directories_json TEXT, | ||
| git_branch TEXT, | ||
| git_repository_url TEXT, | ||
| version INTEGER NOT NULL, |
|
|
||
| CREATE INDEX IF NOT EXISTS idx_conversations_source_name | ||
| ON conversations(source_name) WHERE source_name IS NOT NULL; | ||
| ON conversations(source_name); |
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_attachment_id | ||
| ON attachments(provider_attachment_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_meta_provider_id | ||
| ON attachments(json_extract(provider_meta, '$.provider_id')) | ||
| WHERE provider_meta IS NOT NULL; | ||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_file_id | ||
| ON attachments(provider_file_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_meta_file_id | ||
| ON attachments(json_extract(provider_meta, '$.fileId')) | ||
| WHERE provider_meta IS NOT NULL; | ||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_drive_id | ||
| ON attachments(provider_drive_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_meta_drive_id | ||
| ON attachments(json_extract(provider_meta, '$.driveId')) | ||
| WHERE provider_meta IS NOT NULL; | ||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_attachment_id | ||
| ON attachment_refs(provider_attachment_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_meta_id | ||
| ON attachment_refs(json_extract(provider_meta, '$.id')) | ||
| WHERE provider_meta IS NOT NULL; | ||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_file_id | ||
| ON attachment_refs(provider_file_id); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_meta_provider_id | ||
| ON attachment_refs(json_extract(provider_meta, '$.provider_id')) | ||
| WHERE provider_meta IS NOT NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_meta_file_id | ||
| ON attachment_refs(json_extract(provider_meta, '$.fileId')) | ||
| WHERE provider_meta IS NOT NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_meta_drive_id | ||
| ON attachment_refs(json_extract(provider_meta, '$.driveId')) | ||
| WHERE provider_meta IS NOT NULL; | ||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_drive_id | ||
| ON attachment_refs(provider_drive_id); |
| _PROVIDER_META_PROMOTION_ATTACHMENT_INDEXES_DDL = """ | ||
| DROP INDEX IF EXISTS idx_attachments_provider_meta_id; | ||
| DROP INDEX IF EXISTS idx_attachments_provider_meta_provider_id; | ||
| DROP INDEX IF EXISTS idx_attachments_provider_meta_file_id; | ||
| DROP INDEX IF EXISTS idx_attachments_provider_meta_drive_id; | ||
| DROP INDEX IF EXISTS idx_attachment_refs_provider_meta_id; | ||
| DROP INDEX IF EXISTS idx_attachment_refs_provider_meta_provider_id; | ||
| DROP INDEX IF EXISTS idx_attachment_refs_provider_meta_file_id; | ||
| DROP INDEX IF EXISTS idx_attachment_refs_provider_meta_drive_id; | ||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_attachment_id | ||
| ON attachments(provider_attachment_id); | ||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_file_id | ||
| ON attachments(provider_file_id); | ||
| CREATE INDEX IF NOT EXISTS idx_attachments_provider_drive_id | ||
| ON attachments(provider_drive_id); | ||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_attachment_id | ||
| ON attachment_refs(provider_attachment_id); | ||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_file_id | ||
| ON attachment_refs(provider_file_id); | ||
| CREATE INDEX IF NOT EXISTS idx_attachment_refs_provider_drive_id | ||
| ON attachment_refs(provider_drive_id); | ||
| """ |
| statements: list[str] = [] | ||
| if snapshot.has_table("conversations"): | ||
| statements.extend(s for s in _split_ddl_into_statements(_PROVIDER_META_PROMOTION_CONVERSATION_DDL) if s) | ||
| if snapshot.has_table("attachments"): | ||
| statements.extend(s for s in _split_ddl_into_statements(_PROVIDER_META_PROMOTION_ATTACHMENT_DDL) if s) | ||
| if snapshot.has_table("attachment_refs"): | ||
| statements.extend(s for s in _split_ddl_into_statements(_PROVIDER_META_PROMOTION_ATTACHMENT_REF_DDL) if s) | ||
| statements.extend(s for s in _split_ddl_into_statements(_PROVIDER_META_PROMOTION_ATTACHMENT_INDEXES_DDL) if s) | ||
| return SchemaExtensionPlan(statements=tuple(statements), scripts=()) |
Slice 1 of #864 (DDL only). Universal archive semantics — source identity, working directories, git context, attachment native IDs — were trapped in `provider_meta` JSON blobs with eight JSON-expression indexes. Schema v9 → v10 promotes them to first-class columns; PR #909 supplies the population. - Conversations: adds `working_directories_json`, `git_branch`, `git_repository_url`. `source_name` is now a real `TEXT` column instead of a generated `json_extract(provider_meta, '$.source')` column. - Attachments / attachment_refs: adds `provider_attachment_id`, `provider_file_id`, `provider_drive_id`. - Indexes: replaces eight JSON-expression indexes with six plain B-tree indexes. - Migration: v9 → v10 upgrade plan with `ALTER TABLE ADD COLUMN` and index replacement; rejects unknown source versions per the fresh-first policy. Refs #840, #864
Slice 1 of #864 (DDL only). Universal archive semantics — source identity, working directories, git context, attachment native IDs — were trapped in `provider_meta` JSON blobs with eight JSON-expression indexes. Schema v9 → v10 promotes them to first-class columns; PR #909 supplies the population. - Conversations: adds `working_directories_json`, `git_branch`, `git_repository_url`. `source_name` is now a real `TEXT` column instead of a generated `json_extract(provider_meta, '$.source')` column. - Attachments / attachment_refs: adds `provider_attachment_id`, `provider_file_id`, `provider_drive_id`. - Indexes: replaces eight JSON-expression indexes with six plain B-tree indexes. - Migration: v9 → v10 upgrade plan with `ALTER TABLE ADD COLUMN` and index replacement; rejects unknown source versions per the fresh-first policy. Refs #840, #864
Summary
Schema v9→v10: promotes provider_meta fields to canonical columns. Slice 1 (DDL only).
Problem
Universal archive semantics (source identity, working directories, git context, attachment native IDs) were trapped in provider_meta JSON blobs with 8 JSON expression indexes.
Solution
Conversations: added
working_directories_json,git_branch,git_repository_url. Source name is now a real TEXT column instead of a generated column.Attachments/attachment_refs: added
provider_attachment_id,provider_file_id,provider_drive_id.Indexes: 8 JSON expression indexes replaced with 6 plain B-tree indexes.
Migration: v9→v10 upgrade plan with ALTER TABLE ADD COLUMN + index replacement.
Verification
devtools verify --quick— all 14 gates passedRefs #864 #840 #852