Migrations: cleanup

This commit is contained in:
Thomas Gelf 2018-10-07 16:45:11 +02:00
parent f32e568b8a
commit 6e25c05d89
2 changed files with 12 additions and 9 deletions

View File

@ -3,8 +3,8 @@
namespace Icinga\Module\Director\Db;
use Exception;
use Icinga\Exception\IcingaException;
use Icinga\Module\Director\Data\Db\DbConnection;
use RuntimeException;
class Migration
{
@ -27,21 +27,25 @@ class Migration
/**
* @param DbConnection $connection
* @return $this
* @throws IcingaException
*/
public function apply(DbConnection $connection)
{
/** @var \Zend_Db_Adapter_Pdo_Abstract $db */
$db = $connection->getDbAdapter();
// TODO: this is fagile and depends on accordingly written schema files:
$queries = preg_split('/[\n\s\t]*\;[\n\s\t]+/s', $this->sql, -1, PREG_SPLIT_NO_EMPTY);
// TODO: this is fragile and depends on accordingly written schema files:
$queries = preg_split(
'/[\n\s\t]*\;[\n\s\t]+/s',
$this->sql,
-1,
PREG_SPLIT_NO_EMPTY
);
if (empty($queries)) {
throw new IcingaException(
throw new RuntimeException(sprintf(
'Migration %d has no queries',
$this->version
);
));
}
try {
@ -53,12 +57,12 @@ class Migration
}
}
} catch (Exception $e) {
throw new IcingaException(
throw new RuntimeException(sprintf(
'Migration %d failed (%s) while running %s',
$this->version,
$e->getMessage(),
$query
);
));
}
return $this;

View File

@ -86,7 +86,6 @@ class Migrations
/**
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function applyPendingMigrations()
{