Commit 79f7554
Add unified cake_migrations table support with BC autodetect (#965)
* Add unified cake_migrations table support with BC autodetect
This change introduces a consolidated migration tracking approach for v5.0:
**New Features:**
- `cake_migrations` table: Single table with `plugin` column to track all migrations
- `UnifiedMigrationsTableStorage`: New storage class for unified table operations
- `migrations upgrade` command: Migrates data from legacy phinxlog tables
**Backward Compatibility:**
- Autodetect mode (default): If any `phinxlog` or `*_phinxlog` table exists,
legacy mode is used automatically - no breaking changes on upgrade
- Fresh installations automatically use the new `cake_migrations` table
**Configuration:**
- `Migrations.legacyTables = null` (default): Autodetect
- `Migrations.legacyTables = false`: Force unified table
- `Migrations.legacyTables = true`: Force legacy phinxlog tables
**Upgrade workflow:**
1. Upgrade to v5.0 (existing apps continue working with phinxlog)
2. Run `bin/cake migrations upgrade` to migrate data
3. Set `Migrations.legacyTables = false` in config
4. Application now uses unified `cake_migrations` table
Refs #822
- Address PR feedback for unified migrations table
- Simplify NULL handling using 'plugin IS' => $this->plugin pattern
- Remove cache complexity from UtilTrait
- Replace empty() with explicit === [] check
- Simplify upgradeTable() to no-op for new table format
- Use in_array for phinxlog detection (simpler than loop)
- Use hasTable() for phinxlog detection. Uses the new hasTable() method from
CakePHP 5.3 as suggested in the PR feedback.
- Add CI matrix, tests, docs for unified migrations table
- Add LEGACY_TABLES CI matrix option to test both modes
- Use schemaDialect()->hasTable() for phinxlog detection
- Add documentation for unified table upgrade process
- Add basic test for UnifiedMigrationsTableStorage
- Update bootstrap to read LEGACY_TABLES from environment
- Remove development notes
- Hide upgrade command when legacyTables is false. When
`Migrations.legacyTables` is set to `false`, the upgrade command is not
needed since the user has already opted into the unified table. Only show it
when in autodetect mode (null) or legacy mode (true).
- Remove LEGACY_TABLES CI matrix, partial test fixes. The unified table feature
works, but tests have extensive hardcoded phinxlog assumptions (99 failures).
Removing CI matrix for now.
- Partial fixes to BakeMigrationDiffCommandTest to show the pattern:
- Add UtilTrait to get correct schema table name
- Update table cleanup to include both table types
- Update queries to use dynamic table name
- Update tests to support unified migrations table mode
- Add helper methods to TestCase for migration table operations:
- getMigrationsTableName() - gets correct table name based on mode
- clearMigrationRecords() - clears records with plugin filtering
- getMigrationRecordCount() - counts records with plugin filtering
- insertMigrationRecord() - inserts with correct structure
- isUsingUnifiedTable() - checks current mode
- Update command tests to use new helper methods:
- MigrateCommandTest
- RollbackCommandTest
- StatusCommandTest
- MarkMigratedTest
- DumpCommandTest
- BakeMigrationDiffCommandTest
- Add cleanup for both phinxlog and cake_migrations tables
- Re-add LEGACY_TABLES=false CI matrix option
- Fix test suite for LEGACY_TABLES=false CI build
- Update Util::tableName() to return cake_migrations when unified table mode is enabled
- Update Manager::cleanupMissingMigrations() to use correct table name and filter by plugin
- Skip cake_migrations table in bake snapshot/diff commands (like phinxlog tables)
- Update TableFinder to skip cake_migrations table
- Update Migrator to not drop cake_migrations during table cleanup
- Update tests to use helper methods for migration record operations
- Add mode-aware assertions in adapter tests
- Skip some Migrator tests in unified mode that test legacy-specific behavior
- Feedback and fixes. I thought the conditional logic in Manager, and
unwrapping decorators pointed to a missing abstraction method. Since we're in
a major anyways, I could extend the interface and have better layering as
well.
- Add more tests.
- Fix diff baking tests to delete migration file after running migrate. The
checkSync() method compares the last migration file version against the last
migrated version. After the test deletes the migration record from the
phinxlog table, the migration file still exists, causing checkSync() to fail
because it sees an unmigrated file.
The fix deletes the migration file after running migrate and before baking
the diff, so checkSync() passes correctly.
- Remove file.
- Auto create folder. ensures a more stable setup.
---------
Co-authored-by: Mark Story <mark@mark-story.com>1 parent 7bdc30e commit 79f7554
File tree
33 files changed
+1550
-170
lines changed- .github/workflows
- docs/en
- src
- Command
- Db/Adapter
- Migration
- TestSuite
- Util
- tests
- TestCase
- Command
- Db/Adapter
- TestSuite
- test_app/config/MigrationsDiffDecimalChange
33 files changed
+1550
-170
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
138 | 146 | | |
139 | 147 | | |
140 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
105 | 194 | | |
106 | 195 | | |
107 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
587 | 590 | | |
588 | 591 | | |
589 | 592 | | |
| |||
0 commit comments