Skip to content

Conversation

@dereuromark
Copy link
Owner

Summary

Adds Prisma-style shadow database drift detection to compare actual database schema against what migrations define.

  • New action: /test-helper/migrations/drift-check
  • Shadow database approach: Creates temp DB, runs all migrations, compares schemas
  • Structured diff report: Shows extra/missing tables, columns, indexes, constraints
  • Multi-database support: MySQL and PostgreSQL

Drift categories detected

Type Description
EXTRA_TABLE Table exists in DB but not defined in migrations
MISSING_TABLE Table defined in migrations but missing from DB
EXTRA_COLUMN Column in DB not expected by migrations
MISSING_COLUMN Column expected by migrations not in DB
TYPE_MISMATCH Column type/length/null/default differs
INDEX_DIFF Index missing, extra, or different
CONSTRAINT_DIFF Foreign key or constraint mismatch

Use cases

  • CI/CD pipelines: Fail deployment if production has unexpected changes
  • Team development: Detect if someone made manual DB changes
  • Post-incident: Verify schema after emergency hotfixes
  • Debugging: Identify why migrations fail due to existing manual changes

Test plan

  • Test drift check workflow on MySQL database
  • Test drift check workflow on PostgreSQL database
  • Verify schema comparison catches column type differences
  • Verify cleanup removes shadow database properly
  • Test with database that has no drift (should show success message)

🤖 Generated with Claude Code

@dereuromark dereuromark force-pushed the schema-drift branch 9 times, most recently from fc4d9c4 to 6351086 Compare November 25, 2025 17:34
Adds Prisma-style drift detection to compare actual database schema
against what migrations define. Uses the `test` database as shadow.

- Add getStructuredSchema() for schema introspection via CakePHP ORM
- Add compareSchemas() to diff expected vs actual schema
- Add driftCheck action using test DB as shadow (no temp DB needed)
- Support MySQL and PostgreSQL databases
- Support connection selection (all except test)
- Safety check: test DB must be different from selected connection
- Ignore plugin phinxlog tables (*_phinxlog)
- Report extra/missing tables, columns, indexes, and constraints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dereuromark dereuromark marked this pull request as ready for review November 25, 2025 17:50
@dereuromark dereuromark merged commit 35f54b7 into master Nov 25, 2025
16 checks passed
@dereuromark dereuromark deleted the schema-drift branch November 25, 2025 17:50
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