X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/31d3138660ee51eccaceb52f99730b6124755b93..ad5eb020d76da3ef5927b3d8c364390d42493ddd:/lib/boot/rails_db.go diff --git a/lib/boot/rails_db.go b/lib/boot/rails_db.go index 44ceb263c3..16e150172d 100644 --- a/lib/boot/rails_db.go +++ b/lib/boot/rails_db.go @@ -13,6 +13,7 @@ import ( "git.arvados.org/arvados.git/lib/controller/dblock" "git.arvados.org/arvados.git/lib/ctrlctx" + "github.com/sirupsen/logrus" ) type railsDatabase struct{} @@ -47,28 +48,10 @@ func (runner railsDatabase) Run(ctx context.Context, fail func(error), super *Su // there are no new migrations, that would add ~2s to startup // time / downtime during service restart. - todo := map[string]bool{} - - // list versions in db/migrate/{version}_{name}.rb - fs.WalkDir(os.DirFS(appdir), "db/migrate", func(path string, d fs.DirEntry, err error) error { - fnm := d.Name() - if !strings.HasSuffix(fnm, ".rb") { - return nil - } - for i, c := range fnm { - if i > 0 && c == '_' { - todo[fnm[:i]] = true - break - } - if c < '0' || c > '9' { - // non-numeric character before the - // first '_' means this is not a - // migration - break - } - } - return nil - }) + todo, err := migrationList(appdir, super.logger) + if err != nil { + return err + } // read schema_migrations table (list of migrations already // applied) and remove those entries from todo @@ -113,3 +96,37 @@ func (runner railsDatabase) Run(ctx context.Context, fail func(error), super *Su defer dblock.RailsMigrations.Unlock() return super.RunProgram(ctx, appdir, runOptions{env: railsEnv}, "bundle", "exec", "rake", "db:migrate") } + +func migrationList(dir string, log logrus.FieldLogger) (map[string]bool, error) { + todo := map[string]bool{} + + // list versions in db/migrate/{version}_{name}.rb + err := fs.WalkDir(os.DirFS(dir), "db/migrate", func(path string, d fs.DirEntry, err error) error { + if d.IsDir() { + return nil + } + fnm := d.Name() + if !strings.HasSuffix(fnm, ".rb") { + log.Warnf("unexpected file in db/migrate dir: %s", fnm) + return nil + } + for i, c := range fnm { + if i > 0 && c == '_' { + todo[fnm[:i]] = true + break + } + if c < '0' || c > '9' { + // non-numeric character before the + // first '_' means this is not a + // migration + log.Warnf("unexpected file in db/migrate dir: %s", fnm) + return nil + } + } + return nil + }) + if err != nil { + return nil, err + } + return todo, nil +}