1
0
Fork 0
forked from s3lph/matemat

Merge branch 'staging' into 'master'

Hotfix: Database migration caused data loss.

See merge request s3lph/matemat!47
This commit is contained in:
s3lph 2018-09-13 16:50:36 +00:00
commit d5253bf954

View file

@ -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