Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ permissions:
jobs:
testsuite-linux:
runs-on: ubuntu-22.04
continue-on-error: ${{ matrix.php-version == '8.6' }}
strategy:
fail-fast: false
matrix:
php-version: ['8.4', '8.5']
php-version: ['8.5', '8.6']
db-type: [mariadb, mysql, pgsql, sqlite]
prefer-lowest: ['']
legacy-tables: ['']
include:
- php-version: '8.4'
- php-version: '8.5'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'
- php-version: '8.4'
db-type: 'mysql'
- php-version: '8.4'
db-type: 'pgsql'
# Test unified cake_migrations table (non-legacy mode)
- php-version: '8.4'
- php-version: '8.5'
db-type: 'mysql'
legacy-tables: 'false'
services:
Expand Down Expand Up @@ -108,7 +105,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
coverage: pcov
coverage: ${{ matrix.php-version == '8.5' && 'pcov' || 'none' }}

- name: Get composer cache directory
id: composer-cache
Expand All @@ -128,6 +125,8 @@ jobs:
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
elif [[ ${{ matrix.php-version }} == '8.6' ]]; then
composer update --ignore-platform-req=php+
else
composer update
fi
Expand All @@ -139,9 +138,9 @@ jobs:
fi
if [[ ${{ matrix.db-type }} == 'mariadb' ]]; then
export DB='mysql'
export DB_URL='mysql://root:root@127.0.0.1/cakephp_test'
export DB_URL_COMPARE='mysql://root:root@127.0.0.1/cakephp_comparisons'
export DB_URL_SNAPSHOT='mysql://root:root@127.0.0.1/cakephp_snapshot'
export DB_URL='mariadb://root:root@127.0.0.1/cakephp_test'
export DB_URL_COMPARE='mariadb://root:root@127.0.0.1/cakephp_comparisons'
export DB_URL_SNAPSHOT='mariadb://root:root@127.0.0.1/cakephp_snapshot'
fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
export DB='mysql'
Expand All @@ -157,23 +156,23 @@ jobs:
if [[ -n '${{ matrix.legacy-tables }}' ]]; then
export LEGACY_TABLES='${{ matrix.legacy-tables }}'
fi
if [[ ${{ matrix.php-version }} == '8.4' && ${{ matrix.db-type }} == 'mysql' ]]; then
if [[ ${{ matrix.php-version }} == '8.5' && ${{ matrix.db-type }} == 'mysql' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Code Coverage Report
if: success() && matrix.php-version == '8.4' && matrix.db-type == 'mysql'
if: success() && matrix.php-version == '8.5' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v7

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

env:
EXTENSIONS: mbstring, intl, pdo_sqlsrv
PHP_VERSION: '8.4'
PHP_VERSION: '8.5'

steps:
- uses: actions/checkout@v7
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is a Database Migrations system for CakePHP.

The plugin provides a complete database migration solution with support for creating, running, and managing migrations.

This branch is for use with CakePHP **6.x**, requiring PHP 8.4 or higher. See [version map](https://github.com/cakephp/migrations/wiki#version-map) for details.
This branch is for use with CakePHP **6.x**, requiring PHP 8.5 or higher. See [version map](https://github.com/cakephp/migrations/wiki#version-map) for details.

When upgrading from CakePHP 5, regenerate schema dump files with `bin/cake migrations dump`
before baking a diff. Serialized schema metadata uses CakePHP 6's property names.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"source": "https://github.com/cakephp/migrations"
},
"require": {
"php": ">=8.4",
"php": ">=8.5",
"cakephp/cache": "^6.0",
"cakephp/database": "^6.0",
"cakephp/orm": "^6.0"
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Migrations\Util\UtilTrait;
use ReflectionException;
use ReflectionProperty;
use function Cake\Database\Expression\equals;

/**
* Task class for generating migration diff files.
Expand Down Expand Up @@ -172,7 +173,7 @@ protected function setup(): void

// In unified table mode, filter by the current plugin context
if ($this->phinxTable === UnifiedMigrationsTableStorage::TABLE_NAME) {
$query->where(['plugin IS' => $this->plugin]);
$query->where(['plugin' => equals($this->plugin)]);
}

$migratedItems = $query->execute()->fetchAll('assoc');
Expand Down
7 changes: 4 additions & 3 deletions src/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
use PDOException;
use RuntimeException;
use function Cake\Core\deprecationWarning;
use function Cake\Database\Expression\equals;

/**
* Base Abstract Database Adapter.
Expand Down Expand Up @@ -1125,11 +1126,11 @@ public function removeSeedFromLog(SeedInterface $seed): AdapterInterface
if ($plugin !== null) {
// Also remove entries logged before plugin attribution was fixed.
$conditions['OR'] = [
'plugin' => $plugin,
'plugin IS' => null,
['plugin' => $plugin],
['plugin' => equals(null)],
];
} else {
$conditions['plugin IS'] = null;
$conditions['plugin'] = equals(null);
}

$query = $this->getDeleteBuilder();
Expand Down
1 change: 1 addition & 0 deletions src/Db/Adapter/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function instance(): static
* @phpstan-var array<string, class-string<\Migrations\Db\Adapter\AdapterInterface>|\Closure>
*/
protected array $adapters = [
'mariadb' => MariadbAdapter::class,
'mysql' => MysqlAdapter::class,
'postgres' => PostgresAdapter::class,
'sqlite' => SqliteAdapter::class,
Expand Down
42 changes: 42 additions & 0 deletions src/Db/Adapter/MariadbAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

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

namespace Migrations\Db\Adapter;

use Cake\Database\Connection;
use Migrations\Db\AlterInstructions;

/**
* MariaDB adapter.
*/
class MariadbAdapter extends MysqlAdapter
{
/**
* @inheritDoc
*/
protected function getDropCheckConstraintInstructions(string $tableName, string $constraintName): AlterInstructions
{
$alter = sprintf('DROP CONSTRAINT %s', $this->quoteColumnName($constraintName));

return new AlterInstructions([$alter]);
}

/**
* @inheritDoc
*/
protected function hasNativeUuid(): bool
{
// Avoid connecting when an adapter without a configured connection is used as a stub.
if (!$this->connection instanceof Connection || !$this->getOption('connection')) {
return false;
}
$version = $this->getConnection()->getDriver()->version();

return version_compare($version, '10.7', '>=');
}
}
6 changes: 4 additions & 2 deletions src/Db/Adapter/MigrationsTableStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use InvalidArgumentException;
use Migrations\Db\Table;
use Migrations\MigrationInterface;
use function Cake\Database\Expression\in;
use function Cake\Database\Expression\notEquals;

/**
* Backwards compatibility layer for migration table storage.
Expand Down Expand Up @@ -72,7 +74,7 @@ public function cleanupMissing(array $missingVersions): void
{
$this->adapter->beginTransaction();
try {
$where = ['version IN' => $missingVersions];
$where = ['version' => in($missingVersions)];
$delete = $this->adapter->getDeleteBuilder()
->from($this->schemaTableName)
->where($where);
Expand Down Expand Up @@ -159,7 +161,7 @@ public function resetAllBreakpoints(): int
'start_time' => $query->identifier('start_time'),
])
->where([
'breakpoint !=' => 0,
'breakpoint' => notEquals(0),
]);

return $this->adapter->executeQuery($query);
Expand Down
36 changes: 2 additions & 34 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,14 +1146,7 @@ protected function getAddCheckConstraintInstructions(TableMetadata $table, Check
*/
protected function getDropCheckConstraintInstructions(string $tableName, string $constraintName): AlterInstructions
{
// MariaDB uses DROP CONSTRAINT, MySQL uses DROP CHECK
$keyword = $this->isMariaDb() ? 'CONSTRAINT' : 'CHECK';

$alter = sprintf(
'DROP %s %s',
$keyword,
$this->quoteColumnName($constraintName),
);
$alter = sprintf('DROP CHECK %s', $this->quoteColumnName($constraintName));

return new AlterInstructions([$alter]);
}
Expand Down Expand Up @@ -1573,37 +1566,12 @@ protected function getAddPartitionSql(PartitionDefinition $partition): string

/**
* Whether the server has a native uuid type.
* (MariaDB 10.7.0+)
*
* @return bool
*/
protected function hasNativeUuid(): bool
{
// Prevent infinite connect() loop when MysqlAdapter is used as a stub.
if (!$this->connection instanceof Connection || !$this->getOption('connection')) {
return false;
}
$connection = $this->getConnection();
$version = $connection->getDriver()->version();

return version_compare($version, '10.7', '>=');
}

/**
* Whether the server is MariaDB (as opposed to MySQL).
*
* @return bool
*/
protected function isMariaDb(): bool
{
// Prevent infinite connect() loop when MysqlAdapter is used as a stub.
if (!$this->connection instanceof Connection || !$this->getOption('connection')) {
return false;
}
$connection = $this->getConnection();
$version = $connection->getDriver()->version();

return stripos($version, 'mariadb') !== false;
return false;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Migrations\Db\Table\Trigger;
use Migrations\Db\Table\View;
use RuntimeException;
use function Cake\Database\Expression\comparison;
use function Cake\Database\Expression\notEquals;

class PostgresAdapter extends AbstractAdapter
{
Expand Down Expand Up @@ -1153,8 +1155,8 @@ public function getAllSchemas(): array
$query->select(['schema_name'])
->from('information_schema.schemata')
->where([
['schema_name !=' => 'information_schema'],
['schema_name !~' => '^pg_'],
['schema_name' => notEquals('information_schema')],
['schema_name' => comparison('!~', '^pg_')],
]);
$items = $query->execute()->fetchAll('assoc');
$schemaNames = [];
Expand Down
6 changes: 4 additions & 2 deletions src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use Migrations\Db\Table\View;
use PDOException;
use RuntimeException;
use function Cake\Database\Expression\in;
use function Cake\Database\Expression\isNotNull;
use const FILTER_VALIDATE_BOOLEAN;

/**
Expand Down Expand Up @@ -693,9 +695,9 @@ protected function bufferIndicesAndTriggers(AlterInstructions $instructions, str
->select('*')
->from('sqlite_master')
->where([
'type IN' => ['index', 'trigger'],
'type' => in(['index', 'trigger']),
'tbl_name' => $tableName,
'sql IS NOT' => null,
'sql' => isNotNull(),
]);
$rows = $query->execute()->fetchAll('assoc');

Expand Down
17 changes: 10 additions & 7 deletions src/Db/Adapter/UnifiedMigrationsTableStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use InvalidArgumentException;
use Migrations\Db\Table;
use Migrations\MigrationInterface;
use function Cake\Database\Expression\equals;
use function Cake\Database\Expression\in;
use function Cake\Database\Expression\notEquals;

/**
* Unified migration table storage.
Expand Down Expand Up @@ -59,8 +62,8 @@ public function cleanupMissing(array $missingVersions): void
{
$this->adapter->beginTransaction();
try {
$where = ['version IN' => $missingVersions];
$where['plugin IS'] = $this->adapter->getOption('plugin');
$where = ['version' => in($missingVersions)];
$where['plugin'] = equals($this->adapter->getOption('plugin'));

$delete = $this->adapter->getDeleteBuilder()
->from(self::TABLE_NAME)
Expand All @@ -84,7 +87,7 @@ public function getVersions(array $orderBy): SelectQuery
$query = $this->adapter->getSelectBuilder();
$query->select('*')
->from(self::TABLE_NAME)
->where(['plugin IS' => $this->plugin])
->where(['plugin' => equals($this->plugin)])
->orderBy($orderBy);

return $query;
Expand Down Expand Up @@ -127,7 +130,7 @@ public function recordDown(MigrationInterface $migration): void
->from(self::TABLE_NAME)
->where([
'version' => (string)$migration->getVersion(),
'plugin IS' => $this->plugin,
'plugin' => equals($this->plugin),
]);

$this->adapter->executeQuery($query);
Expand Down Expand Up @@ -176,8 +179,8 @@ public function resetAllBreakpoints(): int
'start_time' => $query->identifier('start_time'),
])
->where([
'breakpoint !=' => 0,
'plugin IS' => $this->plugin,
'breakpoint' => notEquals(0),
'plugin' => equals($this->plugin),
]);

return $this->adapter->executeQuery($query);
Expand All @@ -200,7 +203,7 @@ public function markBreakpoint(MigrationInterface $migration, bool $state): void
])
->where([
'version' => $migration->getVersion(),
'plugin IS' => $this->plugin,
'plugin' => equals($this->plugin),
]);

$this->adapter->executeQuery($query);
Expand Down
Loading
Loading