Provide feedback if no files or statements found (#32)

Provide feedback if no migration files were found
This commit is contained in:
Vasileios Karagkounis authored and Michał Matczuk committed 2017-12-19 09:57:50 +01:00
1 parent 6051038fa5
commit cab01c8d25
1 file changed
+9
+9
View File
@@ -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
}