bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/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  	universalID bool
    42  }
    43  
    44  // NewSchema creates a new schema client.
    45  func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
    46  
    47  // Create creates all schema resources.
    48  func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
    49  	migrate, err := schema.NewMigrate(s.drv, opts...)
    50  	if err != nil {
    51  		return fmt.Errorf("ent/migrate: %w", err)
    52  	}
    53  	return migrate.Create(ctx, Tables...)
    54  }
    55  
    56  // WriteTo writes the schema changes to w instead of running them against the database.
    57  //
    58  // 	if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
    59  //		log.Fatal(err)
    60  // 	}
    61  //
    62  func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
    63  	drv := &schema.WriteDriver{
    64  		Writer: w,
    65  		Driver: s.drv,
    66  	}
    67  	migrate, err := schema.NewMigrate(drv, opts...)
    68  	if err != nil {
    69  		return fmt.Errorf("ent/migrate: %w", err)
    70  	}
    71  	return migrate.Create(ctx, Tables...)
    72  }