From fdbbb29cd671e01dc2c5e767391308cb3167fef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Mon, 28 Dec 2020 11:30:39 -0800 Subject: [PATCH] Sqlite migrations should have foreign keys disabled outside the transaction Existing behavior could lead to data loss if schema is changed. --- libs/picodb/lib/PicoDb/Schema.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/picodb/lib/PicoDb/Schema.php b/libs/picodb/lib/PicoDb/Schema.php index a02803680..3cfdc7e3f 100644 --- a/libs/picodb/lib/PicoDb/Schema.php +++ b/libs/picodb/lib/PicoDb/Schema.php @@ -93,8 +93,8 @@ class Schema { try { for ($i = $current_version + 1; $i <= $next_version; $i++) { - $this->db->startTransaction(); $this->db->getDriver()->disableForeignKeys(); + $this->db->startTransaction(); $function_name = $this->getNamespace().'\version_'.$i; @@ -104,8 +104,8 @@ class Schema } $this->db->getDriver()->setSchemaVersion($i); - $this->db->getDriver()->enableForeignKeys(); $this->db->closeTransaction(); + $this->db->getDriver()->enableForeignKeys(); } } catch (PDOException $e) { $this->db->setLogMessage($e->getMessage());