diff --git a/docs/en/index.rst b/docs/en/index.rst index 992ae3cf..55bfa5ef 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -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`__. + Tips and tricks =============== diff --git a/src/ConfigurationTrait.php b/src/ConfigurationTrait.php index 67930082..89941259 100644 --- a/src/ConfigurationTrait.php +++ b/src/ConfigurationTrait.php @@ -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, @@ -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']; } } @@ -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']; } } @@ -186,10 +175,6 @@ public function getConfig($forceRefresh = false): ConfigInterface } if (!empty($connectionConfig['flags'])) { - /** - * @psalm-suppress PossiblyNullArrayAccess - * @psalm-suppress PossiblyNullArgument - */ $config['environments']['default'] += $this->translateConnectionFlags($connectionConfig['flags'], $adapterName); } @@ -197,6 +182,22 @@ public function getConfig($forceRefresh = false): ConfigInterface 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 + */ + 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.