Skip to content

Commit

Permalink
Merge pull request #600 from cakephp/3.x-bc
Browse files Browse the repository at this point in the history
Set BC feature flags to false for now.
  • Loading branch information
markstory authored Jan 12, 2023
2 parents e3de59f + 246d4be commit 97dfc6b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
18 changes: 18 additions & 0 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,24 @@ pass them to the method::
// This one with the "default" connection
$migrate = $migrations->migrate(['connection' => 'default']);

Feature Flags
=============

Migrations uses Phinx, which has some feature flags that are disabled by default for now, but
can enabled if you want them to:

* ``unsigned_primary_keys``: Should Phinx create primary keys as unsigned integers? (default: ``false``)
* ``column_null_default``: Should Phinx create columns as null by default? (default: ``false``)

Set them via Configure to enable (e.g. in ``config/app.php``)::

'Migrations' => [
'unsigned_primary_keys' => true,
'column_null_default' => true,
],

For details see `Phinx docs<https://book.cakephp.org/phinx/0/en/configuration.html#feature-flags>`__.

Tips and tricks
===============

Expand Down
37 changes: 19 additions & 18 deletions src/ConfigurationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,12 @@ public function getConfig($forceRefresh = false): ConfigInterface

$connection = $this->getConnectionName($this->input());

$connectionConfig = ConnectionManager::getConfig($connection);
/**
* @psalm-suppress PossiblyNullArgument
* @psalm-suppress PossiblyNullArrayAccess
*/
$adapterName = $this->getAdapterName($connectionConfig['driver']);
$connectionConfig = (array)ConnectionManager::getConfig($connection);

/** @psalm-suppress PossiblyNullArgument */
$adapterName = $this->getAdapterName($connectionConfig['driver']);
$dsnOptions = $this->extractDsnOptions($adapterName, $connectionConfig);

$templatePath = dirname(__DIR__) . DS . 'templates' . DS;
/** @psalm-suppress PossiblyNullArrayAccess */
$config = [
'paths' => [
'migrations' => $migrationsPath,
Expand All @@ -151,11 +145,11 @@ public function getConfig($forceRefresh = false): ConfigInterface
'dsn_options' => $dsnOptions,
],
],
'feature_flags' => $this->featureFlags(),
];

if ($adapterName === 'pgsql') {
if (!empty($connectionConfig['schema'])) {
/** @psalm-suppress PossiblyNullArrayAccess */
$config['environments']['default']['schema'] = $connectionConfig['schema'];
}
}
Expand All @@ -166,12 +160,7 @@ public function getConfig($forceRefresh = false): ConfigInterface
$config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert'];
}

/** @psalm-suppress PossiblyNullReference */
if (!empty($connectionConfig['ssl_ca'])) {
/**
* @psalm-suppress PossiblyNullReference
* @psalm-suppress PossiblyNullArrayAccess
*/
$config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca'];
}
}
Expand All @@ -186,17 +175,29 @@ public function getConfig($forceRefresh = false): ConfigInterface
}

if (!empty($connectionConfig['flags'])) {
/**
* @psalm-suppress PossiblyNullArrayAccess
* @psalm-suppress PossiblyNullArgument
*/
$config['environments']['default'] +=
$this->translateConnectionFlags($connectionConfig['flags'], $adapterName);
}

return $this->configuration = new Config($config);
}

/**
* The following feature flags are disabled by default to keep BC.
* The next major will turn them on. You can do so on your own before already.
*
* @return array<string, bool>
*/
protected function featureFlags(): array
{
$defaults = [
'unsigned_primary_keys' => false,
'column_null_default' => false,
];

return (array)Configure::read('Migrations') + $defaults;
}

/**
* Returns the correct driver name to use in phinx based on the driver class
* that was configured for the configuration.
Expand Down

0 comments on commit 97dfc6b

Please sign in to comment.