plc.directory mirror
1// Code generated by ent, DO NOT EDIT.
2
3package migrate
4
5import (
6 "context"
7 "fmt"
8 "io"
9
10 "entgo.io/ent/dialect"
11 "entgo.io/ent/dialect/sql/schema"
12)
13
14var (
15 // WithGlobalUniqueID sets the universal ids options to the migration.
16 // If this option is enabled, ent migration will allocate a 1<<32 range
17 // for the ids of each entity (table).
18 // Note that this option cannot be applied on tables that already exist.
19 WithGlobalUniqueID = schema.WithGlobalUniqueID
20 // WithDropColumn sets the drop column option to the migration.
21 // If this option is enabled, ent migration will drop old columns
22 // that were used for both fields and edges. This defaults to false.
23 WithDropColumn = schema.WithDropColumn
24 // WithDropIndex sets the drop index option to the migration.
25 // If this option is enabled, ent migration will drop old indexes
26 // that were defined in the schema. This defaults to false.
27 // Note that unique constraints are defined using `UNIQUE INDEX`,
28 // and therefore, it's recommended to enable this option to get more
29 // flexibility in the schema changes.
30 WithDropIndex = schema.WithDropIndex
31 // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
32 WithForeignKeys = schema.WithForeignKeys
33)
34
35// Schema is the API for creating, migrating and dropping a schema.
36type Schema struct {
37 drv dialect.Driver
38}
39
40// NewSchema creates a new schema client.
41func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
42
43// Create creates all schema resources.
44func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
45 return Create(ctx, s, Tables, opts...)
46}
47
48// Create creates all table resources using the given schema driver.
49func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
50 migrate, err := schema.NewMigrate(s.drv, opts...)
51 if err != nil {
52 return fmt.Errorf("ent/migrate: %w", err)
53 }
54 return migrate.Create(ctx, tables...)
55}
56
57// WriteTo writes the schema changes to w instead of running them against the database.
58//
59// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
60// log.Fatal(err)
61// }
62func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
63 return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
64}