load_dbm.anubis 1.53 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 11/04/2020
 * Time: 12:48
 * © David RENÉ
 */

read tools/string.anubis
read tools/basis.anubis
read xlib/database/migration_sqlite3.anubis
read xlib/database/migration_common_sqlite3.anubis

public define Maybe(Migration)
  load_dbm
  (
    String file_name
  )
  =
  if (LoadAdm(Migration))load_adm(file_name) is 
  {
    file_not_found               then print("File '"+file_name+"' not found.\n\n");failure, 
    read_error                   then print("Error reading file '"+file_name+"'.\n\n");failure, 
    timeout                      then print("Timeout when loading '"+file_name+"'.\n\n");failure, 
    file_damaged                 then print("File '"+file_name+"' is damaged.\n\n");failure, 
    bad_version(expected,found)  then print("Secondary module '"+file_name+"' doesn't have the same\n"+
                                           "  version ("+found+") as primary module ("+expected+").\n\n");failure, 
    wrong_type(expected,found)   then print("Secondary module '"+file_name+"' has different types\n\n");failure, 
    ok(db_migration)             then println("db migration v"+db_migration.version+" module loaded ");success(db_migration)
  }.
   
public define List(Migration)
  all_migrations
  (
    String app_dbm_path,
    String app_name
  )
  =
  with files = directory_list(app_dbm_path, app_name+"_dbm_to_v*.adm"),
  all_list = map_select((String file_name) |-> load_dbm(app_dbm_path+file_name), files),
  merge_sort(all_list, migration_less)
.