Skip to content

feat(brain): add schema versioning and entity migration#20

Draft
themusicman wants to merge 4 commits intomainfrom
feat/brain-schema-migration
Draft

feat(brain): add schema versioning and entity migration#20
themusicman wants to merge 4 commits intomainfrom
feat/brain-schema-migration

Conversation

@themusicman
Copy link
Contributor

Summary

  • Add schema versioning with integer version tracking and migration definitions
  • Implement entity migration engine that transforms entities between schema versions
  • Expose MigrateEntities action so the agent can trigger migrations via tool call

Detailed Changes

Schema Versioning (brain/schema.ex)

  • Schemas now carry a version integer (defaults to 1)
  • save_schema requires a migration map (from_version, to_version, field ops) when updating an existing schema
  • Version validation ensures monotonic progression

Migration Engine (brain/migration.ex)

  • Applies field-level operations: add_field, remove_field, rename_field, transform_field
  • Processes all entities of a type in a single pass, writing updated TOML back to disk
  • Stores migration history in brain/<type>/.migrations/ for auditability
  • Dry-run mode for previewing changes without writing

MigrateEntities Action (actions/brain/migrate_entities.ex)

  • New Jido action that wraps the migration engine
  • Accepts type, workspace, and optional dry_run flag

Path Helpers (brain/paths.ex)

  • Extracted shared path-building logic into a dedicated module
  • Used by both Brain and Migration to resolve workspace/type/entity paths

Error Handling (actions/brain/helpers.ex)

  • New error formatters for migration-specific failure modes

Agent Registration (agent.ex)

  • MigrateEntities added to the agent's action list

Test Plan

  • Schema version round-trips through save/load
  • Migration validates version fields and field operations
  • Entity migration applies add/remove/rename/transform correctly
  • Migration history files are written and readable
  • Dry-run mode returns preview without side effects
  • Path helpers resolve correctly for nested workspace layouts
  • MigrateEntities action integrates end-to-end in brain action tests

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