dialect/sql/schema: skip destructive table changes (#3253)

This will be fixed also in Atlas, but having this extra safety here feels safer
This commit is contained in:
Ariel Mashraki
2023-01-19 15:33:17 +02:00
committed by GitHub
parent a85377846f
commit 7ed84a86a8
5 changed files with 30 additions and 18 deletions

View File

@@ -789,7 +789,17 @@ func (a *Atlas) diff(ctx context.Context, name string, current, desired *schema.
if err != nil {
return nil, err
}
plan, err := a.atDriver.PlanChanges(ctx, name, changes, opts...)
filtered := make([]schema.Change, 0, len(changes))
for _, c := range changes {
// Skip any table drops explicitly. The reason we may encounter this, even though specific tables are passed
// to Inspect, is if the MySQL system variable 'lower_case_table_names' is set to 1. In such a case, the given
// tables will be returned from inspection because MySQL compares case-insensitive, but they won't match when
// compare them in code.
if _, ok := c.(*schema.DropTable); !ok {
filtered = append(filtered, c)
}
}
plan, err := a.atDriver.PlanChanges(ctx, name, filtered, opts...)
if err != nil {
return nil, err
}