Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PrintChanges instead of ShowChanges #89

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/Console/Command/CycleOrm/Generator/ShowChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Command/CycleOrm/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Console/Command/CycleOrm/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.');
}

Expand Down
14 changes: 7 additions & 7 deletions tests/src/Console/Command/CycleOrm/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,15 +57,15 @@ public function testMigrate(): void
'--no-interaction' => true,
], [
'Detecting schema changes...',
'no database changes has been detected',
'No database changes has been detected',
]);
}

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
Expand Down Expand Up @@ -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);
Expand Down
Loading