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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to list migrations in %q: %s", dir, err)
|
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)
|
sort.Strings(fm)
|
||||||
|
|
||||||
// verify migrations
|
// verify migrations
|
||||||
@@ -149,6 +152,7 @@ func applyMigration(ctx context.Context, session *gocql.Session, path string, do
|
|||||||
defer iq.Release()
|
defer iq.Release()
|
||||||
|
|
||||||
i := 1
|
i := 1
|
||||||
|
stmtCount := 0
|
||||||
r := bytes.NewBuffer(b)
|
r := bytes.NewBuffer(b)
|
||||||
for {
|
for {
|
||||||
stmt, err := r.ReadString(';')
|
stmt, err := r.ReadString(';')
|
||||||
@@ -158,6 +162,8 @@ func applyMigration(ctx context.Context, session *gocql.Session, path string, do
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
stmtCount++
|
||||||
|
|
||||||
if i <= done {
|
if i <= done {
|
||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
@@ -178,6 +184,9 @@ func applyMigration(ctx context.Context, session *gocql.Session, path string, do
|
|||||||
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
if stmtCount == 0 {
|
||||||
|
return fmt.Errorf("no migration statements found in %q", info.Name)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user