diff --git a/src/Command/BakeMigrationSnapshotCommand.php b/src/Command/BakeMigrationSnapshotCommand.php index 4b0427e7..4fec4628 100644 --- a/src/Command/BakeMigrationSnapshotCommand.php +++ b/src/Command/BakeMigrationSnapshotCommand.php @@ -105,6 +105,10 @@ public function templateData(Arguments $arguments): array if ($arguments->hasOption('disable-autoid')) { $autoId = !$arguments->getOption('disable-autoid'); } + $forceAutoId = false; + if ($arguments->hasOption('force-autoid')) { + $forceAutoId = !$arguments->getOption('force-autoid'); + } return [ 'plugin' => $this->plugin, @@ -115,6 +119,7 @@ public function templateData(Arguments $arguments): array 'action' => 'create_table', 'name' => $this->_name, 'autoId' => $autoId, + 'forceAutoId' => $forceAutoId, ]; } @@ -171,6 +176,10 @@ public function getOptionParser(): ConsoleOptionParser 'boolean' => true, 'default' => false, 'help' => 'Disable phinx behavior of automatically adding an id field.', + ])->addOption('force-autoid', [ + 'boolean' => true, + 'default' => false, + 'help' => 'Force automatically adding an id field. This will overwrite the disable-autoid option and ignore signed integers.', ]) ->addOption('no-lock', [ 'help' => 'If present, no lock file will be generated after baking', diff --git a/src/View/Helper/MigrationHelper.php b/src/View/Helper/MigrationHelper.php index e892cfa9..513b9360 100644 --- a/src/View/Helper/MigrationHelper.php +++ b/src/View/Helper/MigrationHelper.php @@ -308,7 +308,7 @@ public function hasAutoIdIncompatiblePrimaryKey(array $tables): bool return false; } - $useUnsignedPrimaryKes = Configure::read( + $useUnsignedPrimaryKeys = Configure::read( 'Migrations.unsigned_primary_keys', FeatureFlags::$unsignedPrimaryKeys ); @@ -321,7 +321,7 @@ public function hasAutoIdIncompatiblePrimaryKey(array $tables): bool foreach ($schema->getPrimaryKey() as $column) { $data = $schema->getColumn($column); - if (isset($data['unsigned']) && $data['unsigned'] === !$useUnsignedPrimaryKes) { + if (isset($data['unsigned']) && $data['unsigned'] === !$useUnsignedPrimaryKeys) { return true; } } diff --git a/templates/bake/config/diff.twig b/templates/bake/config/diff.twig index 21b56a22..616bf4d1 100644 --- a/templates/bake/config/diff.twig +++ b/templates/bake/config/diff.twig @@ -14,7 +14,6 @@ */ #} {% set tables = data['fullTables'] %} -{# unset($data['fullTables']) #} {% set constraints = [] %} {% set autoId = not Migration.hasAutoIdIncompatiblePrimaryKey(tables['add'] + tables['remove']) %}