Skip to content

Commit

Permalink
4.next - Revise the migrations interfaces
Browse files Browse the repository at this point in the history
- Add methods that will allow symfony support to be dropped in the next
  major
- Add better intergration with CakePHP abstractions.
- Put some TODOs in for the next set of changes.
  • Loading branch information
markstory committed Sep 23, 2024
1 parent d69b33d commit f04d92f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 38 deletions.
10 changes: 10 additions & 0 deletions src/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,17 @@ function ($phpFile) {
$io->verbose("Constructing <info>$class</info>.");

$config = $this->getConfig();
// TODO Subset config and pass forward.
// Move this to the Migration/phinx shim
$input = new ArrayInput([
'--plugin' => $config['plugin'] ?? null,
'--source' => $config['source'] ?? null,
'--connection' => $config->getConnection(),
]);
// TODO move this to the migration/phinx shim
$output = new OutputAdapter($io);

// TODO constructor should take $io and $config
// instantiate it
$migration = new $class('default', $version, $input, $output);

Expand Down Expand Up @@ -967,16 +971,20 @@ public function getSeeds(): array
$seeds = [];

$config = $this->getConfig();
// TODO Subset config and pass forward.
// TODO move this to the migration/phinx shim
$optionDef = new InputDefinition([
new InputOption('plugin', mode: InputOption::VALUE_OPTIONAL, default: ''),
new InputOption('connection', mode: InputOption::VALUE_OPTIONAL, default: ''),
new InputOption('source', mode: InputOption::VALUE_OPTIONAL, default: ''),
]);
// TODO move this to the migration/phinx shim
$input = new ArrayInput([
'--plugin' => $config['plugin'] ?? null,
'--source' => $config['source'] ?? null,
'--connection' => $config->getConnection(),
], $optionDef);
// TODO move this to the migration/phinx shim
$output = new OutputAdapter($this->io);

foreach ($phpFiles as $filePath) {
Expand All @@ -1003,6 +1011,7 @@ public function getSeeds(): array
} else {
$seed = new $class();
}
// TODO Replace with with setIo and setConfig
$seed->setEnvironment('default');
$seed->setInput($input);
$seed->setOutput($output);
Expand All @@ -1027,6 +1036,7 @@ public function getSeeds(): array
return [];
}

// TODO remove this
foreach ($this->seeds as $instance) {
if (isset($input) && $instance instanceof AbstractSeed) {
$instance->setInput($input);
Expand Down
47 changes: 31 additions & 16 deletions src/MigrationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

namespace Migrations;

use Cake\Console\ConsoleIo;
use Cake\Database\Query;
use Cake\Database\Query\DeleteQuery;
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use Migrations\Config\ConfigInterface;
use Migrations\Db\Adapter\AdapterInterface;
use Migrations\Db\Table;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -61,32 +63,52 @@ public function setAdapter(AdapterInterface $adapter);
public function getAdapter(): ?AdapterInterface;

/**
* Sets the input object to be used in migration object
* Set the Console IO object to be used.
*
* @param \Symfony\Component\Console\Input\InputInterface $input Input
* @param \Cake\Console\ConsoleIo $io The Io
* @return $this
*/
public function setInput(InputInterface $input);
public function setIo(ConsoleIo $io);

/**
* Gets the input object to be used in migration object
* Get the Console IO object to be used.
*
* @return \Symfony\Component\Console\Input\InputInterface|null
* @return \Cake\Console\ConsoleIo|null
*/
public function getInput(): ?InputInterface;
public function getIo(): ?ConsoleIo;

/**
* Sets the output object to be used in migration object
* Gets the config.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output Output
* @return \Migrations\Config\ConfigInterface
*/
public function getConfig(): ConfigInterface;

/**
* Sets the config.
*
* @param \Migrations\Config\ConfigInterface $config Configuration Object
* @return $this
*/
public function setOutput(OutputInterface $output);
public function setConfig(ConfigInterface $config);

/**
* Gets the input object to be used in migration object
*
* A new InputInterface will be generated each time `getOutput` is called.
*
* @return \Symfony\Component\Console\Input\InputInterface|null
* @deprecated 4.5.0 Use getIo() instead.
*/
public function getInput(): ?InputInterface;

/**
* Gets the output object to be used in migration object
*
* A new OutputInterface will be generated each time `getOutput` is called.
*
* @return \Symfony\Component\Console\Output\OutputInterface|null
* @deprecated 4.5.0 Use getIo() instead.
*/
public function getOutput(): ?OutputInterface;

Expand All @@ -97,13 +119,6 @@ public function getOutput(): ?OutputInterface;
*/
public function getName(): string;

/**
* Gets the detected environment
*
* @return string
*/
public function getEnvironment(): string;

/**
* Sets the migration version number.
*
Expand Down
52 changes: 30 additions & 22 deletions src/SeedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Migrations;

use Cake\Console\ConsoleIo;
use Migrations\Config\ConfigInterface;
use Migrations\Db\Adapter\AdapterInterface;
use Migrations\Db\Table;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -45,61 +47,67 @@ public function run(): void;
public function getDependencies(): array;

/**
* Sets the environment.
* Sets the database adapter.
*
* @param \Migrations\Db\Adapter\AdapterInterface $adapter Database Adapter
* @return $this
*/
public function setEnvironment(string $environment);
public function setAdapter(AdapterInterface $adapter);

/**
* Gets the environment.
* Gets the database adapter.
*
* @return string
* @return \Migrations\Db\Adapter\AdapterInterface
*/
public function getEnvironment(): string;
public function getAdapter(): AdapterInterface;

/**
* Sets the database adapter.
* Set the Console IO object to be used.
*
* @param \Migrations\Db\Adapter\AdapterInterface $adapter Database Adapter
* @param \Cake\Console\ConsoleIo $io The Io
* @return $this
*/
public function setAdapter(AdapterInterface $adapter);
public function setIo(ConsoleIo $io);

/**
* Gets the database adapter.
* Get the Console IO object to be used.
*
* @return \Migrations\Db\Adapter\AdapterInterface
* @return \Cake\Console\ConsoleIo|null
*/
public function getAdapter(): AdapterInterface;
public function getIo(): ?ConsoleIo;

/**
* Sets the input object to be used in migration object
* Gets the config.
*
* @param \Symfony\Component\Console\Input\InputInterface $input Input
* @return $this
* @return \Migrations\Config\ConfigInterface
*/
public function setInput(InputInterface $input);
public function getConfig(): ConfigInterface;

/**
* Gets the input object to be used in migration object
* Sets the config.
*
* @return \Symfony\Component\Console\Input\InputInterface
* @param \Migrations\Config\ConfigInterface $config Configuration Object
* @return $this
*/
public function getInput(): InputInterface;
public function setConfig(ConfigInterface $config);

/**
* Sets the output object to be used in migration object
* Gets the input object to be used in migration object
*
* @param \Symfony\Component\Console\Output\OutputInterface $output Output
* @return $this
* A new InputInteface will be generated each time `getOutput` is called.
*
* @return \Symfony\Component\Console\Input\InputInterface
* @deprecated 4.5.0 Use getIo() instead.
*/
public function setOutput(OutputInterface $output);
public function getInput(): InputInterface;

/**
* Gets the output object to be used in migration object
*
* A new OutputInteface will be generated each time `getOutput` is called.
*
* @return \Symfony\Component\Console\Output\OutputInterface
* @deprecated 4.5.0 Use getIo() instead.
*/
public function getOutput(): OutputInterface;

Expand Down

0 comments on commit f04d92f

Please sign in to comment.