discourse/migrations/AGENTS.md
Gerhard Schlager 554977c7e6 MT: Refactor schema configuration from YAML to Ruby DSL
- Replace the YAML-based schema configuration with a Ruby DSL for defining intermediate database schemas
- Add table builders, conventions, enums, ignored tables, and output config as composable DSL files in `migrations/config/schema/`
- Implement schema resolver that combines DSL config with database introspection to produce resolved schemas
- Add generator that produces SQL schema, Ruby models, and enum files from the resolved schema
- Add scaffolder for bootstrapping new table configs and differ for comparing config against the database
- Add plugin manifest and introspection system to auto-detect plugin-owned columns
- Rewrite all schema CLI commands (`add`, `validate`, `diff`, `generate`, `list`, `ignore`, `refresh-plugins`) to use DSL infrastructure
- Add comprehensive specs and documentation (`migrations/docs/schema-configuration.md`)
- Remove old YAML config, JSON schema, and validation infrastructure
2026-03-19 18:10:26 +01:00

1.3 KiB

Migrations Tooling - AI Agent Guide

Running Tests

Tests must be run from the project root with --default-path migrations/spec:

bin/rspec --default-path migrations/spec
bin/rspec --default-path migrations/spec migrations/spec/lib/database/schema/dsl/
bin/rspec --default-path migrations/spec migrations/spec/path/to/file_spec.rb

CLI

The CLI binary is at migrations/bin/cli:

migrations/bin/cli help
migrations/bin/cli schema generate
migrations/bin/cli schema validate
migrations/bin/cli schema diff

Schema DSL

The schema DSL lives in migrations/lib/database/schema/dsl/. Config files are in migrations/config/schema/.

Key files:

  • table_builder.rb - DSL for defining table configs
  • schema_resolver.rb - Resolves DSL config + DB introspection into final schema
  • conventions_builder.rb - Global column conventions (renames, type overrides)
  • generator.rb - Generates SQL, models, and enums from resolved schema
  • validator.rb - Validates DSL config
  • resolved_schema_validator.rb - Validates resolved schema before generation

Linting

bin/lint path/to/file
bin/lint --fix path/to/file

Uses both rubocop and syntax_tree. Always lint changed files.

Gems

bundle config set --local with migrations
bundle install