migrate

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// WithGlobalUniqueID sets the universal ids options to the migration.
	// If this option is enabled, ent migration will allocate a 1<<32 range
	// for the ids of each entity (table).
	// Note that this option cannot be applied on tables that already exist.
	WithGlobalUniqueID = schema.WithGlobalUniqueID
	// WithDropColumn sets the drop column option to the migration.
	// If this option is enabled, ent migration will drop old columns
	// that were used for both fields and edges. This defaults to false.
	WithDropColumn = schema.WithDropColumn
	// WithDropIndex sets the drop index option to the migration.
	// If this option is enabled, ent migration will drop old indexes
	// that were defined in the schema. This defaults to false.
	// Note that unique constraints are defined using `UNIQUE INDEX`,
	// and therefore, it's recommended to enable this option to get more
	// flexibility in the schema changes.
	WithDropIndex = schema.WithDropIndex
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// IssueForEntsColumns holds the columns for the "issue_for_ents" table.
	IssueForEntsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "repository_for_ent_issue_for_ents", Type: field.TypeInt, Nullable: true},
	}
	// IssueForEntsTable holds the schema information for the "issue_for_ents" table.
	IssueForEntsTable = &schema.Table{
		Name:       "issue_for_ents",
		Columns:    IssueForEntsColumns,
		PrimaryKey: []*schema.Column{IssueForEntsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "issue_for_ents_repository_for_ents_issue_for_ents",
				Columns:    []*schema.Column{IssueForEntsColumns[1]},
				RefColumns: []*schema.Column{RepositoryForEntsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// RepositoryForEntsColumns holds the columns for the "repository_for_ents" table.
	RepositoryForEntsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// RepositoryForEntsTable holds the schema information for the "repository_for_ents" table.
	RepositoryForEntsTable = &schema.Table{
		Name:       "repository_for_ents",
		Columns:    RepositoryForEntsColumns,
		PrimaryKey: []*schema.Column{RepositoryForEntsColumns[0]},
	}
	// Table01forEntsColumns holds the columns for the "table01for_ents" table.
	Table01forEntsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "common_field01", Type: field.TypeInt, Nullable: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "field01", Type: field.TypeString, Unique: true},
		{Name: "field02", Type: field.TypeInt},
		{Name: "field03", Type: field.TypeBool, Default: false},
		{Name: "field04", Type: field.TypeEnum, Enums: []string{"value01", "value02"}, Default: "value01"},
		{Name: "field05", Type: field.TypeString, Nullable: true},
		{Name: "field06", Type: field.TypeString, Nullable: true},
		{Name: "field07", Type: field.TypeInt64},
		{Name: "field08", Type: field.TypeFloat64, Default: 1, SchemaType: map[string]string{"mysql": "decimal(6,2)", "postgres": "numeric"}},
		{Name: "field09", Type: field.TypeString, Default: "Field"},
		{Name: "field10", Type: field.TypeString, Nullable: true},
		{Name: "field11", Type: field.TypeString, Nullable: true},
		{Name: "field12", Type: field.TypeString, Nullable: true, Comment: "comment"},
		{Name: "field13", Type: field.TypeString, Nullable: true},
		{Name: "storage_key", Type: field.TypeString, Nullable: true},
		{Name: "field15", Type: field.TypeString, Nullable: true},
	}
	// Table01forEntsTable holds the schema information for the "table01for_ents" table.
	Table01forEntsTable = &schema.Table{
		Name:       "table01for_ents",
		Columns:    Table01forEntsColumns,
		PrimaryKey: []*schema.Column{Table01forEntsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "table01forent_field01_field07",
				Unique:  true,
				Columns: []*schema.Column{Table01forEntsColumns[4], Table01forEntsColumns[10]},
			},
			{
				Name:    "table01forent_field02_field03",
				Unique:  false,
				Columns: []*schema.Column{Table01forEntsColumns[5], Table01forEntsColumns[6]},
			},
		},
	}
	// UserForEntsColumns holds the columns for the "user_for_ents" table.
	UserForEntsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// UserForEntsTable holds the schema information for the "user_for_ents" table.
	UserForEntsTable = &schema.Table{
		Name:       "user_for_ents",
		Columns:    UserForEntsColumns,
		PrimaryKey: []*schema.Column{UserForEntsColumns[0]},
	}
	// RepositoryForEntUserForEntsColumns holds the columns for the "repository_for_ent_user_for_ents" table.
	RepositoryForEntUserForEntsColumns = []*schema.Column{
		{Name: "repository_for_ent_id", Type: field.TypeInt},
		{Name: "user_for_ent_id", Type: field.TypeInt},
	}
	// RepositoryForEntUserForEntsTable holds the schema information for the "repository_for_ent_user_for_ents" table.
	RepositoryForEntUserForEntsTable = &schema.Table{
		Name:       "repository_for_ent_user_for_ents",
		Columns:    RepositoryForEntUserForEntsColumns,
		PrimaryKey: []*schema.Column{RepositoryForEntUserForEntsColumns[0], RepositoryForEntUserForEntsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "repository_for_ent_user_for_ents_repository_for_ent_id",
				Columns:    []*schema.Column{RepositoryForEntUserForEntsColumns[0]},
				RefColumns: []*schema.Column{RepositoryForEntsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "repository_for_ent_user_for_ents_user_for_ent_id",
				Columns:    []*schema.Column{RepositoryForEntUserForEntsColumns[1]},
				RefColumns: []*schema.Column{UserForEntsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		IssueForEntsTable,
		RepositoryForEntsTable,
		Table01forEntsTable,
		UserForEntsTable,
		RepositoryForEntUserForEntsTable,
	}
)

Functions

func Create

func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error

Create creates all table resources using the given schema driver.

Types

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema is the API for creating, migrating and dropping a schema.

func NewSchema

func NewSchema(drv dialect.Driver) *Schema

NewSchema creates a new schema client.

func (*Schema) Create

func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error

Create creates all schema resources.

func (*Schema) WriteTo

func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error

WriteTo writes the schema changes to w instead of running them against the database.

if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
	log.Fatal(err)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL