fix(schema): backfill schema.py to match migrations.py reality (#691) - #732
Closed
AndriiPasternak31 wants to merge 1 commit into
Closed
fix(schema): backfill schema.py to match migrations.py reality (#691)#732AndriiPasternak31 wants to merge 1 commit into
AndriiPasternak31 wants to merge 1 commit into
Conversation
Adds 11 tables, 14 columns, and ~22 indexes that existed only in migrations.py to schema.py, restoring it as a faithful reference for the database (Architectural Invariant #3). Mechanical and additive. Migrations are append-only history. Existing databases unaffected — every new statement uses IF NOT EXISTS. Tables added: subscription_credentials, agent_notifications, subscription_rate_limit_events, slack_workspaces, slack_channel_agents, slack_active_threads, telegram_bindings, telegram_chat_links, telegram_group_configs, whatsapp_bindings, whatsapp_chat_links. Columns added: agent_ownership (full_capabilities, max_backlog_depth, voice_system_prompt), schedule_executions (source_user_id, source_user_email, source_agent_name, source_mcp_key_id, source_mcp_key_name, claude_session_id, queued_at, backlog_metadata, fan_out_id), agent_schedules (webhook_token, webhook_enabled). Indexes added: subscription, notification, rate-limit, multi-agent slack, telegram, whatsapp, plus partial indexes for execution backlog (idx_executions_queued), retry (idx_executions_pending_retry), fan-out (idx_executions_fan_out), webhook tokens (idx_schedules_webhook_token), and proactive sharing (idx_agent_sharing_proactive). Verified: name-only and strict DDL parity scripts both pass with zero missing and zero different entries. test_migrations.py 17/17. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings
src/backend/db/schema.pyinto alignment withsrc/backend/db/migrations.py, restoring it as a faithful reference for the database (Architectural Invariant #3 — "All table DDL lives inschema.py")./validate-schemaflagged 11 tables and 14 columns that existed in every running database (created by migrations) but were missing fromschema.py.The change is mechanical and additive — every CREATE TABLE / ALTER TABLE / CREATE INDEX statement in this PR was copied byte-for-byte from
migrations.py. No migration changes. No code changes. Existing databases unaffected — every new statement usesIF NOT EXISTS.Closes #691
What's added to
schema.py11 tables (each with the canonical DDL from its source migration):
subscription_credentials(SUB-001) — declared beforeagent_ownershipso thesubscription_idFK target exists if FKs ever get turned onagent_notifications(NOTIF-001)subscription_rate_limit_events(SUB-003)slack_workspaces,slack_channel_agents,slack_active_threads(SLACK-002)telegram_bindings,telegram_chat_links,telegram_group_configs(TELEGRAM-001 / TGRAM-GROUP) —verified_email/verified_atandverified_by_email/verified_atrolled in from_migrate_access_controland_migrate_group_auth_modewhatsapp_bindings,whatsapp_chat_links(WHATSAPP-001)14 columns rolled into existing CREATE TABLE bodies:
agent_ownership:full_capabilities,max_backlog_depth,voice_system_promptschedule_executions:source_user_id,source_user_email,source_agent_name,source_mcp_key_id,source_mcp_key_name,claude_session_id,queued_at,backlog_metadata,fan_out_idagent_schedules:webhook_token,webhook_enabled(feat: Webhook triggers for agent schedules (WEBHOOK-001) #291)~22 indexes including the partials that were defined only in migrations:
idx_executions_queued(partial WHEREstatus = 'queued')idx_executions_pending_retry(partial WHEREretry_scheduled_at IS NOT NULL AND status = 'pending_retry')idx_executions_fan_outidx_schedules_webhook_token(partial UNIQUE WHEREwebhook_token IS NOT NULL)idx_agent_sharing_proactive(partial WHEREallow_proactive = 1)Why now
schema.pywas a 70%-true reference — anyone reading it to learn the schema saw the wrong picture, and the architecture cross-reference todb/schema.pyas canonical DDL was misleading. This PR closes that gap. It does not eliminate the two-source-of-truth pattern that lets drift recur — see "Follow-up" below.Out of scope (intentional, per plan)
migrations.py— migrations are append-only history.architecture.mdupdate — Invariant Feature/vector log retention #3 is already documented.Follow-up
A CI gate that fails PRs adding a migration without updating
schema.pywas approved at the autoplan final gate as a separate issue. Filing alongside this PR so the prevention path doesn't slip.Test plan
missing tables: [], no missing cols,missing indexes: []0 missing, 0 differentADD COLUMNcross-reference: every column added by a migration lives inschema.pytests/unit/test_migrations.py: 17/17 pass~/trinity-data/trinity.db(reviewer to verify;IF NOT EXISTSguarantees this is a no-op)🤖 Generated with Claude Code
Migrated from #712 (head moved from fork to upstream as part of dropping the fork-based workflow). See #712 for original review thread.