From 9c1c1f4b7982e5c37f51eabe94b32c26d31a009e Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Fri, 26 Apr 2024 11:41:57 +0200 Subject: [PATCH 1/4] Move postFlighCheck to be called before commit transaction --- src/Phinx/Migration/Manager/Environment.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Phinx/Migration/Manager/Environment.php b/src/Phinx/Migration/Manager/Environment.php index d742e7cd4..8f65b9cd6 100644 --- a/src/Phinx/Migration/Manager/Environment.php +++ b/src/Phinx/Migration/Manager/Environment.php @@ -110,17 +110,17 @@ public function executeMigration(MigrationInterface $migration, string $directio } else { $migration->{$direction}(); } - - // commit the transaction if the adapter supports it - if ($this->getAdapter()->hasTransactions()) { - $this->getAdapter()->commitTransaction(); - } } - $migration->postFlightCheck(); - // Record it in the database $this->getAdapter()->migrated($migration, $direction, date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', time())); + + $migration->postFlightCheck(); + + // commit the transaction if the adapter supports it + if ($this->getAdapter()->hasTransactions()) { + $this->getAdapter()->commitTransaction(); + } } /** From 60b688dd3fc6d5b56639c0e0174e5a12e773e50f Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Fri, 7 Jun 2024 08:57:02 +0200 Subject: [PATCH 2/4] 2288 - Add migration version and name to pending actions error --- src/Phinx/Migration/AbstractMigration.php | 2 +- tests/Phinx/Migration/AbstractMigrationTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Migration/AbstractMigration.php b/src/Phinx/Migration/AbstractMigration.php index 9602efefc..5eb0846b6 100644 --- a/src/Phinx/Migration/AbstractMigration.php +++ b/src/Phinx/Migration/AbstractMigration.php @@ -317,7 +317,7 @@ public function postFlightCheck(): void { foreach ($this->tables as $table) { if ($table->hasPendingActions()) { - throw new RuntimeException('Migration has pending actions after execution!'); + throw new RuntimeException(sprintf('Migration %s_%s has pending actions after execution!', $this->getVersion(), $this->getName())); } } } diff --git a/tests/Phinx/Migration/AbstractMigrationTest.php b/tests/Phinx/Migration/AbstractMigrationTest.php index b617752e6..cf494f082 100644 --- a/tests/Phinx/Migration/AbstractMigrationTest.php +++ b/tests/Phinx/Migration/AbstractMigrationTest.php @@ -277,7 +277,7 @@ public function testPostFlightCheckFail() $table->addColumn('column1', 'integer', ['null' => true]); $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Migration has pending actions after execution!'); + $this->expectExceptionMessage(sprintf('Migration %s_%s has pending actions after execution!', $migrationStub->getVersion(), $migrationStub->getName())); $migrationStub->postFlightCheck(); } From 8d7f28da9af31e1a718cade59df2bcc7626e152f Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Fri, 7 Jun 2024 10:10:36 +0200 Subject: [PATCH 3/4] 2288 - Add expectedDeprecation for CakePHP 4.5 compatibility and update php version to 7.4 --- .github/workflows/ci.yml | 20 +++++++++---------- composer.json | 2 +- tests/Phinx/Db/Adapter/MysqlAdapterTest.php | 5 +++++ .../Phinx/Db/Adapter/PostgresAdapterTest.php | 5 +++++ tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 5 +++++ .../Phinx/Db/Adapter/SqlServerAdapterTest.php | 5 +++++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd51c5d74..6aa4199c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,29 +13,29 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.2', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.4', '8.0', '8.1', '8.2'] db-type: [sqlite, mysql, pgsql] prefer-lowest: [''] include: - - php-version: '7.2' + - php-version: '7.4' db-type: mysql prefer-lowest: prefer-lowest steps: - name: Setup MySQL latest - if: matrix.db-type == 'mysql' && matrix.php-version != '7.2' - run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql --default-authentication-plugin=mysql_native_password + if: matrix.db-type == 'mysql' && matrix.php-version != '7.4' + run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:8.3 --default-authentication-plugin=mysql_native_password - name: Setup MySQL 5.6 - if: matrix.db-type == 'mysql' && matrix.php-version == '7.2' + if: matrix.db-type == 'mysql' && matrix.php-version == '7.4' run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:5.6 --character-set-server=utf8 - name: Setup PostgreSQL latest - if: matrix.db-type == 'pgsql' && matrix.php-version != '7.2' + if: matrix.db-type == 'pgsql' && matrix.php-version != '7.4' run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres - name: Setup PostgreSQL 9.4 - if: matrix.db-type == 'pgsql' && matrix.php-version == '7.2' + if: matrix.db-type == 'pgsql' && matrix.php-version == '7.4' run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres:9.4 - uses: actions/checkout@v3 @@ -70,7 +70,7 @@ jobs: fi - name: Setup problem matchers for PHPUnit - if: matrix.php-version == '7.2' && matrix.db-type == 'mysql' + if: matrix.php-version == '7.4' && matrix.db-type == 'mysql' run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Setup Database @@ -109,11 +109,11 @@ jobs: testsuite-windows: runs-on: windows-2019 - name: Windows - PHP 7.2 & SQL Server + name: Windows - PHP 7.4 & SQL Server env: EXTENSIONS: pdo_sqlsrv - PHP_VERSION: '7.2' + PHP_VERSION: '7.4' steps: - uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index 18b07b3b2..73e6502e3 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=7.4.0", "cakephp/database": "^4.0", "psr/container": "^1.0 || ^2.0", "symfony/console": "^3.4|^4.0|^5.0|^6.0", diff --git a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php index 419f90aa4..f4bb5e5a6 100644 --- a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php +++ b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php @@ -2070,6 +2070,11 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); + if (method_exists(\Cake\Database\Connection::class, 'selectQuery')) { + $this->expectDeprecation(); + $this->expectExceptionMessage('As of 4.5.0, using newQuery() is deprecated. Instead, use `insertQuery()`, `deleteQuery()`, `selectQuery()` or `updateQuery()`. The query objects returned by these methods will emit deprecations that will become fatal errors in 5.0.See https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html for more information'); + } + $builder = $this->adapter->getQueryBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 6599d4e98..b5f901629 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -2415,6 +2415,11 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); + if (method_exists(\Cake\Database\Connection::class, 'selectQuery')) { + $this->expectDeprecation(); + $this->expectExceptionMessage('As of 4.5.0, using newQuery() is deprecated. Instead, use `insertQuery()`, `deleteQuery()`, `selectQuery()` or `updateQuery()`. The query objects returned by these methods will emit deprecations that will become fatal errors in 5.0.See https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html for more information'); + } + $builder = $this->adapter->getQueryBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 283030328..f8a858b0b 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -1274,6 +1274,11 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); + if (method_exists(\Cake\Database\Connection::class, 'selectQuery')) { + $this->expectDeprecation(); + $this->expectExceptionMessage('As of 4.5.0, using newQuery() is deprecated. Instead, use `insertQuery()`, `deleteQuery()`, `selectQuery()` or `updateQuery()`. The query objects returned by these methods will emit deprecations that will become fatal errors in 5.0.See https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html for more information'); + } + $builder = $this->adapter->getQueryBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index d85dcd629..985cc6a51 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -1130,6 +1130,11 @@ public function testQueryBuilder() ->addColumn('int_col', 'integer') ->save(); + if (method_exists(\Cake\Database\Connection::class, 'selectQuery')) { + $this->expectDeprecation(); + $this->expectExceptionMessage('As of 4.5.0, using newQuery() is deprecated. Instead, use `insertQuery()`, `deleteQuery()`, `selectQuery()` or `updateQuery()`. The query objects returned by these methods will emit deprecations that will become fatal errors in 5.0.See https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html for more information'); + } + $builder = $this->adapter->getQueryBuilder(); $stm = $builder ->insert(['string_col', 'int_col']) From 46cac487485fe0c4d4ba6a101609f1010852c116 Mon Sep 17 00:00:00 2001 From: Alejandro Ibarra Date: Mon, 10 Jun 2024 09:53:46 +0200 Subject: [PATCH 4/4] 2288 - Update postFlightCheckFail test to remove dynamic message --- tests/Phinx/Migration/AbstractMigrationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Phinx/Migration/AbstractMigrationTest.php b/tests/Phinx/Migration/AbstractMigrationTest.php index cf494f082..dc51f4735 100644 --- a/tests/Phinx/Migration/AbstractMigrationTest.php +++ b/tests/Phinx/Migration/AbstractMigrationTest.php @@ -262,7 +262,7 @@ public function testTableMethod() public function testPostFlightCheckFail() { // stub migration - $migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', ['mockenv', 0]); + $migrationStub = $this->getMockForAbstractClass('\Phinx\Migration\AbstractMigration', ['mockenv', 20230102030405], 'PostFlightCheck'); $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) @@ -277,7 +277,7 @@ public function testPostFlightCheckFail() $table->addColumn('column1', 'integer', ['null' => true]); $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage(sprintf('Migration %s_%s has pending actions after execution!', $migrationStub->getVersion(), $migrationStub->getName())); + $this->expectExceptionMessage('Migration 20230102030405_PostFlightCheck has pending actions after execution!'); $migrationStub->postFlightCheck(); }