Commit 75d4dac812185f205cd459fb7b1eddb3776e1271
1 parent
d0c372c0
during db migration the database schema version is now get from database itself
Showing
2 changed files
with
41 additions
and
25 deletions
Show diff stats
database/migration_sqlite3.anubis
| @@ -213,13 +213,13 @@ define Maybe(One) | @@ -213,13 +213,13 @@ define Maybe(One) | ||
| 213 | SQLite3DataBase db, | 213 | SQLite3DataBase db, |
| 214 | (LogLevel, String) -> One logger, | 214 | (LogLevel, String) -> One logger, |
| 215 | Migration _migration, | 215 | Migration _migration, |
| 216 | - (DB_Version) -> One update_db_version | 216 | + (SQLite3DataBase , DB_Version) -> One update_db_version |
| 217 | )= | 217 | )= |
| 218 | since _migration is migration(mig_version, _, create_tables, create_indexes), | 218 | since _migration is migration(mig_version, _, create_tables, create_indexes), |
| 219 | 219 | ||
| 220 | if create_tables(db, logger) is success(_) then | 220 | if create_tables(db, logger) is success(_) then |
| 221 | if create_indexes(db, logger) is success(_) then | 221 | if create_indexes(db, logger) is success(_) then |
| 222 | - update_db_version(mig_version); | 222 | + update_db_version(db, mig_version); |
| 223 | success(unique) | 223 | success(unique) |
| 224 | else | 224 | else |
| 225 | failure | 225 | failure |
| @@ -235,7 +235,7 @@ define Maybe(One) | @@ -235,7 +235,7 @@ define Maybe(One) | ||
| 235 | // String current_version, //current version of app | 235 | // String current_version, //current version of app |
| 236 | DB_Version db_ver, //version found in db settings | 236 | DB_Version db_ver, //version found in db settings |
| 237 | List(Migration) migrations, | 237 | List(Migration) migrations, |
| 238 | - (DB_Version) -> One update_db_version, | 238 | + (SQLite3DataBase , DB_Version) -> One update_db_version |
| 239 | ) = | 239 | ) = |
| 240 | if migrations is | 240 | if migrations is |
| 241 | { | 241 | { |
| @@ -250,7 +250,7 @@ define Maybe(One) | @@ -250,7 +250,7 @@ define Maybe(One) | ||
| 250 | if migrate_to(db, logger) is failure then | 250 | if migrate_to(db, logger) is failure then |
| 251 | failure | 251 | failure |
| 252 | else | 252 | else |
| 253 | - update_db_version(migration_version); | 253 | + update_db_version(db, migration_version); |
| 254 | do_migration_loop(db, logger, migration_version, t, update_db_version) | 254 | do_migration_loop(db, logger, migration_version, t, update_db_version) |
| 255 | 255 | ||
| 256 | more then | 256 | more then |
| @@ -266,7 +266,7 @@ define Maybe(One) | @@ -266,7 +266,7 @@ define Maybe(One) | ||
| 266 | if migrate_to(db, logger) is failure then | 266 | if migrate_to(db, logger) is failure then |
| 267 | failure | 267 | failure |
| 268 | else | 268 | else |
| 269 | - update_db_version(migration_version); | 269 | + update_db_version(db, migration_version); |
| 270 | do_migration_loop(db, logger, migration_version, t, update_db_version) | 270 | do_migration_loop(db, logger, migration_version, t, update_db_version) |
| 271 | } | 271 | } |
| 272 | }. | 272 | }. |
| @@ -277,7 +277,7 @@ public define Maybe(One) | @@ -277,7 +277,7 @@ public define Maybe(One) | ||
| 277 | SQLite3DataBase db, | 277 | SQLite3DataBase db, |
| 278 | (LogLevel, String) -> One logger, | 278 | (LogLevel, String) -> One logger, |
| 279 | DB_Version current_db_version, | 279 | DB_Version current_db_version, |
| 280 | - (DB_Version) -> One update_db_version, | 280 | + (SQLite3DataBase , DB_Version) -> One update_db_version, |
| 281 | List(Migration) all_migrations, | 281 | List(Migration) all_migrations, |
| 282 | )= | 282 | )= |
| 283 | if is_empty_database(db) then // new empty database | 283 | if is_empty_database(db) then // new empty database |
database/settings_sqlite3.anubis
| @@ -17,9 +17,9 @@ public define Maybe(String) | @@ -17,9 +17,9 @@ public define Maybe(String) | ||
| 17 | select_settings | 17 | select_settings |
| 18 | ( | 18 | ( |
| 19 | SQLite3DataBase db, | 19 | SQLite3DataBase db, |
| 20 | - String var, | 20 | + String name, |
| 21 | )= | 21 | )= |
| 22 | - if sql_query_timeout(db, "SELECT var_value FROM settings WHERE var_name=" + db_make_sql_string(var) + ";", [], "select_settings") is | 22 | + if sql_query_timeout(db, "SELECT value FROM settings WHERE name = :name;", [bind_String(":name",name)], "select_settings") is |
| 23 | { | 23 | { |
| 24 | error(_) then failure, //error in the SQL request | 24 | error(_) then failure, //error in the SQL request |
| 25 | ok(_, cursor, _) then | 25 | ok(_, cursor, _) then |
| @@ -90,29 +90,29 @@ public define One | @@ -90,29 +90,29 @@ public define One | ||
| 90 | update_settings | 90 | update_settings |
| 91 | ( | 91 | ( |
| 92 | SQLite3DataBase db, | 92 | SQLite3DataBase db, |
| 93 | - String var, | 93 | + String name, |
| 94 | Bool value | 94 | Bool value |
| 95 | )= | 95 | )= |
| 96 | - with bool_str = if value is true then "true" else "false", | ||
| 97 | - with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_String(":value", bool_str)], | ||
| 98 | - if select_settings(db, var) is success(_) then | ||
| 99 | - forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings")) | 96 | + //with bool_str = if value is true then "true" else "false", |
| 97 | + with binds = (List(SQLite3Bind))[bind_String(":name", name), bind_Bool(":value", value)], | ||
| 98 | + if select_settings(db, name) is success(_) then | ||
| 99 | + forget(sql_query_timeout(db, "UPDATE settings SET value = :value WHERE name = :name;", binds, "update_settings")) | ||
| 100 | else | 100 | else |
| 101 | - forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings")) | 101 | + forget(sql_query_timeout(db, "INSERT INTO settings (name, value) VALUES (:name, :value)", binds, "update_settings")) |
| 102 | . | 102 | . |
| 103 | 103 | ||
| 104 | public define One | 104 | public define One |
| 105 | update_settings | 105 | update_settings |
| 106 | ( | 106 | ( |
| 107 | SQLite3DataBase db, | 107 | SQLite3DataBase db, |
| 108 | - String var, | 108 | + String name, |
| 109 | Int value | 109 | Int value |
| 110 | )= | 110 | )= |
| 111 | - with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_Int(":value", value)], | ||
| 112 | - if select_settings(db, var) is success(_) then | ||
| 113 | - forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings")) | 111 | + with binds = (List(SQLite3Bind))[bind_String(":name", name), bind_Int(":value", value)], |
| 112 | + if select_settings(db, name) is success(_) then | ||
| 113 | + forget(sql_query_timeout(db, "UPDATE settings SET value = :value WHERE name = :name;", binds, "update_settings")) | ||
| 114 | else | 114 | else |
| 115 | - forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings")) | 115 | + forget(sql_query_timeout(db, "INSERT INTO settings (name, value) VALUES (:name, :value)", binds, "update_settings")) |
| 116 | . | 116 | . |
| 117 | 117 | ||
| 118 | 118 | ||
| @@ -120,13 +120,29 @@ public define One | @@ -120,13 +120,29 @@ public define One | ||
| 120 | update_settings | 120 | update_settings |
| 121 | ( | 121 | ( |
| 122 | SQLite3DataBase db, | 122 | SQLite3DataBase db, |
| 123 | - String var, | 123 | + String name, |
| 124 | String value | 124 | String value |
| 125 | )= | 125 | )= |
| 126 | - with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_String(":value", value)], | ||
| 127 | - if select_settings(db, var) is success(_) then | ||
| 128 | - forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings")) | 126 | + with binds = (List(SQLite3Bind))[bind_String(":name", name), bind_String(":value", value)], |
| 127 | + if select_settings(db, name) is success(_) then | ||
| 128 | + forget(sql_query_timeout(db, "UPDATE settings SET value = :value WHERE name = :name;", binds, "update_settings")) | ||
| 129 | else | 129 | else |
| 130 | - forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings")) | 130 | + forget(sql_query_timeout(db, "INSERT INTO settings (name, value) VALUES (:name, :value)", binds, "update_settings")) |
| 131 | . | 131 | . |
| 132 | - | 132 | + |
| 133 | + | ||
| 134 | +public define Bool | ||
| 135 | + create_settings_table | ||
| 136 | + ( | ||
| 137 | + SQLite3DataBase db | ||
| 138 | + )= | ||
| 139 | + if sql_query_timeout(db, "CREATE TABLE IF NOT EXISTS settings ( | ||
| 140 | + id INTEGER PRIMARY KEY, | ||
| 141 | + name TEXT UNIQUE, | ||
| 142 | + value TEXT | ||
| 143 | + );", [], "create_settings_table") is | ||
| 144 | + { | ||
| 145 | + error(_) then false, //error in the SQL request | ||
| 146 | + ok(_, _, _) then true | ||
| 147 | + } | ||
| 148 | +. |