summaryrefslogtreecommitdiffstats
path: root/data_model/db_update.gd
blob: 595f1bcb7cd20a5be707fac1cb78b75613c0ac6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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")