fix migration for sqlite (#881)

This commit is contained in:
Kevin Papst
2019-06-30 15:16:44 +02:00
committed by GitHub
parent d8621f0b7a
commit 834a0a873f
7 changed files with 62 additions and 44 deletions

View File

@@ -52,6 +52,25 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
return 'kimai2_' . $name;
}
protected function isSupportingForeignKeys(): bool
{
return true;
}
protected function deactivateForeignKeysOnSqlite()
{
if ($this->isPlatformSqlite() && !$this->isSupportingForeignKeys()) {
$this->addSql('PRAGMA foreign_keys = OFF;');
}
}
private function activateForeignKeysOnSqlite()
{
if ($this->isPlatformSqlite() && !$this->isSupportingForeignKeys()) {
$this->addSql('PRAGMA foreign_keys = ON;');
}
}
/**
* @param Schema $schema
* @throws DBALException
@@ -59,6 +78,16 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
public function preUp(Schema $schema): void
{
$this->abortIfPlatformNotSupported();
$this->deactivateForeignKeysOnSqlite();
}
/**
* @param Schema $schema
* @throws DBALException
*/
public function postUp(Schema $schema): void
{
$this->activateForeignKeysOnSqlite();
}
/**
@@ -68,6 +97,16 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
public function preDown(Schema $schema): void
{
$this->abortIfPlatformNotSupported();
$this->deactivateForeignKeysOnSqlite();
}
/**
* @param Schema $schema
* @throws DBALException
*/
public function postDown(Schema $schema): void
{
$this->activateForeignKeysOnSqlite();
}
/**