Provide feedback if no files or statements found (#32)
Provide feedback if no migration files were found
This commit is contained in:
committed by
Michał Matczuk
parent
6051038fa5
commit
cab01c8d25
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user