[arvados] updated: 2.1.0-3172-g3ce0dfd2c
git repository hosting
git at public.arvados.org
Mon Dec 12 21:45:35 UTC 2022
Summary of changes:
lib/boot/rails_db.go | 59 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 22 deletions(-)
via 3ce0dfd2ca992e3608cc37bddfc1594276925acb (commit)
from 31d3138660ee51eccaceb52f99730b6124755b93 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3ce0dfd2ca992e3608cc37bddfc1594276925acb
Author: Tom Clegg <tom at curii.com>
Date: Mon Dec 12 16:44:38 2022 -0500
19709: Test schema_migrations vs. db/migrate/*.rb.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/lib/boot/rails_db.go b/lib/boot/rails_db.go
index 44ceb263c..ad9124d7d 100644
--- a/lib/boot/rails_db.go
+++ b/lib/boot/rails_db.go
@@ -6,6 +6,7 @@ package boot
import (
"context"
+ "fmt"
"io/fs"
"os"
"path/filepath"
@@ -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)
+ if err != nil {
+ return err
+ }
// read schema_migrations table (list of migrations already
// applied) and remove those entries from todo
@@ -113,3 +96,35 @@ 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) (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") {
+ return fmt.Errorf("unexpected file in db/migrate dir: %s", fnm)
+ }
+ 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
+ return fmt.Errorf("unexpected file in db/migrate dir: %s", fnm)
+ }
+ }
+ return nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return todo, nil
+}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list