Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
New commands added
Browse files Browse the repository at this point in the history
  • Loading branch information
devnix committed Oct 16, 2020
1 parent 3dcbe14 commit baf9c8a
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 7 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2]
### Added
- Supported command `doctrine:migrations:current`
- Supported command `doctrine:migrations:latest`
- Supported command `doctrine:migrations:list`
- Supported command `doctrine:migrations:status`
- Supported command `doctrine:migrations:sync-metadata-storage`
- Supported command `doctrine:migrations:up-to-date`

### Changed
- Internal class renaming
- Command description as the original one in `doctrine:migrations:diff` and `doctrine:migrations:version`

## [0.1.1]
### Added
- Project cleanup
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ doctrine_migrations_multiple_database:

### Supported commands

- `doctrine:migrations:current`
- `doctrine:migrations:diff`
- `doctrine:migrations:latest`
- `doctrine:migrations:list`
- `doctrine:migrations:migrate`
- `doctrine:migrations:status`
- `doctrine:migrations:sync-metadata-storage`
- `doctrine:migrations:up-to-date`
- `doctrine:migrations:version`

## Pitfalls
Expand Down
39 changes: 39 additions & 0 deletions src/Command/Doctrine/CurrentCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CurrentCommand extends AbstractCommand
{
/** @var string */
protected static $defaultName = 'doctrine:migrations:current';

protected function configure() : void
{
$this
->setAliases(['current'])
->setDescription('Outputs the current version')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the Entity Manager to handle.')
;

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$newInput = new ArrayInput([]);

$newInput->setInteractive($input->isInteractive());

foreach ($this->getDependencyFactories(strval($input->getOption('em'))) as $dependencyFactory) {
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\CurrentCommand($dependencyFactory);
$otherCommand->run($newInput, $output);
}

return self::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/Command/Doctrine/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DiffCommand extends AbstractCommand
protected function configure(): void
{
$this
->setDescription('Proxy to launch doctrine:migrations:diff command as it would require a "configuration" option, and we can\'t define em/connection in config.')
->setDescription('Generate a migration by comparing your current database to your mapping information.')
->setHelp(
<<<EOT
The <info>%command.name%</info> command generates a migration by comparing your current database to your mapping information:
Expand Down
39 changes: 39 additions & 0 deletions src/Command/Doctrine/LatestCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class LatestCommand extends AbstractCommand
{
/** @var string */
protected static $defaultName = 'doctrine:migrations:latest';

protected function configure() : void
{
$this
->setAliases(['latest'])
->setDescription('Outputs the latest version')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the Entity Manager to handle.')
;

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$newInput = new ArrayInput([]);

$newInput->setInteractive($input->isInteractive());

foreach ($this->getDependencyFactories(strval($input->getOption('em'))) as $dependencyFactory) {
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\LatestCommand($dependencyFactory);
$otherCommand->run($newInput, $output);
}

return self::SUCCESS;
}
}
44 changes: 44 additions & 0 deletions src/Command/Doctrine/ListCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ListCommand extends AbstractCommand
{
protected static $defaultName = 'doctrine:migrations:list';

protected function configure() : void
{
$this
->setAliases(['list-migrations'])
->setDescription('Display a list of all available migrations and their status.')
->setHelp(<<<EOT
The <info>%command.name%</info> command outputs a list of all available migrations and their status:
<info>%command.full_name%</info>
EOT
)
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the Entity Manager to handle.')
;

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$newInput = new ArrayInput([]);

$newInput->setInteractive($input->isInteractive());

foreach ($this->getDependencyFactories(strval($input->getOption('em'))) as $dependencyFactory) {
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\CurrentCommand($dependencyFactory);
$otherCommand->run($newInput, $output);
}

return self::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/Command/Doctrine/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MigrateCommand extends AbstractCommand
protected function configure(): void
{
$this
->setDescription('Proxy to launch doctrine:migrations:migrate command as it would require a "configuration" option, and we can\'t define em/connection in config.')
->setDescription('Execute a migration to a specified version or the latest available version.')
->addArgument(
'version',
InputArgument::OPTIONAL,
Expand Down
45 changes: 45 additions & 0 deletions src/Command/Doctrine/StatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class StatusCommand extends AbstractCommand
{
/** @var string */
protected static $defaultName = 'doctrine:migrations:status';

protected function configure() : void
{
$this
->setAliases(['status'])
->setDescription('View the status of a set of migrations.')
->setHelp(<<<EOT
The <info>%command.name%</info> command outputs the status of a set of migrations:
<info>%command.full_name%</info>
EOT
)
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the Entity Manager to handle.')
;

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$newInput = new ArrayInput([]);

$newInput->setInteractive($input->isInteractive());

foreach ($this->getDependencyFactories(strval($input->getOption('em'))) as $dependencyFactory) {
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\StatusCommand($dependencyFactory);
$otherCommand->run($newInput, $output);
}

return self::SUCCESS;
}
}
45 changes: 45 additions & 0 deletions src/Command/Doctrine/SyncMetadataCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class SyncMetadataCommand extends AbstractCommand
{
/** @var string */
protected static $defaultName = 'doctrine:migrations:sync-metadata-storage';

protected function configure() : void
{
parent::configure();

$this
->setAliases(['sync-metadata-storage'])
->setDescription('Ensures that the metadata storage is at the latest version.')
->setHelp(<<<EOT
The <info>%command.name%</info> command updates metadata storage the latest version.
<info>%command.full_name%</info>
EOT
)
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the Entity Manager to handle.')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$newInput = new ArrayInput([]);

$newInput->setInteractive($input->isInteractive());

foreach ($this->getDependencyFactories(strval($input->getOption('em'))) as $dependencyFactory) {
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand($dependencyFactory);
$otherCommand->run($newInput, $output);
}

return self::SUCCESS;
}
}
50 changes: 50 additions & 0 deletions src/Command/Doctrine/UpToDateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UpToDateCommand extends AbstractCommand
{
/** @var string */
protected static $defaultName = 'doctrine:migrations:up-to-date';

protected function configure() : void
{
$this
->setAliases(['up-to-date'])
->setDescription('Tells you if your schema is up-to-date.')
->addOption('fail-on-unregistered', 'u', InputOption::VALUE_NONE, 'Whether to fail when there are unregistered extra migrations found')
->addOption('list-migrations', 'l', InputOption::VALUE_NONE, 'Show a list of missing or not migrated versions.')
->setHelp(<<<EOT
The <info>%command.name%</info> command tells you if your schema is up-to-date:
<info>%command.full_name%</info>
EOT
)
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the Entity Manager to handle.')
;

parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$newInput = new ArrayInput([
'--fail-on-unregistered' => $input->getOption('fail-on-unregistered'),
'--list-migrations' => $input->getOption('list-migrations'),
]);

$newInput->setInteractive($input->isInteractive());

foreach ($this->getDependencyFactories(strval($input->getOption('em'))) as $dependencyFactory) {
$otherCommand = new \Doctrine\Migrations\Tools\Console\Command\UpToDateCommand($dependencyFactory);
$otherCommand->run($newInput, $output);
}

return self::SUCCESS;
}
}
41 changes: 36 additions & 5 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,53 @@ services:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

# TODO
doctrine_migrations.sync_metadata_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\SyncMetadataCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

doctrine_migrations.versions_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\ListCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

doctrine_migrations.current_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\CurrentCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

# doctrine_migrations.dump_schema_command:
# doctrine_migrations.execute_command:
# doctrine_migrations.generate_command:
# doctrine_migrations.latest_command:

doctrine_migrations.latest_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\LatestCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

doctrine_migrations.migrate_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\MigrateCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

# TODO
# doctrine_migrations.rollup_command:
# doctrine_migrations.status_command:
# doctrine_migrations.up_to_date_command:

doctrine_migrations.status_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\StatusCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

doctrine_migrations.up_to_date_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\UpToDateCommand
arguments:
- '@doctrine.migrations_multiple_database.configuration'
tags: ['console.command']

doctrine_migrations.version_command:
class: AvaiBookSports\Bundle\MigrationsMutlipleDatabase\Command\Doctrine\VersionCommand
Expand Down

0 comments on commit baf9c8a

Please sign in to comment.