diff --git a/db.odin b/db.odin index 4bda676..4f71aec 100644 --- a/db.odin +++ b/db.odin @@ -4,7 +4,6 @@ import "base:runtime" import "core:crypto/hash" import "core:encoding/hex" import "core:encoding/ini" -import "core:encoding/json" import "core:fmt" import "core:mem" import "core:os" @@ -222,7 +221,6 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) { allocator := db_allocator(db) results := make([dynamic]EnvFile, 0, 10, allocator) - migrate := false for { rc = sqlite.step(stmt) if rc == sqlite.DONE { @@ -233,24 +231,13 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) { #no_bounds_check return results[:], false } - // TODO: Remove json support after next major release - remotes: [dynamic]string = --- remotes_raw := string(sqlite.column_text(stmt, 1)) - if len(remotes_raw) > 0 { - if remotes_raw[0] == '[' { - err := json.unmarshal_string(remotes_raw, &remotes, allocator = allocator) - if err != nil { - fmt.eprintf("Warning: malformed remotes JSON: %v\n", err) - } - migrate = true - } else { - split := strings.split_lines(remotes_raw, context.temp_allocator) - remotes = make([dynamic]string, 0, len(split), allocator = allocator) - for s in split { - append(&remotes, strings.clone(s, allocator)) - } - } + split := strings.split_lines(remotes_raw, context.temp_allocator) + remotes := make([dynamic]string, 0, len(split), allocator = allocator) + for s in split { + append(&remotes, strings.clone(s, allocator)) } + path := clone_cstring(sqlite.column_text(stmt, 0), allocator) append( @@ -265,10 +252,6 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) { ) } - if migrate { - migrate_remotes(db) - } - #no_bounds_check return results[:], true } @@ -364,33 +347,15 @@ db_fetch :: proc(db: ^Db, path: string) -> (EnvFile, bool) { return EnvFile{}, false } - // TODO: Remove json support after next major release - migrate := false - remotes: [dynamic]string = --- remotes_raw := string(sqlite.column_text(stmt, 1)) - if len(remotes_raw) > 0 { - if remotes_raw[0] == '[' { - err := json.unmarshal_string(remotes_raw, &remotes, allocator = allocator) - if err != nil { - fmt.eprintf("Warning: malformed remotes JSON: %v\n", err) - } - - migrate = true - } else { - split := strings.split_lines(remotes_raw, context.temp_allocator) - remotes = make([dynamic]string, 0, len(split), allocator = allocator) - for s in split { - append(&remotes, strings.clone(s, allocator)) - } - } + split := strings.split_lines(remotes_raw, context.temp_allocator) + remotes := make([dynamic]string, 0, len(split), allocator = allocator) + for s in split { + append(&remotes, strings.clone(s, allocator)) } file_path := clone_cstring(sqlite.column_text(stmt, 0), allocator) - if migrate { - migrate_remotes(db) - } - return EnvFile { path = file_path, dir = filepath.dir(file_path), @@ -525,27 +490,6 @@ db_persist :: proc(db: ^Db, f: ^EnvFile, old_path: string) -> bool { return db_insert(db, f^) } -// TODO: Remove after the next major release -migrate_remotes :: proc(db: ^Db) { - sql :: - "UPDATE envr_env_files " + - "SET remotes = COALESCE((" + - " SELECT group_concat(atom, char(10)) " + - " FROM json_each(envr_env_files.remotes)" + - "), '') " + - "WHERE remotes LIKE '[%'" - - rc := sqlite.exec(db.conn, sql, nil, nil, nil) - if rc != sqlite.OK { - fmt.eprintf("Warning: failed to migrate remotes: %s\n", sqlite.errmsg(db.conn)) - return - } - - if sqlite.changes(db.conn) > 0 { - db.changed = true - } -} - try_move_dir :: proc(db: ^Db, f: ^EnvFile, allocator: mem.Allocator) -> (bool, SyncError) { roots, ok := find_git_roots(db.cfg) if !ok {