Merge branch 'staging' into 'master'
Hotfix: Database migration caused data loss. See merge request s3lph/matemat!47
This commit is contained in:
commit
d5253bf954
1 changed files with 4 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue