Database: use schema_version and application_id

This commit is contained in:
2023-09-17 18:58:11 +02:00
parent eac0f4f6a9
commit 5249b7a054
4 changed files with 9 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

@ -152,3 +152,6 @@ date,from,to,hours,category,name
2023-09-12,10:00,12:00,2,database,Credit
2023-09-12,14:00,17:30,3.5,wpf,Credit
2023-09-12,21:00,23:00,2,wpf,Cleanup and build
2023-09-13,21:45,23:30,1.75,wpf,DeliveryAdminWindow fixes
2023-09-14,20:45,23:45,4,wpf,Small bugfixes
2023-09-17,17:00,19:00,2,database,use schema_version and application_id

1 date from to hours category name
152 2023-09-12 10:00 12:00 2 database Credit
153 2023-09-12 14:00 17:30 3.5 wpf Credit
154 2023-09-12 21:00 23:00 2 wpf Cleanup and build
155 2023-09-13 21:45 23:30 1.75 wpf DeliveryAdminWindow fixes
156 2023-09-14 20:45 23:45 4 wpf Small bugfixes
157 2023-09-17 17:00 19:00 2 database use schema_version and application_id

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