Skip to content

Commit

Permalink
Merge branch '4.x' into 4.next
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 23, 2024
2 parents 19144eb + f68024a commit 706eaf4
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
- name: Code Coverage Report
if: success() && matrix.php-version == '8.1' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5

testsuite-windows:
runs-on: windows-2022
Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Submit code coverage
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5

cs-stan:
uses: cakephp/.github/.github/workflows/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.11.9" installed="1.11.9" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.25.0" installed="5.25.0" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="2.0.1" installed="2.0.1" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.26.1" installed="5.26.1" location="./tools/psalm" copy="false"/>
</phive>
5 changes: 0 additions & 5 deletions .stickler.yml

This file was deleted.

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bin/cake plugin load Migrations
```
Or you can manually add the loading statement in the **src/Application.php** file of your application:
```php
public function bootstrap(): void
{
Expand All @@ -37,7 +38,20 @@ public function bootstrap(): void
}
```

Additionally, you will need to configure the ``default`` database configuration in your **config/app.php** file.
### Enabling the builtin backend

In a future release, migrations will be switching to a new backend based on the CakePHP ORM. We're aiming
to be compatible with as many existing migrations as possible, and could use your feedback. Enable the
new backend with:

```php
// in app/config/app_local.php
$config = [
// Other configuration
'Migrations' => ['backend' => 'builtin'],
];

```

## Documentation

Expand Down
17 changes: 9 additions & 8 deletions docs/en/upgrading-to-builtin-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Upgrading to the builtin backend
################################

As of migrations 4.3 there is a new migrations backend that uses CakePHP's
database abstractions and ORM. Longer term this will allow for phinx to be
database abstractions and ORM. In 4.4, the ``builtin`` backend became the
default backend. Longer term this will allow for phinx to be
removed as a dependency. This greatly reduces the dependency footprint of
migrations.

Expand Down Expand Up @@ -42,16 +43,16 @@ Similar changes are for fetching a single row::
$stmt = $this->getAdapter()->query('SELECT * FROM articles');
$rows = $stmt->fetch('assoc');

Enabling the new backend
========================
Problems with the new backend?
==============================

The new backend can be enabled through application configuration. Add the
The new backend is enabled by default. If your migrations contain errors when
run with the builtin backend, please open `an issue
<https://github.com/cakephp/migrations/issues/new>`_. You can also switch back
to the ``phinx`` backend through application configuration. Add the
following to your ``config/app.php``::

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

If your migrations have problems running with the builtin backend, removing this
configuration option will revert to using phinx.
140 changes: 119 additions & 21 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,71 +1,169 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method object\\:\\:loadHelper\\(\\)\\.$#"
message: '#^Call to an undefined method object\:\:loadHelper\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Command/BakeMigrationCommand.php

-
message: "#^Call to an undefined method object\\:\\:loadHelper\\(\\)\\.$#"
message: '#^Parameter \#1 \$arguments of method Migrations\\Util\\ColumnParser\:\:parseFields\(\) expects array\<string\>, array\<int\<min, \-1\>\|int\<1, max\>, list\<string\>\|string\> given\.$#'
identifier: argument.type
count: 1
path: src/Command/BakeMigrationCommand.php

-
message: '#^Parameter \#1 \$arguments of method Migrations\\Util\\ColumnParser\:\:parseIndexes\(\) expects array\<string\>, array\<int\<min, \-1\>\|int\<1, max\>, list\<string\>\|string\> given\.$#'
identifier: argument.type
count: 1
path: src/Command/BakeMigrationCommand.php

-
message: '#^Parameter \#1 \$arguments of method Migrations\\Util\\ColumnParser\:\:parsePrimaryKey\(\) expects array\<string\>, array\<int\<min, \-1\>\|int\<1, max\>, list\<string\>\|string\> given\.$#'
identifier: argument.type
count: 1
path: src/Command/BakeMigrationCommand.php

-
message: '#^Call to an undefined method object\:\:loadHelper\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Command/BakeMigrationDiffCommand.php

-
message: "#^Call to an undefined method object\\:\\:loadHelper\\(\\)\\.$#"
message: '#^Call to an undefined method object\:\:loadHelper\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Command/BakeMigrationSnapshotCommand.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
message: '#^PHPDoc tag @var with type string is not subtype of native type non\-falsy\-string\|true\.$#'
identifier: varTag.nativeType
count: 1
path: src/Command/BakeSeedCommand.php

-
message: '#^Strict comparison using \!\=\= between string and false will always evaluate to true\.$#'
identifier: notIdentical.alwaysTrue
count: 1
path: src/Command/BakeSeedCommand.php

-
message: '#^Call to an undefined method Cake\\Datasource\\ConnectionInterface\:\:cacheMetadata\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Command/Phinx/CacheBuild.php

-
message: '#^Call to an undefined method Cake\\Datasource\\ConnectionInterface\:\:cacheMetadata\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Command/Phinx/CacheClear.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: 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\\.$#"
message: '#^Offset ''id'' on non\-empty\-array\<string, mixed\> in isset\(\) always exists and is not nullable\.$#'
identifier: isset.offset
count: 2
path: src/Db/Adapter/MysqlAdapter.php

-
message: "#^Right side of && is always true\\.$#"
message: '#^Offset 3 might not exist on array\{0\: string, 1\: non\-empty\-string, 2\?\: string, 3\?\: ''''\|numeric\-string, 4\?\: string, 5\?\: ''''\|numeric\-string, 6\?\: non\-empty\-string\}\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Db/Adapter/MysqlAdapter.php

-
message: "#^Access to an undefined property Cake\\\\Database\\\\Connection\\:\\:\\$connection\\.$#"
message: '#^Offset 5 might not exist on array\{0\: string, 1\: non\-empty\-string, 2\?\: string, 3\?\: ''''\|numeric\-string, 4\?\: string, 5\?\: ''''\|numeric\-string, 6\?\: non\-empty\-string\}\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Db/Adapter/PdoAdapter.php
path: src/Db/Adapter/MysqlAdapter.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 6 might not exist on array\{0\: string, 1\: non\-empty\-string, 2\?\: string, 3\?\: ''''\|numeric\-string, 4\?\: string, 5\?\: ''''\|numeric\-string, 6\?\: non\-empty\-string\}\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Db/Adapter/MysqlAdapter.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: '#^Right side of && is always true\.$#'
identifier: booleanAnd.rightAlwaysTrue
count: 1
path: src/Db/Adapter/MysqlAdapter.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: '#^Right side of && is always true\.$#'
identifier: booleanAnd.rightAlwaysTrue
count: 1
path: src/Db/Adapter/SqliteAdapter.php

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

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

-
message: "#^Method Migrations\\\\Shim\\\\OutputAdapter\\:\\:getVerbosity\\(\\) should return 16\\|32\\|64\\|128\\|256 but returns int\\.$#"
message: '#^Parameter \#1 \$message of method Cake\\Console\\ConsoleIo\:\:verbose\(\) expects list\<string\>\|string, array\<non\-falsy\-string\> given\.$#'
identifier: argument.type
count: 1
path: src/Migration/Manager.php

-
message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, array given\.$#'
identifier: argument.type
count: 1
path: src/Migration/Manager.php

-
message: '#^PHPDoc tag @var with type array\<string, string\> is not subtype of native type mixed\.$#'
identifier: varTag.nativeType
count: 1
path: src/Migration/ManagerFactory.php

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

-
message: "#^Possibly invalid array key type Cake\\\\Database\\\\Schema\\\\TableSchemaInterface\\|string\\.$#"
message: '#^Parameter \#1 \$message of method Cake\\Console\\ConsoleIo\:\:out\(\) expects list\<string\>\|string, array\|string given\.$#'
identifier: argument.type
count: 2
path: src/Shim/OutputAdapter.php

-
message: '#^Parameter \#2 \$tables of method Cake\\TestSuite\\ConnectionHelper\:\:dropTables\(\) expects list\<string\>\|null, non\-empty\-array\<string\> given\.$#'
identifier: argument.type
count: 1
path: src/TestSuite/Migrator.php

-
message: '#^Parameter \#2 \$tables of method Cake\\TestSuite\\ConnectionHelper\:\:truncateTables\(\) expects list\<string\>\|null, non\-empty\-array\<string\> given\.$#'
identifier: argument.type
count: 2
path: src/TestSuite/Migrator.php

-
message: '#^Offset 0 on non\-empty\-list\<string\> in isset\(\) always exists and is not nullable\.$#'
identifier: isset.offset
count: 2
path: src/Util/TableFinder.php

-
message: '#^Possibly invalid array key type Cake\\Database\\Schema\\TableSchemaInterface\|string\.$#'
identifier: offsetAccess.invalidOffset
count: 2
path: src/View/Helper/MigrationHelper.php
26 changes: 26 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<DeprecatedTrait>
<code><![CDATA[ConfigurationTrait]]></code>
</DeprecatedTrait>
<PossiblyNullReference>
<code><![CDATA[getVersionsToMark]]></code>
<code><![CDATA[markVersionsAsMigrated]]></code>
</PossiblyNullReference>
</file>
<file src="src/Command/Phinx/Migrate.php">
<DeprecatedTrait>
Expand All @@ -82,6 +86,23 @@
<DeprecatedTrait>
<code><![CDATA[ConfigurationTrait]]></code>
</DeprecatedTrait>
<PossiblyNullArgument>
<code><![CDATA[$maxNameLength]]></code>
</PossiblyNullArgument>
<PossiblyNullPropertyFetch>
<code><![CDATA[$this->getManager()->maxNameLength]]></code>
</PossiblyNullPropertyFetch>
<PossiblyNullReference>
<code><![CDATA[getConfig]]></code>
<code><![CDATA[getOutput]]></code>
<code><![CDATA[getOutput]]></code>
<code><![CDATA[printStatus]]></code>
</PossiblyNullReference>
</file>
<file src="src/Command/SeedCommand.php">
<DeprecatedMethod>
<code><![CDATA[getMultipleOption]]></code>
</DeprecatedMethod>
</file>
<file src="src/Command/SeedCommand.php">
<DeprecatedMethod>
Expand Down Expand Up @@ -224,4 +245,9 @@
<code><![CDATA[$this->regexpParseField]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Util/SchemaTrait.php">
<PossiblyUndefinedMethod>
<code><![CDATA[cacheMetadata]]></code>
</PossiblyUndefinedMethod>
</file>
</files>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="./psalm-baseline.xml"
errorBaseline="psalm-baseline.xml"
autoloader="tests/bootstrap.php"
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
Expand Down
2 changes: 0 additions & 2 deletions src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

/**
* Task class for generating migration diff files.
*
* @property \Bake\Shell\Task\TestTask $Test
*/
class BakeMigrationDiffCommand extends BakeSimpleMigrationCommand
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Phinx/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->output($output);

$path = $this->getOperationsPath($input);
/** @var string $connectionName */
$connectionName = $input->getOption('connection') ?: 'default';
assert(is_string($connectionName), 'Connection name must be a string');
$connection = ConnectionManager::get($connectionName);
assert($connection instanceof Connection);
$collection = $connection->getSchemaCollection();
Expand Down
1 change: 0 additions & 1 deletion src/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public function getConnection(): Connection
$this->connect();
}

/** @var \Cake\Database\Connection $this->connection */
return $this->connection;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ public function createTable(Table $table, array $columns = [], array $indexes =
$parts = $this->getSchemaName($table->getName());

// Add the default primary key
if (!isset($options['id']) || (isset($options['id']) && $options['id'] === true)) {
if (!isset($options['id']) || $options['id'] === true) {
$options['id'] = 'id';
}

if (isset($options['id']) && is_string($options['id'])) {
if (is_string($options['id'])) {
// Handle id => "field_name" to support AUTO_INCREMENT
$column = new Column();
$column->setName($options['id'])
Expand Down
4 changes: 2 additions & 2 deletions src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ public function createTable(Table $table, array $columns = [], array $indexes =
{
// Add the default primary key
$options = $table->getOptions();
if (!isset($options['id']) || (isset($options['id']) && $options['id'] === true)) {
if (!isset($options['id']) || ($options['id'] === true)) {
$options['id'] = 'id';
}

if (isset($options['id']) && is_string($options['id'])) {
if (is_string($options['id'])) {
// Handle id => "field_name" to support AUTO_INCREMENT
$column = new Column();
$column->setName($options['id'])
Expand Down
Loading

0 comments on commit 706eaf4

Please sign in to comment.