Skip to content

refactor(schema): promote provider-meta fields to canonical columns (#864) - #884

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/provider-meta-promotion-864
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/provider-meta-promotion-864

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026

Copy link
Copy Markdown
Owner

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 passed
  • 5 files, +95/-29
  • Slice 2 (parsers + materialization) follows

Refs #864 #840 #852

…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]>
Copilot AI review requested due to automatic review settings May 7, 2026 07:14
@Sinity
Sinity merged commit 54c5dae into master May 7, 2026
@Sinity
Sinity deleted the feature/refactor/provider-meta-promotion-864 branch May 7, 2026 07:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

if snapshot.current_version != SCHEMA_VERSION:

P0 Badge Add missing v9→v10 bootstrap path

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".

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 10 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c8adb982-156a-47cc-817e-8969f4861a45

📥 Commits

Reviewing files that changed from the base of the PR and between 73c7824 and da79458.

📒 Files selected for processing (5)
  • docs/plans/file-size-budgets.yaml
  • polylogue/storage/runtime/archive/records.py
  • polylogue/storage/sqlite/schema_bootstrap.py
  • polylogue/storage/sqlite/schema_ddl.py
  • polylogue/storage/sqlite/schema_ddl_archive.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/provider-meta-promotion-864

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_VERSION to 10.
  • Update archive DDL to add canonical columns on conversations, attachments, and attachment_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.

Comment on lines 73 to 86
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",
]
Comment on lines 45 to 60
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);
Comment on lines +224 to +240
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);
Comment on lines +889 to +910
_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);
"""
Comment on lines +917 to +925
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=())
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants