Sqlite migrations should have foreign keys disabled outside the transaction

Existing behavior could lead to data loss if schema is changed.
This commit is contained in:
Frédéric Guillot
2020-12-28 11:30:39 -08:00
committed by fguillot
parent aad436d219
commit fdbbb29cd6

View File

@@ -93,8 +93,8 @@ class Schema
{ {
try { try {
for ($i = $current_version + 1; $i <= $next_version; $i++) { for ($i = $current_version + 1; $i <= $next_version; $i++) {
$this->db->startTransaction();
$this->db->getDriver()->disableForeignKeys(); $this->db->getDriver()->disableForeignKeys();
$this->db->startTransaction();
$function_name = $this->getNamespace().'\version_'.$i; $function_name = $this->getNamespace().'\version_'.$i;
@@ -104,8 +104,8 @@ class Schema
} }
$this->db->getDriver()->setSchemaVersion($i); $this->db->getDriver()->setSchemaVersion($i);
$this->db->getDriver()->enableForeignKeys();
$this->db->closeTransaction(); $this->db->closeTransaction();
$this->db->getDriver()->enableForeignKeys();
} }
} catch (PDOException $e) { } catch (PDOException $e) {
$this->db->setLogMessage($e->getMessage()); $this->db->setLogMessage($e->getMessage());