mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
* 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
29 lines
1.1 KiB
Cheetah
29 lines
1.1 KiB
Cheetah
{{/*
|
|
Copyright 2019-present Facebook Inc. All rights reserved.
|
|
This source code is licensed under the Apache 2.0 license found
|
|
in the LICENSE file in the root directory of this source tree.
|
|
*/}}
|
|
|
|
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
|
|
|
|
{{ define "migrate/diff" }}
|
|
// Diff creates a migration file containing the statements to resolve the diff
|
|
// between the Ent schema and the connected database.
|
|
func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error {
|
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
|
if err != nil {
|
|
return fmt.Errorf("ent/migrate: %w", err)
|
|
}
|
|
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 }} |