Skip to content

feat(db): add template-mirror tracking columns#351

Closed
buremba wants to merge 2 commits into
mainfrom
feat/schema-mirror-tracking-cols
Closed

feat(db): add template-mirror tracking columns#351
buremba wants to merge 2 commits into
mainfrom
feat/schema-mirror-tracking-cols

Conversation

@buremba
Copy link
Copy Markdown
Member

@buremba buremba commented Apr 25, 2026

Summary

  • Adds managed_by_template_agent_id and source_template_org_id to entity_types, entity_relationship_types, event_classifiers, and watchers.
  • Partial indexes (WHERE managed_by_template_agent_id IS NOT NULL) keep user-authored rows unindexed.
  • Foundation for the template-agent schema-mirror feature: when a user installs a template agent, mirrored schema rows carry these columns so subsequent template updates can re-sync them.

This is the first slice of the personal-finance agent's platform foundation; downstream PRs (install flow, WhatsApp routing) will use these columns.

Test plan

  • Pre-commit Biome + tsc pass.
  • `dbmate up` applies the migration cleanly against dev Postgres.
  • `dbmate rollback` reverts cleanly via the `migrate:down` block.

Adds managed_by_template_agent_id and source_template_org_id to
entity_types, entity_relationship_types, event_classifiers, and watchers.

When a user installs a template agent, the install flow mirrors that
agent's canonical entity types, relationship types, classifiers and
watcher definitions from the template org into the user's personal org.
The two new columns record the provenance of those mirrored rows so they
can be re-synced on template updates and treated as read-only by the
user-org owner.

Partial indexes only cover non-NULL rows so user-authored entity
types/relationships/classifiers/watchers stay un-indexed (the common case).
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

- Add IF NOT EXISTS to ALTER TABLE ADD COLUMN so a rollback + re-apply
  doesn't fail on column-exists.
- Rename indexes from idx_*_managed_by_template to
  idx_*_template_agent_id to match the existing
  idx_<table>_<column> convention (cf. idx_cc_watcher_id).
@buremba
Copy link
Copy Markdown
Member Author

buremba commented Apr 25, 2026

Closing per docs/plans/world-model.md — schema cloning is dead weight once vocabularies live in shared public_catalog orgs and agents resolve them via cross-org references. No template-mirror tracking columns are needed because there is no mirror.

If we ever bring back per-tenant schema overrides, the right shape is local entity_types in the tenant org, not duplicated catalog rows. New plan replaces this with: organization.kind + visibility, denormalized source/target org_ids on entity_relationships, app-level write guard for cross-org refs.

@buremba buremba closed this Apr 25, 2026
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.

1 participant