mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 18:28:49 +02:00
Fix migrations with DBAL 3
This commit is contained in:
parent
f163b8d223
commit
4a90f2ac35
2 changed files with 14 additions and 8 deletions
|
@ -41,16 +41,17 @@ final class Version20190902140506 extends AbstractMultiPlatformMigration
|
||||||
// this up() migration is auto-generated, please modify it to your needs
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
|
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
|
||||||
|
|
||||||
try {
|
//Check if we can use this migration method:
|
||||||
//Check if we can use this migration method:
|
$version = $this->getOldDBVersion();
|
||||||
$version = (int) $this->connection->fetchColumn("SELECT keyValue AS version FROM `internal` WHERE `keyName` = 'dbVersion'");
|
|
||||||
$this->abortIf(26 !== $version, 'This database migration can only be used if the database version is 26! Install Part-DB 0.5.6 and update database there!');
|
//If we dont have an old databse, skip this migration
|
||||||
} catch (DBALException $dBALException) {
|
if ($version === 0) {
|
||||||
//when the table was not found, then you can not use this migration
|
|
||||||
$this->warnIf(true, 'Empty database detected. Skip migration.');
|
$this->warnIf(true, 'Empty database detected. Skip migration.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->abortIf(26 !== $version, 'This database migration can only be used if the database version is 26! Install Part-DB 0.5.6 and update database there!');
|
||||||
|
|
||||||
//Deactive SQL Modes (especially NO_ZERO_DATE, which prevents updating)
|
//Deactive SQL Modes (especially NO_ZERO_DATE, which prevents updating)
|
||||||
$this->addSql("SET sql_mode = ''");
|
$this->addSql("SET sql_mode = ''");
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Migration;
|
||||||
|
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Doctrine\DBAL\DBALException;
|
use Doctrine\DBAL\DBALException;
|
||||||
|
use Doctrine\DBAL\Exception;
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -68,8 +69,12 @@ abstract class AbstractMultiPlatformMigration extends AbstractMigration
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (int) $this->connection->fetchColumn("SELECT keyValue AS version FROM `internal` WHERE `keyName` = 'dbVersion'");
|
$version = $this->connection->fetchOne("SELECT keyValue AS version FROM `internal` WHERE `keyName` = 'dbVersion'");
|
||||||
} catch (DBALException $dBALException) {
|
if (is_bool($version)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (int) $version;
|
||||||
|
} catch (Exception $dBALException) {
|
||||||
//when the table was not found, we can proceed, because we have an empty DB!
|
//when the table was not found, we can proceed, because we have an empty DB!
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue