Skip to content

Commit

Permalink
Merge pull request #2210 from cakephp/0.x-1.x-merge
Browse files Browse the repository at this point in the history
Merge branch '0.x' into 1.x
  • Loading branch information
dereuromark committed Aug 3, 2023
2 parents efec06d + 28746e8 commit 8ca989d
Show file tree
Hide file tree
Showing 37 changed files with 1,442 additions and 79 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- '0.x'
- '0.next'
- '1.x'
pull_request:

Expand Down Expand Up @@ -64,12 +63,10 @@ jobs:

- name: Composer install
run: |
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
composer install --ignore-platform-req=php
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer update
composer install
fi
- name: Setup problem matchers for PHPUnit
Expand All @@ -96,7 +93,7 @@ jobs:
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export MYSQL_DSN='mysql://root:root@127.0.0.1/phinx'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export PGSQL_DSN='pgsql://postgres:postgres@127.0.0.1/phinx'; fi
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
else
vendor/bin/phpunit
Expand All @@ -107,7 +104,7 @@ jobs:
run: composer require --dev dereuromark/composer-prefer-lowest && vendor/bin/validate-prefer-lowest -m

- name: Submit code coverage
if: matrix.php-version == '8.1'
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v3

testsuite-windows:
Expand Down Expand Up @@ -209,7 +206,7 @@ jobs:
run: composer stan-setup

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --report=checkstyle -np app/ src/ tests/
run: vendor/bin/phpcs

- name: Run phpstan
if: always()
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.2
FROM php:7.3

# system dependecies
RUN apt-get update && apt-get install -y \
Expand Down
22 changes: 18 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
(The MIT license)

Copyright (c) 2012-present Rob Morgan
Copyright (c) 2012-2017 Rob Morgan
Copyright (c) 2017-present, Cake Software Foundation, Inc. (https://cakefoundation.org)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# [Phinx](https://phinx.org): Simple PHP Database Migrations

[![Build Status](https://github.com/cakephp/phinx/workflows/Phinx%20CI/badge.svg?branch=master&event=push)](https://github.com/cakephp/phinx/actions?query=workflow%3A%22Phinx+CI%22+branch%3Amaster+event%3Apush)
[![Build Status](https://github.com/cakephp/phinx/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/cakephp/phinx/actions?query=workflow%3A%22CI%22+branch%3Amaster+event%3Apush)
[![Code Coverage](https://codecov.io/gh/cakephp/phinx/branch/master/graph/badge.svg)](https://codecov.io/gh/cakephp/phinx)
[![Latest Stable Version](https://poser.pugx.org/robmorgan/phinx/version.png)](https://packagist.org/packages/robmorgan/phinx)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg)](https://php.net/)
[![Total Downloads](https://poser.pugx.org/robmorgan/phinx/d/total.png)](https://packagist.org/packages/robmorgan/phinx)

## Intro
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
],
"require": {
"php": ">=8.1",
"php-64bit": ">=8.1",
"cakephp/database": "5.x-dev",
"psr/container": "^2.0",
"symfony/console": "^6.0",
Expand Down Expand Up @@ -71,9 +71,9 @@
"@test",
"@cs-check"
],
"cs-check": "phpcs -np app/ src/ tests/",
"cs-fix": "phpcbf -np app/ src/ tests/",
"stan": "phpstan analyse src/",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"stan": "phpstan analyse",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.9.0 && mv composer.backup composer.json",
"test": "phpunit --colors=always"
},
Expand Down
20 changes: 20 additions & 0 deletions docs/en/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,23 @@ Within the bootstrap script, the following variables will be available:
* @var \Symfony\Component\Console\Output\OutputInterface $output The executing command's output object
* @var \Phinx\Console\Command\AbstractCommand $context the executing command object
*/
Feature Flags
-------------

For some breaking changes, Phinx offers a way to opt-out of new behavior. The following flags are available:

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

.. code-block:: yaml
feature_flags:
unsigned_primary_keys: false
These values can also be set by modifying class fields on the ```Phinx\Config\FeatureFlags``` class, converting
the flag name to ``camelCase``, for example:

.. code-block:: php
Phinx\Config\FeatureFlags::$unsignedPrimaryKeys = false;
7 changes: 6 additions & 1 deletion docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
Phinx Documentation
===================

Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minutes, you can install Phinx using Composer and create your first database migration. Phinx is just about migrations without all the bloat of a database ORM system or application framework.
Phinx makes it ridiculously easy to manage the database migrations for your PHP
app. In less than 5 minutes, you can install Phinx using Composer and create
your first database migration. Phinx is just about migrations without all the
bloat of a database ORM system or application framework.

Phinx requires a 64-bit version of PHP to function.

Contents
========
Expand Down
7 changes: 2 additions & 5 deletions docs/en/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,8 @@ Limit Option and MySQL

When using the MySQL adapter, there are a couple things to consider when working with limits:

- When using a ``string`` primary key or index on MySQL 5.7 or below and the default charset of ``utf8mb4_unicode_ci``, you
must specify a limit less than or equal to 191, or use a different charset.
- Additional hinting of database column type can be
made for ``integer``, ``text``, ``blob``, ``tinyblob``, ``mediumblob``, ``longblob`` columns. Using ``limit`` with
one the following options will modify the column type accordingly:
- When using a ``string`` primary key or index on MySQL 5.7 or below, or the MyISAM storage engine, and the default charset of ``utf8mb4_unicode_ci``, you must specify a limit less than or equal to 191, or use a different charset.
- Additional hinting of database column type can be made for ``integer``, ``text``, ``blob``, ``tinyblob``, ``mediumblob``, ``longblob`` columns. Using ``limit`` with one the following options will modify the column type accordingly:

============ ==============
Limit Column Type
Expand Down
9 changes: 7 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
<ruleset name="Phinx">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>

<arg value="nps"/>

<file>src/</file>
<file>tests/</file>

<exclude-pattern>*_files*</exclude-pattern>

<rule ref="CakePHP"/>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<severity>0</severity>
</rule>

<exclude-pattern>*_files*</exclude-pattern>
</ruleset>
4 changes: 4 additions & 0 deletions src/Phinx/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function __construct(array $configArray, ?string $configFilePath = null)
{
$this->configFilePath = $configFilePath;
$this->values = $this->replaceTokens($configArray);

if (isset($this->values['feature_flags'])) {
FeatureFlags::setFlagsFromConfig($this->values['feature_flags']);
}
}

/**
Expand Down
41 changes: 41 additions & 0 deletions src/Phinx/Config/FeatureFlags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace Phinx\Config;

/**
* Class to hold features flags to toggle breaking changes in Phinx.
*
* New flags should be added very sparingly.
*/
class FeatureFlags
{
/**
* @var bool Should Phinx create unsigned primary keys by default?
*/
public static $unsignedPrimaryKeys = true;
/**
* @var bool Should Phinx create columns NULL by default?
*/
public static $columnNullDefault = true;

/**
* Set the feature flags from the `feature_flags` section of the overall
* config.
*
* @param array $config The `feature_flags` section of the config
*/
public static function setFlagsFromConfig(array $config): void
{
if (isset($config['unsigned_primary_keys'])) {
self::$unsignedPrimaryKeys = (bool)$config['unsigned_primary_keys'];
}
if (isset($config['column_null_default'])) {
self::$columnNullDefault = (bool)$config['column_null_default'];
}
}
}
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function createSchemaTable(): void
->addColumn('migration_name', 'string', ['limit' => 100, 'default' => null, 'null' => true])
->addColumn('start_time', 'timestamp', ['default' => null, 'null' => true])
->addColumn('end_time', 'timestamp', ['default' => null, 'null' => true])
->addColumn('breakpoint', 'boolean', ['default' => false])
->addColumn('breakpoint', 'boolean', ['default' => false, 'null' => false])
->save();
} catch (Exception $exception) {
throw new InvalidArgumentException(
Expand Down
10 changes: 6 additions & 4 deletions src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Cake\Database\Driver\Mysql as MysqlDriver;
use InvalidArgumentException;
use PDO;
use Phinx\Config\FeatureFlags;
use Phinx\Db\Table\Column;
use Phinx\Db\Table\ForeignKey;
use Phinx\Db\Table\Index;
Expand Down Expand Up @@ -285,7 +286,7 @@ public function createTable(Table $table, array $columns = [], array $indexes =
$column->setName($options['id'])
->setType('integer')
->setOptions([
'signed' => $options['signed'] ?? false,
'signed' => $options['signed'] ?? !FeatureFlags::$unsignedPrimaryKeys,
'identity' => true,
]);

Expand Down Expand Up @@ -454,7 +455,7 @@ public function truncateTable(string $tableName): void
public function getColumns(string $tableName): array
{
$columns = [];
$rows = $this->fetchAll(sprintf('SHOW COLUMNS FROM %s', $this->quoteTableName($tableName)));
$rows = $this->fetchAll(sprintf('SHOW FULL COLUMNS FROM %s', $this->quoteTableName($tableName)));
foreach ($rows as $columnInfo) {
$phinxType = $this->getPhinxType($columnInfo['Type']);

Expand All @@ -464,7 +465,8 @@ public function getColumns(string $tableName): array
->setType($phinxType['name'])
->setSigned(strpos($columnInfo['Type'], 'unsigned') === false)
->setLimit($phinxType['limit'])
->setScale($phinxType['scale']);
->setScale($phinxType['scale'])
->setComment($columnInfo['Comment']);

if ($columnInfo['Extra'] === 'auto_increment') {
$column->setIdentity(true);
Expand Down Expand Up @@ -928,7 +930,7 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr

if (empty($instructions->getAlterParts())) {
throw new InvalidArgumentException(sprintf(
"Not foreign key on columns '%s' exist",
"No foreign key on column(s) '%s' exists",
implode(',', $columns)
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ protected function getDefaultValueDefinition($default, ?string $columnType = nul
{
if ($default instanceof Literal) {
$default = (string)$default;
} elseif (is_string($default) && strpos($default, 'CURRENT_TIMESTAMP') !== 0) {
} elseif (is_string($default) && stripos($default, 'CURRENT_TIMESTAMP') !== 0) {
// Ensure a defaults of CURRENT_TIMESTAMP(3) is not quoted.
$default = $this->getConnection()->quote($default);
} elseif (is_bool($default)) {
Expand Down
Loading

0 comments on commit 8ca989d

Please sign in to comment.