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

Reduce phinx usage and stabilize backend inteface #756

Merged
merged 9 commits into from
Oct 13, 2024
44 changes: 44 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<file src="src/AbstractSeed.php">
<DeprecatedClass>
<code><![CDATA[new Seed()]]></code>
</DeprecatedClass>
</file>
<file src="src/Command/BakeMigrationDiffCommand.php">
<DeprecatedClass>
<code><![CDATA[Dump::class]]></code>
<code><![CDATA[new $className()]]></code>
</DeprecatedClass>
</file>
<file src="src/Command/MigrationsCommand.php">
<DeprecatedClass>
<code><![CDATA[MigrationsDispatcher]]></code>
Expand All @@ -9,6 +20,23 @@
<code><![CDATA[new MigrationsDispatcher(PHINX_VERSION)]]></code>
</DeprecatedClass>
</file>
<file src="src/Command/Phinx/CommandTrait.php">
<DeprecatedClass>
<code><![CDATA[$this->addOption('--environment', '-e', InputArgument::OPTIONAL)]]></code>
<code><![CDATA[$this->addOption('--environment', '-e', InputArgument::OPTIONAL)]]></code>
<code><![CDATA[$this->addOption('--environment', '-e', InputArgument::OPTIONAL)]]></code>
<code><![CDATA[$this->addOption('--environment', '-e', InputArgument::OPTIONAL)]]></code>
<code><![CDATA[$this->addOption('--environment', '-e', InputArgument::OPTIONAL)]]></code>
<code><![CDATA[$this->addOption('--environment', '-e', InputArgument::OPTIONAL)]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
<code><![CDATA[$this->setManager(new CakeManager($this->getConfig(), $input, $output))]]></code>
</DeprecatedClass>
</file>
<file src="src/Command/Phinx/Create.php">
<DeprecatedTrait>
<code><![CDATA[ConfigurationTrait]]></code>
Expand Down Expand Up @@ -142,6 +170,22 @@
<code><![CDATA[ConfigurationTrait]]></code>
</DeprecatedTrait>
</file>
<file src="src/MigrationsDispatcher.php">
<DeprecatedClass>
<code><![CDATA[Phinx\Create::class]]></code>
<code><![CDATA[Phinx\Dump::class]]></code>
<code><![CDATA[Phinx\MarkMigrated::class]]></code>
<code><![CDATA[Phinx\Migrate::class]]></code>
<code><![CDATA[Phinx\Rollback::class]]></code>
<code><![CDATA[Phinx\Seed::class]]></code>
<code><![CDATA[Phinx\Status::class]]></code>
</DeprecatedClass>
</file>
<file src="src/Shim/MigrationAdapter.php">
<PossiblyNullReference>
<code><![CDATA[hasTransactions]]></code>
</PossiblyNullReference>
</file>
<file src="src/Shim/OutputAdapter.php">
<ArgumentTypeCoercion>
<code><![CDATA[$messages]]></code>
Expand Down
3 changes: 3 additions & 0 deletions src/Command/Phinx/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class Create extends CreateCommand
{
use CommandTrait {
Expand Down
2 changes: 2 additions & 0 deletions src/Command/Phinx/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* Dump command class.
* A "dump" is a snapshot of a database at a given point in time. It is stored in a
* .lock file in the same folder as migrations files.
*
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class Dump extends AbstractCommand
{
Expand Down
1 change: 1 addition & 0 deletions src/Command/Phinx/MarkMigrated.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* @method \Migrations\CakeManager getManager()
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class MarkMigrated extends AbstractCommand
{
Expand Down
3 changes: 3 additions & 0 deletions src/Command/Phinx/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class Migrate extends MigrateCommand
{
use CommandTrait {
Expand Down
3 changes: 3 additions & 0 deletions src/Command/Phinx/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class Rollback extends RollbackCommand
{
use CommandTrait {
Expand Down
3 changes: 3 additions & 0 deletions src/Command/Phinx/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class Seed extends SeedRun
{
use CommandTrait {
Expand Down
1 change: 1 addition & 0 deletions src/Command/Phinx/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/**
* @method \Migrations\CakeManager getManager()
* @deprecated 4.5.0 This command is deprecated alongside phinx compatibility.
*/
class Status extends StatusCommand
{
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use InvalidArgumentException;
use Migrations\Config\Config;
use Migrations\Db\Action\AddColumn;
use Migrations\Db\Action\AddForeignKey;
use Migrations\Db\Action\AddIndex;
Expand All @@ -39,7 +40,6 @@
use Migrations\MigrationInterface;
use PDO;
use PDOException;
use Phinx\Config\Config;
use Phinx\Util\Literal as PhinxLiteral;
use ReflectionMethod;
use RuntimeException;
Expand Down
4 changes: 2 additions & 2 deletions src/Db/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Migrations\Db\Table;

use Cake\Core\Configure;
use Migrations\Db\Adapter\AdapterInterface;
use Migrations\Db\Adapter\PostgresAdapter;
use Migrations\Db\Literal;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Adapter\PostgresAdapter;
use RuntimeException;

/**
Expand Down
81 changes: 81 additions & 0 deletions src/Migration/BackendInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);

namespace Migrations\Migration;

interface BackendInterface
{
/**
* Returns the status of each migrations based on the options passed
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `format` Format to output the response. Can be 'json'
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* @return array The migrations list and their statuses
*/
public function status(array $options = []): array;

/**
* Migrates available migrations
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `target` The version number to migrate to. If not provided, will migrate
* everything it can
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* - `date` The date to migrate to
* @return bool Success
*/
public function migrate(array $options = []): bool;

/**
* Rollbacks migrations
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `target` The version number to migrate to. If not provided, will only migrate
* the last migrations registered in the phinx log
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* - `date` The date to rollback to
* @return bool Success
*/
public function rollback(array $options = []): bool;

/**
* Marks a migration as migrated
*
* @param int|string|null $version The version number of the migration to mark as migrated
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* @return bool Success
*/
public function markMigrated(int|string|null $version = null, array $options = []): bool;

/**
* Seed the database using a seed file
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* - `seed` The seed file to use
* @return bool Success
*/
public function seed(array $options = []): bool;
}
83 changes: 6 additions & 77 deletions src/Migration/BuiltinBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,15 @@
use DateTime;
use InvalidArgumentException;
use Migrations\Config\ConfigInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* The Migrations class is responsible for handling migrations command
* within an none-shell application.
*
* @internal
*/
class BuiltinBackend
class BuiltinBackend implements BackendInterface
{
/**
* The OutputInterface.
* Should be a \Symfony\Component\Console\Output\NullOutput instance
*
* @var \Symfony\Component\Console\Output\OutputInterface
*/
protected OutputInterface $output;

/**
* Manager instance
*
Expand All @@ -63,14 +52,6 @@ class BuiltinBackend
*/
protected string $command;

/**
* Stub input to feed the manager class since we might not have an input ready when we get the Manager using
* the `getManager()` method
*
* @var \Symfony\Component\Console\Input\ArrayInput
*/
protected ArrayInput $stubInput;

/**
* Constructor
*
Expand All @@ -82,25 +63,13 @@ class BuiltinBackend
*/
public function __construct(array $default = [])
{
$this->output = new NullOutput();
$this->stubInput = new ArrayInput([]);

if ($default) {
$this->default = $default;
}
}

/**
* Returns the status of each migrations based on the options passed
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `format` Format to output the response. Can be 'json'
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* @return array The migrations list and their statuses
* {@inheritDoc}
*/
public function status(array $options = []): array
{
Expand All @@ -110,18 +79,7 @@ public function status(array $options = []): array
}

/**
* Migrates available migrations
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `target` The version number to migrate to. If not provided, will migrate
* everything it can
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* - `date` The date to migrate to
* @return bool Success
* {@inheritDoc}
*/
public function migrate(array $options = []): bool
{
Expand All @@ -141,18 +99,7 @@ public function migrate(array $options = []): bool
}

/**
* Rollbacks migrations
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `target` The version number to migrate to. If not provided, will only migrate
* the last migrations registered in the phinx log
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* - `date` The date to rollback to
* @return bool Success
* {@inheritDoc}
*/
public function rollback(array $options = []): bool
{
Expand All @@ -172,16 +119,7 @@ public function rollback(array $options = []): bool
}

/**
* Marks a migration as migrated
*
* @param int|string|null $version The version number of the migration to mark as migrated
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* @return bool Success
* {@inheritDoc}
*/
public function markMigrated(int|string|null $version = null, array $options = []): bool
{
Expand All @@ -206,16 +144,7 @@ public function markMigrated(int|string|null $version = null, array $options = [
}

/**
* Seed the database using a seed file
*
* @param array<string, mixed> $options Options to pass to the command
* Available options are :
*
* - `connection` The datasource connection to use
* - `source` The folder where migrations are in
* - `plugin` The plugin containing the migrations
* - `seed` The seed file to use
* @return bool Success
* {@inheritDoc}
*/
public function seed(array $options = []): bool
{
Expand Down
Loading
Loading