1
0
Fork 0
forked from s3lph/matemat

fix: sqlite constraint migration

This commit is contained in:
s3lph 2024-12-07 21:15:08 +01:00
parent dd65b5c4d0
commit 51adba2e25
Signed by untrusted user: s3lph
GPG key ID: 0AA29A52FB33CFB5

View file

@ -74,10 +74,12 @@ class DatabaseWrapper(object):
# Enable foreign key enforcement # Enable foreign key enforcement
cursor = self._sqlite_db.cursor() cursor = self._sqlite_db.cursor()
cursor.execute('PRAGMA foreign_keys = 1') cursor.execute('PRAGMA foreign_keys=ON')
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:
c.execute('PRAGMA foreign_keys=OFF')
c.execute('PRAGMA legacy_alter_table=ON')
if from_version <= 1 and to_version >= 2: if from_version <= 1 and to_version >= 2:
migrate_schema_1_to_2(c) migrate_schema_1_to_2(c)
if from_version <= 2 and to_version >= 3: if from_version <= 2 and to_version >= 3:
@ -98,6 +100,8 @@ class DatabaseWrapper(object):
migrate_schema_8_to_9(c) migrate_schema_8_to_9(c)
if from_version <= 9 and to_version >= 10: if from_version <= 9 and to_version >= 10:
migrate_schema_9_to_10(c) migrate_schema_9_to_10(c)
c.execute('PRAGMA foreign_key_check')
c.execute('PRAGMA foreign_keys=ON')
def connect(self) -> None: def connect(self) -> None:
if self.is_connected(): if self.is_connected():