Skip to content

Commit f49eadd

Browse files
authored
5.x - Require cakephp 5.3 and remove remaining symfony references (#888)
Use the dev branch as 5.3 release hasn't started yet, but I'd like to validate the new reflection API by integrating it into migrations. * Remove remaining references to symfony classes. * Fix failing tests. * Remove unused cake_version block and update php version cakephp 5.3 requires 8.2 * Update deps to align with cakephp version * Don't ignore php versions * Fix expected SQL * Fix regression with postgres schema generation * Fix deprecation warnings from plugin classes * Restore jsonb column constant and update windows php version * Fix failing identity column tests cakephp/database does not support `identity => true, generated => null` as a way to remove identity clauses on columns, as `generated => null` is the default value which for identity columns ~= 'by default'. Fix and re-enable the identity column tests as cakephp 5.3 will have identity column support.
1 parent 93e536b commit f49eadd

File tree

15 files changed

+58
-527
lines changed

15 files changed

+58
-527
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
php-version: ['8.1', '8.4']
23+
php-version: ['8.2', '8.4']
2424
db-type: [mariadb, mysql, pgsql, sqlite]
2525
prefer-lowest: ['']
26-
cake_version: ['']
2726
include:
28-
- php-version: '8.1'
27+
- php-version: '8.2'
2928
db-type: 'sqlite'
3029
prefer-lowest: 'prefer-lowest'
3130
- php-version: '8.3'
@@ -106,13 +105,9 @@ jobs:
106105
- name: Composer install
107106
run: |
108107
if [[ ${{ matrix.php-version }} == '8.2' || ${{ matrix.php-version }} == '8.3' || ${{ matrix.php-version }} == '8.4' ]]; then
109-
composer install --ignore-platform-req=php
108+
composer install
110109
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
111110
composer update --prefer-lowest --prefer-stable
112-
elif ${{ matrix.cake_version != '' }}; then
113-
composer require --dev "cakephp/cakephp:${{ matrix.cake_version }}"
114-
composer require --dev --with-all-dependencies "cakephp/bake:dev-3.next as 3.1.0"
115-
composer update
116111
else
117112
composer update
118113
fi
@@ -151,11 +146,11 @@ jobs:
151146

152147
testsuite-windows:
153148
runs-on: windows-2022
154-
name: Windows - PHP 8.1 & SQL Server
149+
name: Windows - PHP 8.2 & SQL Server
155150

156151
env:
157152
EXTENSIONS: mbstring, intl, pdo_sqlsrv
158-
PHP_VERSION: '8.1'
153+
PHP_VERSION: '8.2'
159154

160155
steps:
161156
- uses: actions/checkout@v5

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
"source": "https://github.com/cakephp/migrations"
2323
},
2424
"require": {
25-
"php": ">=8.1",
26-
"cakephp/cache": "^5.2",
27-
"cakephp/orm": "^5.2",
28-
"symfony/config": "^6.0 || ^7.0",
29-
"symfony/console": "^6.0 || ^7.0"
25+
"php": ">=8.2",
26+
"cakephp/cache": "dev-5.next as 5.3.0",
27+
"cakephp/orm": "dev-5.next as 5.3.0"
3028
},
3129
"require-dev": {
3230
"cakephp/bake": "^3.3",
33-
"cakephp/cakephp": "^5.2.5",
31+
"cakephp/cakephp": "dev-5.next as 5.3.0",
3432
"cakephp/cakephp-codesniffer": "^5.0",
35-
"phpunit/phpunit": "^10.5.5 || ^11.1.3 || ^12.2.4"
33+
"phpunit/phpunit": "^11.5.3 || ^12.1.3"
3634
},
3735
"suggest": {
3836
"cakephp/bake": "If you want to generate migrations.",
@@ -51,7 +49,9 @@
5149
"Migrations\\Test\\": "tests/",
5250
"SimpleSnapshot\\": "tests/test_app/Plugin/SimpleSnapshot/src/",
5351
"TestApp\\": "tests/test_app/App/",
54-
"TestBlog\\": "tests/test_app/Plugin/TestBlog/src/"
52+
"TestBlog\\": "tests/test_app/Plugin/TestBlog/src/",
53+
"Blog\\": "tests/test_app/Plugin/Blog/src/",
54+
"Migrator\\": "tests/test_app/Plugin/Migrator/src/"
5555
}
5656
},
5757
"config": {

src/Db/Adapter/AbstractAdapter.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@
4242
use Migrations\Db\Table\Index;
4343
use Migrations\Db\Table\Table as TableMetadata;
4444
use Migrations\MigrationInterface;
45-
use Migrations\Shim\OutputAdapter;
4645
use PDOException;
4746
use RuntimeException;
48-
use Symfony\Component\Console\Input\InputInterface;
49-
use Symfony\Component\Console\Output\OutputInterface;
5047

5148
/**
5249
* Base Abstract Database Adapter.
@@ -300,38 +297,6 @@ protected function verboseLog(string $message): void
300297
$io->out($message);
301298
}
302299

303-
/**
304-
* @inheritDoc
305-
*/
306-
public function setInput(InputInterface $input): AdapterInterface
307-
{
308-
throw new RuntimeException('Using setInput() interface is not supported.');
309-
}
310-
311-
/**
312-
* @inheritDoc
313-
*/
314-
public function getInput(): ?InputInterface
315-
{
316-
throw new RuntimeException('Using getInput() interface is not supported.');
317-
}
318-
319-
/**
320-
* @inheritDoc
321-
*/
322-
public function setOutput(OutputInterface $output): AdapterInterface
323-
{
324-
throw new RuntimeException('Using setInput() method is not supported');
325-
}
326-
327-
/**
328-
* @inheritDoc
329-
*/
330-
public function getOutput(): OutputInterface
331-
{
332-
return new OutputAdapter($this->io);
333-
}
334-
335300
/**
336301
* Gets the schema table name.
337302
*

src/Db/Adapter/AdapterInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ interface AdapterInterface
4242
public const PHINX_TYPE_BINARYUUID = TableSchemaInterface::TYPE_BINARY_UUID;
4343
public const PHINX_TYPE_BOOLEAN = TableSchemaInterface::TYPE_BOOLEAN;
4444
public const PHINX_TYPE_JSON = TableSchemaInterface::TYPE_JSON;
45+
/**
46+
* @deprecated 5.0.0 Use TableSchemaInterface::TYPE_JSON instead.
47+
*/
48+
public const PHINX_TYPE_JSONB = 'jsonb';
4549
public const PHINX_TYPE_UUID = TableSchemaInterface::TYPE_UUID;
4650
public const PHINX_TYPE_NATIVEUUID = TableSchemaInterface::TYPE_NATIVE_UUID;
4751

src/Db/Adapter/PostgresAdapter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class PostgresAdapter extends AbstractAdapter
3535
*/
3636
protected static array $specificColumnTypes = [
3737
self::PHINX_TYPE_JSON,
38+
self::PHINX_TYPE_JSONB,
3839
self::PHINX_TYPE_CIDR,
3940
self::PHINX_TYPE_INET,
4041
self::PHINX_TYPE_MACADDR,
@@ -454,6 +455,8 @@ protected function getChangeColumnInstructions(
454455
$columnSql = $dialect->columnDefinitionSql($this->mapColumnData($newColumn->toArray()));
455456
// Remove the column name from $columnSql
456457
$columnType = preg_replace('/^"?(?:[^"]+)"?\s+/', '', $columnSql);
458+
// Remove generated clause
459+
$columnType = preg_replace('/GENERATED (?:ALWAYS|BY DEFAULT) AS IDENTITY/', '', $columnType);
457460

458461
$sql = sprintf(
459462
'ALTER COLUMN %s TYPE %s',

src/Db/Table/Column.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ public function toArray(): array
834834
'length' => $length,
835835
'null' => $this->getNull(),
836836
'default' => $default,
837+
'generated' => $this->getGenerated(),
837838
'unsigned' => !$this->getSigned(),
838839
'onUpdate' => $this->getUpdate(),
839840
'collate' => $this->getCollation(),

src/Migrations.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,13 @@
1515

1616
use Migrations\Migration\BackendInterface;
1717
use Migrations\Migration\BuiltinBackend;
18-
use Symfony\Component\Console\Input\ArrayInput;
19-
use Symfony\Component\Console\Input\InputInterface;
20-
use Symfony\Component\Console\Output\NullOutput;
21-
use Symfony\Component\Console\Output\OutputInterface;
2218

2319
/**
2420
* The Migrations class is responsible for handling migrations command
2521
* within a non-shell application.
2622
*/
2723
class Migrations
2824
{
29-
/**
30-
* The OutputInterface.
31-
* Should be a \Symfony\Component\Console\Output\NullOutput instance
32-
*
33-
* @var \Symfony\Component\Console\Output\OutputInterface
34-
*/
35-
protected OutputInterface $output;
36-
3725
/**
3826
* Default options to use
3927
*
@@ -50,14 +38,6 @@ class Migrations
5038
*/
5139
protected string $command;
5240

53-
/**
54-
* Stub input to feed the manager class since we might not have an input ready when we get the Manager using
55-
* the `getManager()` method
56-
*
57-
* @var \Symfony\Component\Console\Input\ArrayInput
58-
*/
59-
protected ArrayInput $stubInput;
60-
6141
/**
6242
* Constructor
6343
*
@@ -69,9 +49,6 @@ class Migrations
6949
*/
7050
public function __construct(array $default = [])
7151
{
72-
$this->output = new NullOutput();
73-
$this->stubInput = new ArrayInput([]);
74-
7552
if ($default) {
7653
$this->default = $default;
7754
}
@@ -195,51 +172,4 @@ public function seed(array $options = []): bool
195172

196173
return $backend->seed($options);
197174
}
198-
199-
/**
200-
* Get the input needed for each commands to be run
201-
*
202-
* TODO(mark) Remove as part of phinx removal
203-
*
204-
* @param string $command Command name for which we need the InputInterface
205-
* @param array<string, mixed> $arguments Simple key/values array representing the command arguments
206-
* to pass to the InputInterface
207-
* @param array<string, mixed> $options Simple key/values array representing the command options
208-
* to pass to the InputInterface
209-
* @return \Symfony\Component\Console\Input\InputInterface InputInterface needed for the
210-
* Manager to properly run
211-
*/
212-
public function getInput(string $command, array $arguments, array $options): InputInterface
213-
{
214-
$className = 'Migrations\Command\\' . $command;
215-
$options = $arguments + $this->prepareOptions($options);
216-
/** @var \Symfony\Component\Console\Command\Command $command */
217-
$command = new $className();
218-
$definition = $command->getDefinition();
219-
220-
return new ArrayInput($options, $definition);
221-
}
222-
223-
/**
224-
* Prepares the option to pass on to the InputInterface
225-
*
226-
* TODO(mark) Remove as part of phinx removal
227-
*
228-
* @param array<string, mixed> $options Simple key-values array to pass to the InputInterface
229-
* @return array<string, mixed> Prepared $options
230-
*/
231-
protected function prepareOptions(array $options = []): array
232-
{
233-
$options += $this->default;
234-
if (!$options) {
235-
return $options;
236-
}
237-
238-
foreach ($options as $name => $value) {
239-
$options['--' . $name] = $value;
240-
unset($options[$name]);
241-
}
242-
243-
return $options;
244-
}
245175
}

0 commit comments

Comments
 (0)