oceanbase
71 строка · 2.4 Кб
1// Code generated by entc, 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.
19WithGlobalUniqueID = 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.
23WithDropColumn = 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.
30WithDropIndex = schema.WithDropIndex
31// WithFixture sets the foreign-key renaming option to the migration when upgrading
32// ent from v0.1.0 (issue-#285). Defaults to false.
33WithFixture = schema.WithFixture
34// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
35WithForeignKeys = schema.WithForeignKeys
36)
37
38// Schema is the API for creating, migrating and dropping a schema.
39type Schema struct {
40drv dialect.Driver
41}
42
43// NewSchema creates a new schema client.
44func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
45
46// Create creates all schema resources.
47func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
48migrate, err := schema.NewMigrate(s.drv, opts...)
49if err != nil {
50return fmt.Errorf("ent/migrate: %w", err)
51}
52return migrate.Create(ctx, Tables...)
53}
54
55// WriteTo writes the schema changes to w instead of running them against the database.
56//
57// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
58// log.Fatal(err)
59// }
60//
61func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
62drv := &schema.WriteDriver{
63Writer: w,
64Driver: s.drv,
65}
66migrate, err := schema.NewMigrate(drv, opts...)
67if err != nil {
68return fmt.Errorf("ent/migrate: %w", err)
69}
70return migrate.Create(ctx, Tables...)
71}
72