diff --git a/CXM_message_constants.anubis b/CXM_message_constants.anubis index e9028e7..79a6081 100644 --- a/CXM_message_constants.anubis +++ b/CXM_message_constants.anubis @@ -3,7 +3,7 @@ * User: David RENÉ * Date: 07/04/2007 * Time: 16:06 - * © Calexium + * © David RENÉ * */ diff --git a/database/migration_sqlite3.anubis b/database/migration_sqlite3.anubis index 807ff00..4b2d142 100644 --- a/database/migration_sqlite3.anubis +++ b/database/migration_sqlite3.anubis @@ -12,7 +12,9 @@ read system/logger.anubis read system/string.anubis read data_base/sqlite.anubis read calexium_lib/database/alter_table.anubis +read calexium_lib/database/db_utils.anubis read calexium_lib/net_services_protocols/logger_service.anubis +read calexium_lib/types/version.anubis read migration_common_sqlite3.anubis @@ -24,7 +26,7 @@ public type Migration: ). -define String dir_save_database = "/db_backup/". +define String dir_save_database = "db_backup/". public define Bool @@ -36,41 +38,6 @@ public define Bool db_version_less(a.version, b.version) . - -/** - * Compare two version string. Returns -1 if first is lower than second, 1 if first is greater than second, and 0 if equals. - */ -//public define Int -// compare_db_version -// ( -// String version1, -// String version2 -// ) = -// with compare = (List(String) v1, List(String) v2) |-compare-> (Int) -// if v1 is -// { -// [] then -// if v2 is -// { -// [] then 0, -// [h2 . t2] then -1 -// }, -// [h1 . t1] then -// if v2 is -// { -// [] then 1, -// [h2 . t2] then -// if h1 = h2 then compare(t1, t2) -// else -// with v1i = force_Type(decimal_scan(h1), 0), -// v2i = force_Type(decimal_scan(h2), 0), -// if v1i < v2i then -1 -// else if v1i > v2i then 1 -// else 0 -// }, -// }, -// compare(split(version1, '.'), split(version2, '.')). - public define Maybe(One) backup_database ( @@ -95,8 +62,8 @@ public define Maybe(One) with dir_save = db_path + dir_save_database, if (Maybe(String))make_directory(dir_save) is { - failure then logError(logger, "Can't create directory '"+db_path + dir_save_database+"'"); failure, - success(_) then + failure then logError(logger, "Can't create directory '"+db_path + dir_save_database+"'"); failure, + success(_) then with copy_with_log = (String src, String dst) |-> if file_exists(src) then if copy_file(src, dst) is @@ -124,6 +91,51 @@ public define Maybe(One) } //else success(unique) . + +public define Maybe(One) + backup_database + ( + Logger logger, + SQLite3DataBase db, + String db_path, + String main_db_name + )= + //we use SQLite 3.27.0 feature to backup the database. So we check the running SQLite engine version before + //to proceed + with v3_27 = version(3,27,0,0), + with sqlite_version = if sql_query_timeout(db, "SELECT sqlite_version();", "backup_database get version") is + { + error(_) then logError(logger, "Can't get sqlite version for backup");failure, + ok(_, cursor, _) then + with sqlite_version_str = db_get_String(cursor), + to_Version(sqlite_version_str) + }, + + if sqlite_version is + { + failure then logError(logger, "Can't get sqlite version for backup ");failure, + success(sqlite_v) then + //if the SQLite engine version is < 3.27 we use old method for backup + if sqlite_v.numeric +< v3_27.numeric then + logWarning(logger, "The current SQLite engine v"+sqlite_v+" doesn't support vaccum into. Fallback to previous method"); + backup_database(logger, db_path, main_db_name, []) + else + //construct the target folder for backup + with dir_save = db_path + dir_save_database, + if (Maybe(String))make_directory(dir_save) is + { + failure then logError(logger, "Can't create directory '"+db_path + dir_save_database+"'"); failure, + success(_) then + with filename = db_path + dir_save_database+get_current_datetime_condensed+"-"+main_db_name, + if sql_query(db, "VACUUM INTO '"+filename+"';") is + { + error(err) then logError(logger,db_error(err, "Can't backup database into "+filename));failure, + ok(_,) then logInfo(logger, "database backuped into "+filename);success(unique) + } + } + } +. + // //define Maybe(One) // do_migration_loop -- libgit2 0.21.4