Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force-autoid config. #668

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Command/BakeMigrationSnapshotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -115,6 +119,7 @@ public function templateData(Arguments $arguments): array
'action' => 'create_table',
'name' => $this->_name,
'autoId' => $autoId,
'forceAutoId' => $forceAutoId,
];
}

Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/MigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function hasAutoIdIncompatiblePrimaryKey(array $tables): bool
return false;
}

$useUnsignedPrimaryKes = Configure::read(
$useUnsignedPrimaryKeys = Configure::read(
'Migrations.unsigned_primary_keys',
FeatureFlags::$unsignedPrimaryKeys
);
Expand All @@ -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;
}
}
Expand Down
1 change: 0 additions & 1 deletion templates/bake/config/diff.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
#}
{% set tables = data['fullTables'] %}
{# unset($data['fullTables']) #}
{% set constraints = [] %}
{% set autoId = not Migration.hasAutoIdIncompatiblePrimaryKey(tables['add'] + tables['remove']) %}
<?php
Expand Down
4 changes: 2 additions & 2 deletions templates/bake/config/snapshot.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% set constraints = [] %}
{% set foreignKeys = [] %}
{% set dropForeignKeys = [] %}
{% if autoId and Migration.hasAutoIdIncompatiblePrimaryKey(tables) %}
{% if not forceAutoId and autoId and Migration.hasAutoIdIncompatiblePrimaryKey(tables) %}
{% set autoId = false %}
{% endif %}
<?php
Expand All @@ -26,7 +26,7 @@ use Migrations\AbstractMigration;

class {{ name }} extends AbstractMigration
{
{% if not autoId %}
{% if not autoId and not forceAutoId %}
public bool $autoId = false;

{% endif %}
Expand Down
Loading