-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from leepeuker/improve-cli-database-management
Improve cli database management
- Loading branch information
Showing
10 changed files
with
153 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ volumes: | |
## Important: First steps | ||
- Run database migrations: `docker exec movary php bin/console.php database:migration --migrate` | ||
- Run database migrations: `docker exec movary php bin/console.php database:migration:migrate` | ||
- Create a user: `docker exec movary php bin/console.php user:create [email protected] your-password` | ||
|
||
List all available cli commands: `docker exec movary php bin/console.php` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Command; | ||
|
||
use Phinx\Console\PhinxApplication; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DatabaseMigrationMigrate extends Command | ||
{ | ||
protected static $defaultName = 'database:migration:migrate'; | ||
|
||
public function __construct( | ||
private readonly PhinxApplication $phinxApplication, | ||
private readonly string $phinxConfigurationFile | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() : void | ||
{ | ||
$this->setDescription('Execute missing database migrations.'); | ||
} | ||
|
||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | ||
protected function execute(InputInterface $input, OutputInterface $output) : int | ||
{ | ||
$command = $this->phinxApplication->find('migrate'); | ||
|
||
$arguments = [ | ||
'command' => $command, | ||
'--configuration' => $this->phinxConfigurationFile, | ||
]; | ||
|
||
return $command->run(new ArrayInput($arguments), $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Command; | ||
|
||
use Phinx\Console\PhinxApplication; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DatabaseMigrationRollback extends Command | ||
{ | ||
protected static $defaultName = 'database:migration:rollback'; | ||
|
||
public function __construct( | ||
private readonly PhinxApplication $phinxApplication, | ||
private readonly string $phinxConfigurationFile | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() : void | ||
{ | ||
$this->setDescription('Rollback last database migration.'); | ||
} | ||
|
||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | ||
protected function execute(InputInterface $input, OutputInterface $output) : int | ||
{ | ||
$command = $this->phinxApplication->find('rollback'); | ||
|
||
$arguments = [ | ||
'command' => $command, | ||
'--configuration' => $this->phinxConfigurationFile, | ||
]; | ||
|
||
return $command->run(new ArrayInput($arguments), $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Command; | ||
|
||
use Phinx\Console\PhinxApplication; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DatabaseMigrationStatus extends Command | ||
{ | ||
protected static $defaultName = 'database:migration:status'; | ||
|
||
public function __construct( | ||
private readonly PhinxApplication $phinxApplication, | ||
private readonly string $phinxConfigurationFile | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() : void | ||
{ | ||
$this->setDescription('Status of database migrations.'); | ||
} | ||
|
||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter | ||
protected function execute(InputInterface $input, OutputInterface $output) : int | ||
{ | ||
$command = $this->phinxApplication->find('status'); | ||
|
||
$arguments = [ | ||
'command' => $command, | ||
'--configuration' => $this->phinxConfigurationFile, | ||
]; | ||
|
||
return $command->run(new ArrayInput($arguments), $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters