Skip to content

Conversation

@dereuromark
Copy link
Member

Resolves #659

The Bug: The getColumnOption() method will only convert limit to precision/scale if precision is already set. But when a decimal column is changed (e.g., from DECIMAL(4,2) to DECIMAL(6,2)), the $changedAttributes array in
BakeMigrationDiffCommand::getColumns() may only contain the changed values, not necessarily the precision field!

  1. When bake migration_diff detects a change in a decimal column's precision (e.g., from DECIMAL(4,2) to DECIMAL(6,2))
  2. The BakeMigrationDiffCommand::getColumns() method builds a $changedAttributes array with limit set to the new precision value
  3. But it may not include the precision field (which holds the scale in CakePHP)
  4. When MigrationHelper::getColumnOption() is called, it checks if (!isset($columnOptions['precision']) and if the precision field is not set, it skips the conversion logic
  5. As a result, the generated migration uses 'limit' => 6 instead of 'precision' => 6, 'scale' => 2

The fix requires ensuring that when a decimal column is changed, both the precision (total digits) and scale (decimal places) are included in the $changedAttributes array, or modifying the getColumnOption() method to
handle decimal types even when the precision field is not initially set.

@dereuromark dereuromark added this to the 4.x (CakePHP 5) milestone Oct 15, 2025
@dereuromark dereuromark requested a review from markstory October 16, 2025 13:04
- Created schema-dump-test_comparisons_mysql.lock and pgsql.lock with DECIMAL(8,2)
- Modified setup migrations to CREATE table instead of CHANGE column
- Added expected output files in mysql/ and pgsql/ subdirectories with CHANGE column
- This allows the diff command to compare DB (10,2) vs dump (8,2) and generate changeColumn migration
Added PHPStan ignore comment for setMigrations() call since we now support both AbstractMigration and BaseMigration which both implement MigrationInterface, but the parent method expects specifically AbstractMigration[].
…ompatible with Phinx

- Modified BaseMigration constructor to accept both signatures:
  - BaseMigration($version)
  - AbstractMigration($env, $version, $input, $output)
- Removed the entire getMigrations() override from CakeManager (100+ lines of duplicate code)
- Simplified executeMigration() by removing conditional instantiation
- This is a much cleaner solution than overriding the entire method
@dereuromark dereuromark deleted the fix-decimal branch October 22, 2025 00:42
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.

migration_diff generates incorrect code for decimal column definition change

3 participants