Skip to content

Commit

Permalink
Merge pull request #714 from cakephp/no-phinx
Browse files Browse the repository at this point in the history
Merge in 'builtin' backend to 4.x
  • Loading branch information
markstory authored May 3, 2024
2 parents 3de99c3 + fa77f18 commit fa055cc
Show file tree
Hide file tree
Showing 162 changed files with 39,186 additions and 381 deletions.
72 changes: 71 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: matrix.db-type == 'mysql'
run: |
sudo service mysql start
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_test DEFAULT COLLATE=utf8mb4_general_ci;'
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_test CHARACTER SET = utf8mb4 DEFAULT COLLATE=utf8mb4_general_ci;'
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_comparisons;'
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp_snapshot;'
Expand Down Expand Up @@ -119,6 +119,76 @@ jobs:
if: success() && matrix.php-version == '8.1' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v4

testsuite-windows:
runs-on: windows-2022
name: Windows - PHP 8.1 & SQL Server

env:
EXTENSIONS: mbstring, intl, pdo_sqlsrv
PHP_VERSION: '8.1'

steps:
- uses: actions/checkout@v4

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Setup PHP extensions cache
id: php-ext-cache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.EXTENSIONS }}
key: ${{ steps.key-date.outputs.date }}

- name: Cache PHP extensions
uses: actions/cache@v3
with:
path: ${{ steps.php-ext-cache.outputs.dir }}
key: ${{ runner.os }}-php-ext-${{ steps.php-ext-cache.outputs.key }}
restore-keys: ${{ runner.os }}-php-ext-${{ steps.php-ext-cache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.EXTENSIONS }}
ini-values: apc.enable_cli=1, extension=php_fileinfo.dll, zend.assertions=1, error_reporting=-1, display_errors=On
coverage: pcov

- name: Setup SQLServer
run: |
# MSSQLLocalDB is the default SQL LocalDB instance
SqlLocalDB start MSSQLLocalDB
SqlLocalDB info MSSQLLocalDB
sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "create database cakephp_test;"
sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "create database cakephp_snapshot;"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: composer update

- name: Run PHPUnit
env:
DB_URL: 'sqlserver://(localdb)\MSSQLLocalDB/cakephp_test'
DB_URL_SNAPSHOT: 'sqlserver://(localdb)\MSSQLLocalDB/cakephp_snapshot'
CODECOVERAGE: 1
run: |
vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Submit code coverage
uses: codecov/codecov-action@v3

cs-stan:
uses: cakephp/.github/.github/workflows/[email protected]
secrets: inherit
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"php": ">=8.1",
"cakephp/cache": "^5.0",
"cakephp/orm": "^5.0",
"robmorgan/phinx": "^0.15.3 || ^0.16.0"
"robmorgan/phinx": "^0.16.0"
},
"require-dev": {
"cakephp/bake": "^3.0",
Expand Down
1 change: 1 addition & 0 deletions docs/en/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
:caption: CakePHP Migrations

/index
/upgrading-to-builtin-backend
57 changes: 57 additions & 0 deletions docs/en/upgrading-to-builtin-backend.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Upgrading to the builtin backend
################################

As of migrations XXX there is a new migrations backend that uses CakePHP's
database abstractions and ORM. Longer term this will allow for phinx to be
removed as a dependency. This greatly reduces the dependency footprint of
migrations.

What is the same?
=================

Your migrations shouldn't have to change much to adapt to the new backend.
The migrations backend implements all of the phinx interfaces and can run
migrations based on phinx classes. If your migrations don't work in a way that
could be addressed by the changes outlined below, please open an issue, as we'd
like to maintain as much compatibility as we can.

What is different?
==================

If your migrations are using the ``AdapterInterface`` to fetch rows or update
rows you will need to update your code. If you use ``Adapter::query()`` to
execute queries, the return of this method is now
``Cake\Database\StatementInterface`` instead. This impacts ``fetchAll()``,
and ``fetch()``::

// This
$stmt = $this->getAdapter()->query('SELECT * FROM articles');
$rows = $stmt->fetchAll();

// Now needs to be
$stmt = $this->getAdapter()->query('SELECT * FROM articles');
$rows = $stmt->fetchAll('assoc');

Similar changes are for fetching a single row::

// This
$stmt = $this->getAdapter()->query('SELECT * FROM articles');
$rows = $stmt->fetch();

// Now needs to be
$stmt = $this->getAdapter()->query('SELECT * FROM articles');
$rows = $stmt->fetch('assoc');

Enabling the new backend
========================

The new backend can be enabled through application configuration. Add the
following to your ``config/app.php``::

return [
// Other configuration.
'Migrations' => ['backend' => 'builtin'],
];

If your migrations have problems running with the builtin backend, removing this
configuration option will revert to using phinx.
50 changes: 50 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,56 @@ parameters:
count: 1
path: src/Command/BakeMigrationSnapshotCommand.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Db/Adapter/AdapterFactory.php

-
message: "#^Offset 'id' on non\\-empty\\-array\\<string, mixed\\> in isset\\(\\) always exists and is not nullable\\.$#"
count: 2
path: src/Db/Adapter/MysqlAdapter.php

-
message: "#^Right side of && is always true\\.$#"
count: 1
path: src/Db/Adapter/MysqlAdapter.php

-
message: "#^Access to an undefined property Cake\\\\Database\\\\Connection\\:\\:\\$connection\\.$#"
count: 1
path: src/Db/Adapter/PdoAdapter.php

-
message: "#^Offset 'id' on array\\<string, mixed\\> in isset\\(\\) always exists and is not nullable\\.$#"
count: 2
path: src/Db/Adapter/PostgresAdapter.php

-
message: "#^Offset 'id' on array\\<string, mixed\\> in isset\\(\\) always exists and is not nullable\\.$#"
count: 2
path: src/Db/Adapter/SqliteAdapter.php

-
message: "#^Offset 'id' on array\\<string, mixed\\> in isset\\(\\) always exists and is not nullable\\.$#"
count: 2
path: src/Db/Adapter/SqlserverAdapter.php

-
message: "#^PHPDoc tag @return with type Phinx\\\\Db\\\\Adapter\\\\AdapterInterface is not subtype of native type Migrations\\\\Db\\\\Adapter\\\\AdapterInterface\\.$#"
count: 1
path: src/Db/Adapter/SqlserverAdapter.php

-
message: "#^Ternary operator condition is always true\\.$#"
count: 2
path: src/Db/Adapter/SqlserverAdapter.php

-
message: "#^Method Migrations\\\\Shim\\\\OutputAdapter\\:\\:getVerbosity\\(\\) should return 16\\|32\\|64\\|128\\|256 but returns int\\.$#"
count: 1
path: src/Shim/OutputAdapter.php

-
message: "#^Possibly invalid array key type Cake\\\\Database\\\\Schema\\\\TableSchemaInterface\\|string\\.$#"
count: 2
Expand Down
14 changes: 10 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
colors="true"
cacheDirectory=".phpunit.cache"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
>

<testsuites>
<testsuite name="migrations">
<directory>tests/TestCase</directory>
<exclude>tests/TestCase/TestSuite</exclude>
<exclude>tests/TestCase/Migration/ManagerTest.php</exclude>
</testsuite>
<testsuite name="migrator">
<directory>tests/TestCase/TestSuite</directory>
</testsuite>
<!-- Has to run last individually as these tests drop the database -->
<testsuite name="manager">
<file>tests/TestCase/Migration/ManagerTest.php</file>
</testsuite>
</testsuites>

<extensions>
Expand All @@ -30,20 +34,22 @@
<php>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>

<!-- SQLite
<env name="DB" value="sqlite"/>
<env name="DB_URL" value="sqlite://127.0.0.1/cakephp_test"/>
<env name="DB_URL" value="sqlite://127.0.0.1/tests.sqlite"/>
<env name="DB_URL_SNAPSHOT" value="sqlite://127.0.0.1/snapshot-tests.sqlite"/>
-->
<!-- Postgres
<env name="DB" value="pgsql"/>
<env name="DB_URL" value="postgres://localhost/cake_test?timezone=UTC"/>
<env name="DB_URL_SNAPSHOT" value="postgres://localhost/cake_snapshot_test?timezone=UTC"/>
-->
<!-- Mysql
<env name="DB" value="mysql"/>
<env name="DB_URL" value="mysql://localhost/cake_test?timezone=UTC"/>
<env name="DB_URL_COMPARE" value="mysql://localhost/cake_comparison"/>
<env name="DB_URL_SNAPSHOT" value="mysql://localhost/cake_snapshot"/>
-->
</php>
</phpunit>
Loading

0 comments on commit fa055cc

Please sign in to comment.