Skip to content

Commit

Permalink
entc/gen/template/dialect/sql/feature: add NamedDiff method to create…
Browse files Browse the repository at this point in the history
… named versioned migration files
  • Loading branch information
masseelch committed Mar 10, 2022
1 parent 5b184f2 commit 0754d31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions entc/gen/template/dialect/sql/feature/migrate_diff.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
10 changes: 10 additions & 0 deletions entc/integration/migrate/versioned/migrate/migrate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0754d31

Please sign in to comment.