From cab01c8d2517cf5fae742968467cede98e02fec9 Mon Sep 17 00:00:00 2001 From: Vasileios Karagkounis Date: Tue, 19 Dec 2017 10:57:50 +0200 Subject: [PATCH] Provide feedback if no files or statements found (#32) Provide feedback if no migration files were found --- migrate/migrate.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/migrate/migrate.go b/migrate/migrate.go index 4bc2451..4d68b4a 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -78,6 +78,9 @@ func Migrate(ctx context.Context, session *gocql.Session, dir string) error { if err != nil { return fmt.Errorf("failed to list migrations in %q: %s", dir, err) } + if len(fm) == 0 { + return fmt.Errorf("no migration files found in %q", dir) + } sort.Strings(fm) // verify migrations @@ -149,6 +152,7 @@ func applyMigration(ctx context.Context, session *gocql.Session, path string, do defer iq.Release() i := 1 + stmtCount := 0 r := bytes.NewBuffer(b) for { stmt, err := r.ReadString(';') @@ -158,6 +162,8 @@ func applyMigration(ctx context.Context, session *gocql.Session, path string, do if err != nil { return err } + stmtCount++ + if i <= done { i++ continue @@ -178,6 +184,9 @@ func applyMigration(ctx context.Context, session *gocql.Session, path string, do i++ } + if stmtCount == 0 { + return fmt.Errorf("no migration statements found in %q", info.Name) + } return nil }