Database: use schema_version and application_id
This commit is contained in:
@ -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,
|
||||
|
2
sql/v01/99.schema_version.sql
Normal file
2
sql/v01/99.schema_version.sql
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
PRAGMA schema_version = 100; -- This value MUST NOT be changed while other connections are open!
|
@ -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
|
||||
|
Reference in New Issue
Block a user