Skip to content
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
6 changes: 5 additions & 1 deletion src/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,11 @@ public function getVersions(): array
protected function migrationsTable(): MigrationsTableStorage
{
// TODO Use configure/auto-detect which implmentation to use.
return new MigrationsTableStorage($this, $this->getSchemaTableName());
return new MigrationsTableStorage(
$this,
$this->getSchemaTableName(),
$this->getOption('plugin'),
);
}

/**
Expand Down
28 changes: 10 additions & 18 deletions src/Db/Adapter/MigrationsTableStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,15 @@ class MigrationsTableStorage
*
* @param \Migrations\Db\Adapter\AbstractAdapter $adapter The database adapter.
* @param string $schemaTableName The schema table name.
* @param string|null $plugin The plugin name.
*/
public function __construct(
protected AbstractAdapter $adapter,
protected string $schemaTableName = 'phinxlog',
protected ?string $plugin = null,
) {
}

/**
* Gets the schema table name.
*
* @return string
*/
public function getSchemaTableName(): string
{
return $this->schemaTableName;
}

/**
* Gets all the migration versions.
*
Expand All @@ -61,7 +53,7 @@ public function getVersions(array $orderBy): SelectQuery
{
$query = $this->adapter->getSelectBuilder();
$query->select('*')
->from($this->getSchemaTableName())
->from($this->schemaTableName)
->orderBy($orderBy);

return $query;
Expand All @@ -79,7 +71,7 @@ public function recordUp(MigrationInterface $migration, string $startTime, strin
{
$query = $this->adapter->getInsertBuilder();
$query->insert(['version', 'migration_name', 'start_time', 'end_time', 'breakpoint'])
->into($this->getSchemaTableName())
->into($this->schemaTableName)
->values([
'version' => (string)$migration->getVersion(),
'migration_name' => substr($migration->getName(), 0, 100),
Expand All @@ -100,7 +92,7 @@ public function recordDown(MigrationInterface $migration): void
{
$query = $this->adapter->getDeleteBuilder();
$query->delete()
->from($this->getSchemaTableName())
->from($this->schemaTableName)
->where(['version' => (string)$migration->getVersion()]);
$this->adapter->executeQuery($query);
}
Expand All @@ -119,7 +111,7 @@ public function toggleBreakpoint(MigrationInterface $migration): void
$this->adapter->query(
sprintf(
'UPDATE %1$s SET %2$s = CASE %2$s WHEN true THEN false ELSE true END, %4$s = %4$s WHERE %3$s = ?;',
$this->adapter->quoteTableName($this->getSchemaTableName()),
$this->adapter->quoteTableName($this->schemaTableName),
$this->adapter->quoteColumnName('breakpoint'),
$this->adapter->quoteColumnName('version'),
$this->adapter->quoteColumnName('start_time'),
Expand All @@ -136,7 +128,7 @@ public function toggleBreakpoint(MigrationInterface $migration): void
public function resetAllBreakpoints(): int
{
$query = $this->adapter->getUpdateBuilder();
$query->update($this->getSchemaTableName())
$query->update($this->schemaTableName)
->set([
'breakpoint' => 0,
'start_time' => $query->identifier('start_time'),
Expand All @@ -158,7 +150,7 @@ public function resetAllBreakpoints(): int
public function markBreakpoint(MigrationInterface $migration, bool $state): void
{
$query = $this->adapter->getUpdateBuilder();
$query->update($this->getSchemaTableName())
$query->update($this->schemaTableName)
->set([
'breakpoint' => (int)$state,
'start_time' => $query->identifier('start_time'),
Expand All @@ -183,7 +175,7 @@ public function createTable(): void
'primary_key' => 'version',
];

$table = new Table($this->getSchemaTableName(), $options, $this->adapter);
$table = new Table($this->schemaTableName, $options, $this->adapter);
$table->addColumn('version', 'biginteger', ['null' => false])
->addColumn('migration_name', 'string', ['limit' => 100, 'default' => null, 'null' => true])
->addColumn('start_time', 'timestamp', ['default' => null, 'null' => true])
Expand All @@ -206,7 +198,7 @@ public function createTable(): void
*/
public function upgradeTable(): void
{
$table = new Table($this->getSchemaTableName(), [], $this->adapter);
$table = new Table($this->schemaTableName, [], $this->adapter);
if (!$table->hasColumn('migration_name')) {
$table
->addColumn(
Expand Down
1 change: 1 addition & 0 deletions src/Migration/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function createConfig(): ConfigInterface
'database' => $connectionConfig['database'],
'migration_table' => $table,
'dryrun' => $this->getOption('dry-run'),
'plugin' => $plugin,
];

$configData = [
Expand Down
11 changes: 11 additions & 0 deletions tests/TestCase/Migration/ManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ public function testConnection(): void
$this->assertSame('test', $result->getConfig()->getConnection());
}

public function testCreateConfigPluginAdapter(): void
{
$factory = new ManagerFactory([
'connection' => 'test',
'plugin' => 'Migrator',
]);

$config = $factory->createConfig();
$this->assertSame('Migrator', $config['environment']['plugin']);
}

public function testDsnConnection(): void
{
$out = new StubConsoleOutput();
Expand Down
Loading