From b3a1df9e18e69decfd00bc798eaf2539308f5e31 Mon Sep 17 00:00:00 2001 From: s3lph Date: Thu, 13 Sep 2018 18:39:10 +0200 Subject: [PATCH] Hotfix: Database migration caused data loss. --- matemat/db/wrapper.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/matemat/db/wrapper.py b/matemat/db/wrapper.py index 6441f1c..4460680 100644 --- a/matemat/db/wrapper.py +++ b/matemat/db/wrapper.py @@ -62,14 +62,8 @@ class DatabaseWrapper(object): return DatabaseTransaction(self._sqlite_db, exclusive) def _setup(self) -> None: - # Enable foreign key enforcement - cursor = self._sqlite_db.cursor() - cursor.execute('PRAGMA foreign_keys = 1') - # Create or update schemas if necessary with self.transaction() as c: - # Defer foreign key enforcement in the setup transaction - c.execute('PRAGMA defer_foreign_keys = 1') version: int = self._user_version if version < 1: # Don't use executescript, as it issues a COMMIT first @@ -81,6 +75,10 @@ class DatabaseWrapper(object): raise RuntimeError('Database schema is newer than supported by this version of Matemat.') self._user_version = self.SCHEMA_VERSION + # Enable foreign key enforcement + cursor = self._sqlite_db.cursor() + cursor.execute('PRAGMA foreign_keys = 1') + def _upgrade(self, from_version: int, to_version: int) -> None: with self.transaction() as c: # Note to future s3lph: If there are further migrations, also consider upgrades like 1 -> 3