github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/migrate/migrate.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package migrate 4 5 import ( 6 "context" 7 "fmt" 8 "io" 9 10 "entgo.io/ent/dialect" 11 "entgo.io/ent/dialect/sql/schema" 12 ) 13 14 var ( 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 // WithFixture sets the foreign-key renaming option to the migration when upgrading 32 // ent from v0.1.0 (issue-#285). Defaults to false. 33 WithFixture = schema.WithFixture 34 // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. 35 WithForeignKeys = schema.WithForeignKeys 36 ) 37 38 // Schema is the API for creating, migrating and dropping a schema. 39 type Schema struct { 40 drv dialect.Driver 41 } 42 43 // NewSchema creates a new schema client. 44 func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } 45 46 // Create creates all schema resources. 47 func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { 48 migrate, err := schema.NewMigrate(s.drv, opts...) 49 if err != nil { 50 return fmt.Errorf("ent/migrate: %w", err) 51 } 52 return 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 // 61 func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { 62 drv := &schema.WriteDriver{ 63 Writer: w, 64 Driver: s.drv, 65 } 66 migrate, err := schema.NewMigrate(drv, opts...) 67 if err != nil { 68 return fmt.Errorf("ent/migrate: %w", err) 69 } 70 return migrate.Create(ctx, Tables...) 71 }