migrate

package
v0.0.0-...-aa092f0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 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
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// RdMessageColumns holds the columns for the "rd_message" table.
	RdMessageColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
		{Name: "sender_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "recver_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "content", Type: field.TypeJSON},
		{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
	}
	// RdMessageTable holds the schema information for the "rd_message" table.
	RdMessageTable = &schema.Table{
		Name:       "rd_message",
		Columns:    RdMessageColumns,
		PrimaryKey: []*schema.Column{RdMessageColumns[0]},
	}
	// RdMomentColumns holds the columns for the "rd_moment" table.
	RdMomentColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "type", Type: field.TypeInt32, Nullable: true, Default: 1},
		{Name: "by_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "txt", Type: field.TypeString, Size: 2147483647},
		{Name: "imgs", Type: field.TypeJSON},
		{Name: "status", Type: field.TypeInt32, Nullable: true},
		{Name: "publish_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
	}
	// RdMomentTable holds the schema information for the "rd_moment" table.
	RdMomentTable = &schema.Table{
		Name:       "rd_moment",
		Columns:    RdMomentColumns,
		PrimaryKey: []*schema.Column{RdMomentColumns[0]},
	}
	// RdRMomentsFollowingColumns holds the columns for the "rd_r_moments_following" table.
	RdRMomentsFollowingColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "moment_id", Type: field.TypeInt64, Nullable: true, Default: 1},
		{Name: "moment_type", Type: field.TypeInt32, Nullable: true, Default: 1},
		{Name: "by_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "for_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "txt", Type: field.TypeString, Size: 2147483647},
		{Name: "imgs", Type: field.TypeJSON},
		{Name: "status", Type: field.TypeInt32, Nullable: true},
		{Name: "publish_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
	}
	// RdRMomentsFollowingTable holds the schema information for the "rd_r_moments_following" table.
	RdRMomentsFollowingTable = &schema.Table{
		Name:       "rd_r_moments_following",
		Columns:    RdRMomentsFollowingColumns,
		PrimaryKey: []*schema.Column{RdRMomentsFollowingColumns[0]},
	}
	// RdRUserFollowersColumns holds the columns for the "rd_r_user_followers" table.
	RdRUserFollowersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "uid", Type: field.TypeInt32, Nullable: true},
		{Name: "followers_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
	}
	// RdRUserFollowersTable holds the schema information for the "rd_r_user_followers" table.
	RdRUserFollowersTable = &schema.Table{
		Name:       "rd_r_user_followers",
		Columns:    RdRUserFollowersColumns,
		PrimaryKey: []*schema.Column{RdRUserFollowersColumns[0]},
	}
	// RdRUserFollowingColumns holds the columns for the "rd_r_user_following" table.
	RdRUserFollowingColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt64, Increment: true},
		{Name: "uid", Type: field.TypeInt32, Nullable: true},
		{Name: "following_uid", Type: field.TypeInt32, Nullable: true},
		{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
	}
	// RdRUserFollowingTable holds the schema information for the "rd_r_user_following" table.
	RdRUserFollowingTable = &schema.Table{
		Name:       "rd_r_user_following",
		Columns:    RdRUserFollowingColumns,
		PrimaryKey: []*schema.Column{RdRUserFollowingColumns[0]},
	}
	// RdUserColumns holds the columns for the "rd_user" table.
	RdUserColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt32, Increment: true},
		{Name: "nick", Type: field.TypeString},
		{Name: "status", Type: field.TypeInt32, Default: 1},
		{Name: "create_time", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
	}
	// RdUserTable holds the schema information for the "rd_user" table.
	RdUserTable = &schema.Table{
		Name:       "rd_user",
		Columns:    RdUserColumns,
		PrimaryKey: []*schema.Column{RdUserColumns[0]},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		RdMessageTable,
		RdMomentTable,
		RdRMomentsFollowingTable,
		RdRUserFollowersTable,
		RdRUserFollowingTable,
		RdUserTable,
	}
)

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