dialect/sql/schema: add name to versioned migration files (#2375)

* add name to versioned migration files

* Skip writing migration files if the plan has no changes
This commit is contained in:
Huy TQ
2022-03-07 16:18:07 +07:00
committed by GitHub
parent 3aab4d91c2
commit ddddc1d92a
2 changed files with 5 additions and 1 deletions

View File

@@ -364,7 +364,7 @@ func (m *Migrate) atDiff(ctx context.Context, conn dialect.ExecQuerier, tables .
return nil, err
}
// Plan changes.
return drv.PlanChanges(ctx, "", changes)
return drv.PlanChanges(ctx, "changes", changes)
}
type db struct{ dialect.ExecQuerier }

View File

@@ -171,6 +171,10 @@ func (m *Migrate) Diff(ctx context.Context, tables ...*Table) error {
if err != nil {
return err
}
// Skip if the plan has no changes
if len(plan.Changes) == 0 {
return nil
}
return migrate.NewPlanner(nil, m.atlas.dir, migrate.WithFormatter(m.atlas.fmt)).WritePlan(plan)
}