Skip to content

Fix checkSync() to only consider migrations from current context#1061

Open
dereuromark wants to merge 1 commit into5.xfrom
fix-checksync-plugin-context
Open

Fix checkSync() to only consider migrations from current context#1061
dereuromark wants to merge 1 commit into5.xfrom
fix-checksync-plugin-context

Conversation

@dereuromark
Copy link
Copy Markdown
Member

@dereuromark dereuromark commented Mar 28, 2026

Summary

Fixes #1060

When using the unified cake_migrations table, BakeMigrationDiffCommand had two issues:

  1. setup() didn't filter migrations by context: The query for migrated items fetched ALL migrations from cake_migrations without filtering by the current plugin. This caused issues when baking diffs for plugins.

  2. checkSync() compared wrong versions: It compared the last migrated version (from ALL contexts) against the last migration file in the current context only.

Symptoms

$ bin/cake bake migration_diff AddedFieldToUsersSettingsTable
Your migrations history is not in sync with your migrations files. Make sure all your migrations have been migrated before baking a diff.

This happened when a plugin had more recent migrations than the app being baked.

Fix

  1. Filter migratedItems by plugin context in setup(): In unified table mode, the query now includes WHERE plugin IS :plugin to only fetch migrations for the current context.

  2. Context-aware checkSync(): The method now filters migrated versions to only those that have corresponding migration files in the current context before comparing.

Testing

Added testCheckSyncWithPluginMigrationsMoreRecent() that:

  1. Runs app migrations
  2. Creates a schema dump
  3. Inserts a more recent plugin migration record
  4. Verifies that baking a diff for the app succeeds (previously would fail)

@dereuromark dereuromark force-pushed the fix-checksync-plugin-context branch from 73d4ac8 to b7d34d5 Compare March 28, 2026 12:13
When using the unified `cake_migrations` table, `BakeMigrationDiffCommand::checkSync()`
was comparing the last migrated version (from ALL contexts including plugins) against
the last migration file in the current context (app or specific plugin).

This caused false "not in sync" errors when a plugin had more recent migrations
than the app being baked.

The fix filters migrated versions to only consider those that have corresponding
files in the current context before comparing.

Fixes #1060
@dereuromark dereuromark force-pushed the fix-checksync-plugin-context branch from b7d34d5 to f606ec1 Compare March 28, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BakeMigrationDiffCommand::checkSync() is there a difference between apps and plugins?

1 participant