Rename `getSchemaQueryFor()` & drop `$version` param
This commit is contained in:
parent
7e313c921a
commit
2944ceaa52
|
@ -191,9 +191,12 @@ abstract class MigrationHook implements Countable
|
||||||
);
|
);
|
||||||
Logger::debug($e->getTraceAsString());
|
Logger::debug($e->getTraceAsString());
|
||||||
|
|
||||||
|
$schemaQuery = $this->getSchemaQuery()
|
||||||
|
->filter(Filter::equal('version', $migration->getVersion()));
|
||||||
|
|
||||||
static::insertFailedEntry(
|
static::insertFailedEntry(
|
||||||
$conn,
|
$conn,
|
||||||
$this->getSchemaQueryFor($migration->getVersion()),
|
$schemaQuery,
|
||||||
$migration->getVersion(),
|
$migration->getVersion(),
|
||||||
$e->getMessage() . PHP_EOL . $e->getTraceAsString()
|
$e->getMessage() . PHP_EOL . $e->getTraceAsString()
|
||||||
);
|
);
|
||||||
|
@ -247,13 +250,11 @@ abstract class MigrationHook implements Countable
|
||||||
abstract protected function getDb(): Connection;
|
abstract protected function getDb(): Connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a schema version query filtered by the given $version
|
* Get a schema version query
|
||||||
*
|
|
||||||
* @param string $version
|
|
||||||
*
|
*
|
||||||
* @return Query
|
* @return Query
|
||||||
*/
|
*/
|
||||||
abstract protected function getSchemaQueryFor(string $version): Query;
|
abstract protected function getSchemaQuery(): Query;
|
||||||
|
|
||||||
protected function load(): void
|
protected function load(): void
|
||||||
{
|
{
|
||||||
|
@ -361,12 +362,14 @@ abstract class MigrationHook implements Countable
|
||||||
/** @var array<string, string> $states */
|
/** @var array<string, string> $states */
|
||||||
$states = $session->get($this->getModuleName(), []);
|
$states = $session->get($this->getModuleName(), []);
|
||||||
if (! isset($states[$version])) {
|
if (! isset($states[$version])) {
|
||||||
$schemaQuery = $this->getSchemaQueryFor($version);
|
$schemaQuery = $this->getSchemaQuery()
|
||||||
$schemaQuery->setFilter(Filter::all(Filter::equal('success', 'n')));
|
->filter(Filter::equal('version', $version))
|
||||||
|
->filter(Filter::all(Filter::equal('success', 'n')));
|
||||||
|
|
||||||
if (static::getColumnType($this->getDb(), $schemaQuery->getModel()->getTableName(), 'reason')) {
|
if (static::getColumnType($this->getDb(), $schemaQuery->getModel()->getTableName(), 'reason')) {
|
||||||
/** @var Schema $schema */
|
/** @var Schema $schema */
|
||||||
$schema = $schemaQuery->first();
|
$schema = $schemaQuery->first();
|
||||||
if ($schema && version_compare($schema->version, $version, '==')) {
|
if ($schema) {
|
||||||
return $schema->reason;
|
return $schema->reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use Icinga\Application\Hook\MigrationHook;
|
||||||
use Icinga\Common\Database;
|
use Icinga\Common\Database;
|
||||||
use Icinga\Model\Schema;
|
use Icinga\Model\Schema;
|
||||||
use ipl\Orm\Query;
|
use ipl\Orm\Query;
|
||||||
use ipl\Stdlib\Filter;
|
|
||||||
|
|
||||||
class DbMigration extends MigrationHook
|
class DbMigration extends MigrationHook
|
||||||
{
|
{
|
||||||
|
@ -28,7 +27,7 @@ class DbMigration extends MigrationHook
|
||||||
{
|
{
|
||||||
if ($this->version === null) {
|
if ($this->version === null) {
|
||||||
$conn = $this->getDb();
|
$conn = $this->getDb();
|
||||||
$schemaQuery = Schema::on($conn)
|
$schemaQuery = $this->getSchemaQuery()
|
||||||
->orderBy('id', SORT_DESC)
|
->orderBy('id', SORT_DESC)
|
||||||
->limit(2);
|
->limit(2);
|
||||||
|
|
||||||
|
@ -65,9 +64,8 @@ class DbMigration extends MigrationHook
|
||||||
return $this->version;
|
return $this->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSchemaQueryFor(string $version): Query
|
protected function getSchemaQuery(): Query
|
||||||
{
|
{
|
||||||
return Schema::on($this->getDb())
|
return Schema::on($this->getDb());
|
||||||
->filter(Filter::equal('version', $version));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue