From 6ad810d3e200e241540ecff7096adaa707ed38dc Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Wed, 10 Jan 2024 12:03:04 +0200 Subject: [PATCH] Add PrintChanges instead of ShowChanges --- composer.json | 2 +- .../Command/CycleOrm/Generator/ShowChanges.php | 3 +++ src/Console/Command/CycleOrm/MigrateCommand.php | 6 +++--- src/Console/Command/CycleOrm/SyncCommand.php | 8 ++++---- .../Command/CycleOrm/MigrateCommandTest.php | 14 +++++++------- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 17a23e0..d2fc9fb 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "cycle/orm": "^2.0.2", "cycle/schema-migrations-generator": "^2.1", "cycle/schema-renderer": "^1.2", - "cycle/schema-builder": "^2.6", + "cycle/schema-builder": "^2.7", "doctrine/inflector": "^1.4 || ^2.0", "spiral/attributes": "^2.10 || ^3.0", "spiral/reactor": "^3.0", diff --git a/src/Console/Command/CycleOrm/Generator/ShowChanges.php b/src/Console/Command/CycleOrm/Generator/ShowChanges.php index 7591983..2c29159 100644 --- a/src/Console/Command/CycleOrm/Generator/ShowChanges.php +++ b/src/Console/Command/CycleOrm/Generator/ShowChanges.php @@ -10,6 +10,9 @@ use Cycle\Database\Schema\AbstractTable; use Symfony\Component\Console\Output\OutputInterface; +/** + * @deprecated. Use {@see \Cycle\Schema\Generator\PrintChanges} instead. Will be removed in v3.0. + */ final class ShowChanges implements GeneratorInterface { private array $changes = []; diff --git a/src/Console/Command/CycleOrm/MigrateCommand.php b/src/Console/Command/CycleOrm/MigrateCommand.php index 62c6c05..96445cf 100644 --- a/src/Console/Command/CycleOrm/MigrateCommand.php +++ b/src/Console/Command/CycleOrm/MigrateCommand.php @@ -6,10 +6,10 @@ use Cycle\Schema\Generator\Migrations\Strategy\GeneratorStrategyInterface; use Cycle\Schema\Generator\Migrations\Strategy\MultipleFilesStrategy; +use Cycle\Schema\Generator\PrintChanges; use Spiral\Core\BinderInterface; use Spiral\Cycle\Bootloader\SchemaBootloader; use Spiral\Cycle\Config\CycleConfig; -use Spiral\Cycle\Console\Command\CycleOrm\Generator\ShowChanges; use Spiral\Cycle\Console\Command\Migrate\AbstractCommand; use Cycle\Migrations\State; use Cycle\Schema\Generator\Migrations\GenerateMigrations; @@ -57,14 +57,14 @@ public function perform( $schemaCompiler = Compiler::compile( $registry, \array_merge($bootloader->getGenerators($config), [ - $show = new ShowChanges($this->output), + $print = new PrintChanges($this->output), ]), $config->getSchemaDefaults(), ); $schemaCompiler->toMemory($memory); - if ($show->hasChanges()) { + if ($print->hasChanges()) { if ($this->option('split')) { \assert($this->container instanceof BinderInterface); $this->container->bind(GeneratorStrategyInterface::class, MultipleFilesStrategy::class); diff --git a/src/Console/Command/CycleOrm/SyncCommand.php b/src/Console/Command/CycleOrm/SyncCommand.php index 12d0352..7a307bf 100644 --- a/src/Console/Command/CycleOrm/SyncCommand.php +++ b/src/Console/Command/CycleOrm/SyncCommand.php @@ -5,11 +5,11 @@ namespace Spiral\Cycle\Console\Command\CycleOrm; use Spiral\Cycle\Bootloader\SchemaBootloader; +use Cycle\Schema\Generator\PrintChanges; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; use Spiral\Boot\MemoryInterface; use Spiral\Cycle\Config\CycleConfig; -use Spiral\Cycle\Console\Command\CycleOrm\Generator\ShowChanges; use Spiral\Cycle\Console\Command\Migrate\AbstractCommand; use Spiral\Cycle\Schema\Compiler; @@ -28,17 +28,17 @@ public function perform( return self::FAILURE; } - $show = new ShowChanges($this->output); + $print = new PrintChanges($this->output); $schemaCompiler = Compiler::compile( $registry, - \array_merge($bootloader->getGenerators($config), [$show, new SyncTables()]), + \array_merge($bootloader->getGenerators($config), [$print, new SyncTables()]), $config->getSchemaDefaults(), ); $schemaCompiler->toMemory($memory); - if ($show->hasChanges()) { + if ($print->hasChanges()) { $this->info('ORM Schema has been synchronized with database.'); } diff --git a/tests/src/Console/Command/CycleOrm/MigrateCommandTest.php b/tests/src/Console/Command/CycleOrm/MigrateCommandTest.php index 051b2b5..c53767a 100644 --- a/tests/src/Console/Command/CycleOrm/MigrateCommandTest.php +++ b/tests/src/Console/Command/CycleOrm/MigrateCommandTest.php @@ -21,11 +21,11 @@ final class MigrateCommandTest extends ConsoleTest public const USER_MIGRATION = [ 'default.users', 'create table', - 'add column id', - 'add column user_id', - 'add column name', + 'add column [id]', + 'add column [user_id]', + 'add column [name]', 'add index on [user_id]', - 'add foreign key on user_id', + 'add foreign key on [user_id]', ]; protected function setUp(): void @@ -57,7 +57,7 @@ public function testMigrate(): void '--no-interaction' => true, ], [ 'Detecting schema changes...', - 'no database changes has been detected', + 'No database changes has been detected', ]); } @@ -65,7 +65,7 @@ public function testMigrateNoChanges(): void { $this->runCommand('cycle:migrate'); $this->runCommand('migrate'); - $this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [], 'no database changes'); + $this->assertConsoleCommandOutputContainsStrings('cycle:migrate', [], 'No database changes'); } public function testMigrationShouldBeCreatedWhenNewEntityAppeared(): void @@ -102,7 +102,7 @@ class Tag $this->assertConsoleCommandOutputContainsStrings('cycle:migrate', ['-r' => true], [ 'default.tags', 'create table', - 'add column id', + 'add column [id]', ]); $fs->delete($entityPatch);