forked from s3lph/matemat
Hotfix: Database migration caused data loss.
This commit is contained in:
parent
dcbd093eed
commit
b3a1df9e18
1 changed files with 4 additions and 6 deletions
|
@ -62,14 +62,8 @@ class DatabaseWrapper(object):
|
||||||
return DatabaseTransaction(self._sqlite_db, exclusive)
|
return DatabaseTransaction(self._sqlite_db, exclusive)
|
||||||
|
|
||||||
def _setup(self) -> None:
|
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
|
# Create or update schemas if necessary
|
||||||
with self.transaction() as c:
|
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
|
version: int = self._user_version
|
||||||
if version < 1:
|
if version < 1:
|
||||||
# Don't use executescript, as it issues a COMMIT first
|
# 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.')
|
raise RuntimeError('Database schema is newer than supported by this version of Matemat.')
|
||||||
self._user_version = self.SCHEMA_VERSION
|
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:
|
def _upgrade(self, from_version: int, to_version: int) -> None:
|
||||||
with self.transaction() as c:
|
with self.transaction() as c:
|
||||||
# Note to future s3lph: If there are further migrations, also consider upgrades like 1 -> 3
|
# Note to future s3lph: If there are further migrations, also consider upgrades like 1 -> 3
|
||||||
|
|
Loading…
Reference in a new issue