Database: use schema_version and application_id

This commit is contained in:
2023-09-17 18:58:11 +02:00
parent db51e069bc
commit 8f78c8ce89
3 changed files with 6 additions and 10 deletions

View File

@ -1,16 +1,8 @@
PRAGMA application_id = 0x454C5747; -- ASCII: "ELWG"
PRAGMA user_version = 0; -- Product version. 4-byte integer: 1st - major, 2nd - minor, 3rd+4th - patch
PRAGMA foreign_keys = ON;
CREATE TABLE meta (
name TEXT NOT NULL CHECK (name REGEXP '^[a-z_]+$'),
value TEXT NOT NULL,
CONSTRAINT pk_meta PRIMARY KEY (name)
) STRICT;
INSERT INTO meta (name, value)
VALUES ('schema_version', '1');
CREATE TABLE client_parameter (
param TEXT NOT NULL CHECK (param REGEXP '^[A-Z_]+$'),
value TEXT,

View File

@ -0,0 +1,2 @@
PRAGMA schema_version = 100; -- This value MUST NOT be changed while other connections are open!

View File

@ -117,6 +117,7 @@ def main() -> None:
with open(file_name, encoding='utf-8') as sql_file:
print(f'Executing {file_name}')
cnx.executescript(sql_file.read())
ver = cnx.execute("PRAGMA schema_version").fetchall()[0][0]
try:
cnx.isolation_level = None
@ -129,6 +130,7 @@ def main() -> None:
raise RuntimeError('foreign key constraint failed')
cnx.execute("COMMIT")
cnx.execute("VACUUM")
cnx.execute(f"PRAGMA schema_version = {ver}")
except Exception as err:
cnx.execute("ROLLBACK")
raise err