Skip to content

Commit 331c25f

Browse files
Handle errors in UpdateVirtualSchema (#693)
Stop swallowing errors in the `UpdateVirtualSchema` method used to replay virtual schema changes prior to migration rollback.
1 parent e337b62 commit 331c25f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkg/migrations/migrations.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,18 @@ func (m *Migration) Validate(ctx context.Context, s *schema.Schema) error {
9292

9393
// UpdateVirtualSchema updates the in-memory schema representation with the changes
9494
// made by the migration. No changes are made to the physical database.
95-
func (m *Migration) UpdateVirtualSchema(ctx context.Context, s *schema.Schema) {
95+
func (m *Migration) UpdateVirtualSchema(ctx context.Context, s *schema.Schema) error {
9696
db := &db.FakeDB{}
9797
tr := SQLTransformerFunc(func(sql string) (string, error) { return sql, nil })
9898

9999
// Run `Start` on each operation using the fake DB. Updates will be made to
100100
// the in-memory schema `s` without touching the physical database.
101101
for _, op := range m.Operations {
102-
op.Start(ctx, db, "", tr, s)
102+
if _, err := op.Start(ctx, db, "", tr, s); err != nil {
103+
return err
104+
}
103105
}
106+
return nil
104107
}
105108

106109
// ContainsRawSQLOperation returns true if the migration contains a raw SQL operation

pkg/roll/execute.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ func (m *Roll) Rollback(ctx context.Context) error {
261261
}
262262

263263
// update the in-memory schema with the results of applying the migration
264-
migration.UpdateVirtualSchema(ctx, schema)
264+
if err := migration.UpdateVirtualSchema(ctx, schema); err != nil {
265+
return fmt.Errorf("unable to replay changes to in-memory schema: %w", err)
266+
}
265267

266268
// roll back operations in reverse order
267269
for i := len(migration.Operations) - 1; i >= 0; i-- {

0 commit comments

Comments
 (0)