dialect/sql/schema: add method to create a named versioned migration … (#2385)

* dialect/sql/schema: add method to create a named versioned migration file

* doc/md: documentation for named versioned migrations

* entc/gen/template/dialect/sql/feature: add NamedDiff method to create named versioned migration files

* all: go generate

* doc/md: apply CR
This commit is contained in:
MasseElch
2022-03-10 16:40:57 +01:00
committed by GitHub
parent 342088fcce
commit 2853afc1dc
5 changed files with 36 additions and 4 deletions

View File

@@ -16,4 +16,14 @@ func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error {
}
return migrate.Diff(ctx, Tables...)
}
// NamedDiff creates a named migration file containing the statements to resolve the diff
// between the Ent schema and the connected database.
func (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.NamedDiff(ctx, name, Tables...)
}
{{ end }}