From d5b960ad8a9aaa77df5dfda26af4c0171ac240b2 Mon Sep 17 00:00:00 2001 From: saji Date: Thu, 6 Jul 2023 00:24:05 -0500 Subject: [PATCH] wip: more db migration work --- internal/db/db.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/internal/db/db.go b/internal/db/db.go index a6b39de..1d97788 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -51,7 +51,7 @@ func RunMigrations(currentVer int) (finalVer int) { return nil } m := migrationRegex.FindStringSubmatch(d.Name()) - if len(m) != 5 { + if len(m) != 4 { panic("error parsing migration name") } migrationVer, _ := strconv.ParseInt(m[1], 10, 64) @@ -62,11 +62,35 @@ func RunMigrations(currentVer int) (finalVer int) { FileName: d.Name(), } - res[int(migrationVer)][m] + var mMap map[string]Migration + mMap, ok := res[int(migrationVer)] + if !ok { + mMap = make(map[string]Migration) + } + mMap[m[3]] = mig + + res[int(migrationVer)] = mMap return nil }) + // now apply the mappings based on current ver. + + for v := currentVer; v < finalVer; v++ { + // attempt to get the "up" migration. + mMap, ok := res[v] + if !ok { + panic("aa") + } + upMigration, ok := mMap["up"] + if !ok { + panic("aaa") + } + // open the file name + // execute the file. + + } + return res }