migrate

package
v1.0.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 7 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
	// WithFixture sets the foreign-key renaming option to the migration when upgrading
	// ent from v0.1.0 (issue-#285). Defaults to false.
	WithFixture = schema.WithFixture
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// UserProfileColumns holds the columns for the "user_profile" table.
	UserProfileColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "sn", Type: field.TypeString, Unique: true, Size: 22},
		{Name: "nickname", Type: field.TypeString, Size: 20},
		{Name: "gender", Type: field.TypeEnum, Enums: []string{"UNKNOWN", "MALE", "FEMALE"}, Default: "UNKNOWN"},
		{Name: "plan", Type: field.TypeEnum, Nullable: true, Enums: []string{"FREE"}, Default: "FREE"},
		{Name: "avatar_url", Type: field.TypeString, Nullable: true, Size: 2147483647, Default: ""},
		{Name: "phone", Type: field.TypeString, Nullable: true, Size: 20},
		{Name: "second_auth", Type: field.TypeBool, Default: false},
		{Name: "password", Type: field.TypeString, Nullable: true, Size: 140, Default: "NOT_SET"},
		{Name: "status", Type: field.TypeEnum, Nullable: true, Enums: []string{"BLACKLIST"}},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "delete_time", Type: field.TypeTime, Nullable: true},
	}
	// UserProfileTable holds the schema information for the "user_profile" table.
	UserProfileTable = &schema.Table{
		Name:        "user_profile",
		Columns:     UserProfileColumns,
		PrimaryKey:  []*schema.Column{UserProfileColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
		Indexes: []*schema.Index{
			{
				Name:    "user_sn",
				Unique:  true,
				Columns: []*schema.Column{UserProfileColumns[1]},
			},
			{
				Name:    "user_gender_plan_create_time_update_time",
				Unique:  false,
				Columns: []*schema.Column{UserProfileColumns[3], UserProfileColumns[4], UserProfileColumns[10], UserProfileColumns[11]},
			},
		},
	}
	// UserEmailColumns holds the columns for the "user_email" table.
	UserEmailColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "sn", Type: field.TypeString, Unique: true, Size: 22},
		{Name: "email", Type: field.TypeString, Size: 30},
		{Name: "verify_ticket", Type: field.TypeString, Nullable: true, Size: 22},
		{Name: "verify_time", Type: field.TypeTime, Nullable: true},
		{Name: "is_primary", Type: field.TypeBool, Default: false},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "owner_id", Type: field.TypeInt, Nullable: true},
	}
	// UserEmailTable holds the schema information for the "user_email" table.
	UserEmailTable = &schema.Table{
		Name:       "user_email",
		Columns:    UserEmailColumns,
		PrimaryKey: []*schema.Column{UserEmailColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_email_user_profile_UserEmails",
				Columns:    []*schema.Column{UserEmailColumns[8]},
				RefColumns: []*schema.Column{UserProfileColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "useremail_owner_id_is_primary_create_time_update_time",
				Unique:  false,
				Columns: []*schema.Column{UserEmailColumns[8], UserEmailColumns[5], UserEmailColumns[6], UserEmailColumns[7]},
			},
			{
				Name:    "useremail_email",
				Unique:  true,
				Columns: []*schema.Column{UserEmailColumns[2]},
			},
		},
	}
	// UserGroupColumns holds the columns for the "user_group" table.
	UserGroupColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "sn", Type: field.TypeString, Unique: true, Size: 22},
		{Name: "name", Type: field.TypeString, Unique: true, Size: 20},
		{Name: "avatar_url", Type: field.TypeString, Nullable: true, Size: 200},
		{Name: "address", Type: field.TypeString, Nullable: true},
		{Name: "homepage", Type: field.TypeString, Nullable: true, Size: 100},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
	}
	// UserGroupTable holds the schema information for the "user_group" table.
	UserGroupTable = &schema.Table{
		Name:        "user_group",
		Columns:     UserGroupColumns,
		PrimaryKey:  []*schema.Column{UserGroupColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
		Indexes: []*schema.Index{
			{
				Name:    "usergroup_create_time",
				Unique:  false,
				Columns: []*schema.Column{UserGroupColumns[6]},
			},
			{
				Name:    "usergroup_update_time",
				Unique:  false,
				Columns: []*schema.Column{UserGroupColumns[7]},
			},
			{
				Name:    "usergroup_sn_name",
				Unique:  true,
				Columns: []*schema.Column{UserGroupColumns[1], UserGroupColumns[2]},
			},
		},
	}
	// UserSecurityLogColumns holds the columns for the "user_security_log" table.
	UserSecurityLogColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "action", Type: field.TypeEnum, Enums: []string{"UNKNOWN", "SIGN_IN", "SIGN_OUT", "PWD_AUTH", "SIGN_UP_EMAIL", "SIGN_IN___PWD", "SIGN_IN___PHONE", "SIGN_IN___EMAIL", "2ND_AUTH___PWD", "2ND_AUTH___PHONE", "2ND_AUTH___EMAIL"}, Default: "UNKNOWN"},
		{Name: "ip", Type: field.TypeString, Nullable: true, Size: 128},
		{Name: "request_id", Type: field.TypeString, Nullable: true, Size: 100},
		{Name: "server_version", Type: field.TypeString, Nullable: true, Size: 50},
		{Name: "description", Type: field.TypeString, Nullable: true, Size: 200},
		{Name: "remark", Type: field.TypeString, Nullable: true, Size: 200},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "owner_id", Type: field.TypeInt, Nullable: true},
	}
	// UserSecurityLogTable holds the schema information for the "user_security_log" table.
	UserSecurityLogTable = &schema.Table{
		Name:       "user_security_log",
		Columns:    UserSecurityLogColumns,
		PrimaryKey: []*schema.Column{UserSecurityLogColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_security_log_user_profile_UserSecurityLogs",
				Columns:    []*schema.Column{UserSecurityLogColumns[8]},
				RefColumns: []*schema.Column{UserProfileColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// UserSettingColumns holds the columns for the "user_setting" table.
	UserSettingColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "key", Type: field.TypeString, Unique: true, Size: 100},
		{Name: "value", Type: field.TypeString, Nullable: true, Size: 2147483647, Default: ""},
		{Name: "typeof", Type: field.TypeEnum, Enums: []string{"STRING", "BOOL", "INT"}, Default: "STRING"},
		{Name: "expires", Type: field.TypeTime, Nullable: true},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "owner_id", Type: field.TypeInt, Nullable: true},
	}
	// UserSettingTable holds the schema information for the "user_setting" table.
	UserSettingTable = &schema.Table{
		Name:       "user_setting",
		Columns:    UserSettingColumns,
		PrimaryKey: []*schema.Column{UserSettingColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_setting_user_profile_UserSettings",
				Columns:    []*schema.Column{UserSettingColumns[6]},
				RefColumns: []*schema.Column{UserProfileColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "usersetting_owner_id_key",
				Unique:  false,
				Columns: []*schema.Column{UserSettingColumns[6], UserSettingColumns[1]},
			},
		},
	}
	// UserGroupUsersColumns holds the columns for the "user_group_users" table.
	UserGroupUsersColumns = []*schema.Column{
		{Name: "user_group_id", Type: field.TypeInt},
		{Name: "user_id", Type: field.TypeInt},
	}
	// UserGroupUsersTable holds the schema information for the "user_group_users" table.
	UserGroupUsersTable = &schema.Table{
		Name:       "user_group_users",
		Columns:    UserGroupUsersColumns,
		PrimaryKey: []*schema.Column{UserGroupUsersColumns[0], UserGroupUsersColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_group_users_user_group_id",
				Columns:    []*schema.Column{UserGroupUsersColumns[0]},
				RefColumns: []*schema.Column{UserGroupColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "user_group_users_user_id",
				Columns:    []*schema.Column{UserGroupUsersColumns[1]},
				RefColumns: []*schema.Column{UserProfileColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		UserProfileTable,
		UserEmailTable,
		UserGroupTable,
		UserSecurityLogTable,
		UserSettingTable,
		UserGroupUsersTable,
	}
)

Functions

This section is empty.

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