summaryrefslogtreecommitdiffstats
path: root/data_model/db_update.gd
diff options
context:
space:
mode:
Diffstat (limited to 'data_model/db_update.gd')
-rw-r--r--data_model/db_update.gd23
1 files changed, 23 insertions, 0 deletions
diff --git a/data_model/db_update.gd b/data_model/db_update.gd
new file mode 100644
index 0000000..595f1bc
--- /dev/null
+++ b/data_model/db_update.gd
@@ -0,0 +1,23 @@
+class_name db_update
+
+static func update(DBMS):
+ while true:
+ var version = get_version(DBMS)
+ match version:
+ [0,1,0]: break
+ _: exec_sql_file(DBMS, "res://data_model/schema.sql")
+ #insert_test_data(DBMS)
+
+static func get_version(DBMS):
+ var version = DBMS.query("select * from Version", [])
+ return [0,0,0] if version.size() == 0 else [version[0]['major'],version[0]['minor'],version[0]['patch']]
+
+static func exec_sql_file(DBMS, file):
+ var f = File.new()
+ f.open(file, File.READ)
+ var sql = f.get_as_text()
+ f.close()
+ DBMS.query(sql,[])
+
+static func insert_test_data(DBMS):
+ exec_sql_file(DBMS, "res://data_model/test_data.sql")