migrate

package
v0.0.0-...-22bdbfd Latest Latest
Warning

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

Go to latest
Published: Dec 2, 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 (
	// ProductBrandColumns holds the columns for the "product_brand" table.
	ProductBrandColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
		{Name: "sort", Type: field.TypeUint32, Comment: "Sort Number | 排序编号", Default: 1},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "name", Type: field.TypeString, Comment: "品牌名称"},
		{Name: "pic_url", Type: field.TypeString, Comment: "品牌图片"},
		{Name: "description", Type: field.TypeString, Nullable: true, Comment: "品牌描述"},
	}
	// ProductBrandTable holds the schema information for the "product_brand" table.
	ProductBrandTable = &schema.Table{
		Name:       "product_brand",
		Columns:    ProductBrandColumns,
		PrimaryKey: []*schema.Column{ProductBrandColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "brand_name",
				Unique:  true,
				Columns: []*schema.Column{ProductBrandColumns[6]},
			},
		},
	}
	// ProductCategoryColumns holds the columns for the "product_category" table.
	ProductCategoryColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
		{Name: "sort", Type: field.TypeUint32, Comment: "Sort Number | 排序编号", Default: 1},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "name", Type: field.TypeString, Comment: "分类名称"},
		{Name: "pic_url", Type: field.TypeString, Comment: "移动端分类图"},
		{Name: "big_pic_url", Type: field.TypeString, Nullable: true, Comment: "PC 端分类图"},
		{Name: "parent_id", Type: field.TypeUint64, Nullable: true, Comment: "父分类编号"},
	}
	// ProductCategoryTable holds the schema information for the "product_category" table.
	ProductCategoryTable = &schema.Table{
		Name:       "product_category",
		Columns:    ProductCategoryColumns,
		PrimaryKey: []*schema.Column{ProductCategoryColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "product_category_product_category_children",
				Columns:    []*schema.Column{ProductCategoryColumns[9]},
				RefColumns: []*schema.Column{ProductCategoryColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ProductCommentColumns holds the columns for the "product_comment" table.
	ProductCommentColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "user_id", Type: field.TypeUint64, Nullable: true, Comment: "评价人的用户编号,关联 MemberUserDO 的 id 编号"},
		{Name: "user_nickname", Type: field.TypeString, Nullable: true, Comment: "评价人名称"},
		{Name: "user_avatar", Type: field.TypeString, Nullable: true, Comment: "评价人头像"},
		{Name: "anonymous", Type: field.TypeBool, Nullable: true, Comment: "是否匿名"},
		{Name: "order_id", Type: field.TypeUint64, Nullable: true, Comment: "交易订单编号,关联 TradeOrderDO 的 id 编号"},
		{Name: "order_item_id", Type: field.TypeUint64, Nullable: true, Comment: "交易订单项编号,关联 TradeOrderItemDO 的 id 编号"},
		{Name: "spu_id", Type: field.TypeUint64, Nullable: true, Comment: "商品 SPU 编号,关联 ProductSpuDO 的 id"},
		{Name: "spu_name", Type: field.TypeString, Nullable: true, Comment: "商品 SPU 名称"},
		{Name: "sku_pic_url", Type: field.TypeString, Comment: "图片地址"},
		{Name: "sku_properties", Type: field.TypeJSON, Nullable: true, Comment: "属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]"},
		{Name: "visible", Type: field.TypeBool, Nullable: true, Comment: "是否可见,true:显示false:隐藏"},
		{Name: "scores", Type: field.TypeInt8, Nullable: true, Comment: "评分星级1-5分"},
		{Name: "description_scores", Type: field.TypeInt8, Nullable: true, Comment: "描述星级 1-5 星"},
		{Name: "benefit_scores", Type: field.TypeInt8, Nullable: true, Comment: "服务星级 1-5 星"},
		{Name: "content", Type: field.TypeString, Nullable: true, Comment: "评论内容"},
		{Name: "pic_urls", Type: field.TypeString, Nullable: true, Comment: "评论图片地址数组"},
		{Name: "reply_status", Type: field.TypeBool, Nullable: true, Comment: "商家是否回复"},
		{Name: "reply_user_id", Type: field.TypeInt, Nullable: true, Comment: "回复管理员编号,关联 AdminUserDO 的 id 编号"},
		{Name: "reply_content", Type: field.TypeString, Nullable: true, Comment: "商家回复内容"},
		{Name: "reply_time", Type: field.TypeTime, Nullable: true, Comment: "商家回复时间"},
		{Name: "sku_id", Type: field.TypeUint64, Nullable: true, Comment: "商品 SKU 编号,关联 ProductSkuDO 的 id 编号"},
	}
	// ProductCommentTable holds the schema information for the "product_comment" table.
	ProductCommentTable = &schema.Table{
		Name:       "product_comment",
		Columns:    ProductCommentColumns,
		PrimaryKey: []*schema.Column{ProductCommentColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "product_comment_product_sku_comments",
				Columns:    []*schema.Column{ProductCommentColumns[24]},
				RefColumns: []*schema.Column{ProductSkuColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ProductPropertyColumns holds the columns for the "product_property" table.
	ProductPropertyColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "name", Type: field.TypeString, Nullable: true, Comment: "名称"},
		{Name: "remark", Type: field.TypeString, Nullable: true, Comment: "备注"},
	}
	// ProductPropertyTable holds the schema information for the "product_property" table.
	ProductPropertyTable = &schema.Table{
		Name:       "product_property",
		Columns:    ProductPropertyColumns,
		PrimaryKey: []*schema.Column{ProductPropertyColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "property_name",
				Unique:  false,
				Columns: []*schema.Column{ProductPropertyColumns[5]},
			},
		},
	}
	// ProductPropertyValueColumns holds the columns for the "product_property_value" table.
	ProductPropertyValueColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "name", Type: field.TypeString, Nullable: true, Comment: "名称"},
		{Name: "remark", Type: field.TypeString, Nullable: true, Comment: "备注"},
		{Name: "property_id", Type: field.TypeUint64, Nullable: true, Comment: "属性项的编号"},
	}
	// ProductPropertyValueTable holds the schema information for the "product_property_value" table.
	ProductPropertyValueTable = &schema.Table{
		Name:       "product_property_value",
		Columns:    ProductPropertyValueColumns,
		PrimaryKey: []*schema.Column{ProductPropertyValueColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "product_property_value_product_property_property_values",
				Columns:    []*schema.Column{ProductPropertyValueColumns[6]},
				RefColumns: []*schema.Column{ProductPropertyColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ProductSkuColumns holds the columns for the "product_sku" table.
	ProductSkuColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "properties", Type: field.TypeJSON, Nullable: true, Comment: "属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]"},
		{Name: "price", Type: field.TypeInt32, Comment: "商品价格,单位:分"},
		{Name: "market_price", Type: field.TypeInt32, Nullable: true, Comment: "市场价,单位:分"},
		{Name: "cost_price", Type: field.TypeInt32, Comment: "成本价,单位: 分"},
		{Name: "bar_code", Type: field.TypeString, Nullable: true, Comment: "SKU 的条形码"},
		{Name: "pic_url", Type: field.TypeString, Comment: "图片地址"},
		{Name: "stock", Type: field.TypeInt32, Nullable: true, Comment: "库存"},
		{Name: "weight", Type: field.TypeFloat64, Nullable: true, Comment: "商品重量,单位:kg 千克"},
		{Name: "volume", Type: field.TypeFloat64, Nullable: true, Comment: "商品体积,单位:m^3 平米"},
		{Name: "first_brokerage_price", Type: field.TypeInt32, Nullable: true, Comment: "一级分销的佣金,单位:分"},
		{Name: "second_brokerage_price", Type: field.TypeFloat64, Nullable: true, Comment: "二级分销的佣金,单位:分"},
		{Name: "sales_count", Type: field.TypeInt32, Nullable: true, Comment: "商品销量"},
		{Name: "spu_id", Type: field.TypeUint64, Nullable: true, Comment: "spu编号"},
	}
	// ProductSkuTable holds the schema information for the "product_sku" table.
	ProductSkuTable = &schema.Table{
		Name:       "product_sku",
		Columns:    ProductSkuColumns,
		PrimaryKey: []*schema.Column{ProductSkuColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "product_sku_product_spu_skus",
				Columns:    []*schema.Column{ProductSkuColumns[16]},
				RefColumns: []*schema.Column{ProductSpuColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ProductSpuColumns holds the columns for the "product_spu" table.
	ProductSpuColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
		{Name: "sort", Type: field.TypeUint32, Comment: "Sort Number | 排序编号", Default: 1},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
		{Name: "name", Type: field.TypeString, Comment: "商品名称"},
		{Name: "keyword", Type: field.TypeString, Nullable: true, Comment: "关键字"},
		{Name: "introduction", Type: field.TypeString, Nullable: true, Comment: "商品简介"},
		{Name: "description", Type: field.TypeString, Nullable: true, Size: 2147483647, Comment: "商品详情"},
		{Name: "bar_code", Type: field.TypeString, Nullable: true, Comment: "条形码"},
		{Name: "pic_url", Type: field.TypeString, Comment: "商品封面图"},
		{Name: "slider_pic_urls", Type: field.TypeJSON, Nullable: true, Comment: "商品轮播图地址数组,以逗号分隔最多上传15张"},
		{Name: "video_url", Type: field.TypeString, Nullable: true, Comment: "商品视频"},
		{Name: "unit", Type: field.TypeUint8, Comment: "单位"},
		{Name: "spec_type", Type: field.TypeBool, Nullable: true, Comment: "规格类型:0 单规格 1 多规格"},
		{Name: "price", Type: field.TypeInt32, Comment: "商品价格,单位使用:分"},
		{Name: "market_price", Type: field.TypeInt32, Nullable: true, Comment: "市场价,单位使用:分"},
		{Name: "cost_price", Type: field.TypeInt32, Comment: "成本价,单位: 分"},
		{Name: "stock", Type: field.TypeInt32, Comment: "库存"},
		{Name: "delivery_template_id", Type: field.TypeUint64, Nullable: true, Comment: "物流配置模板编号"},
		{Name: "recommend_hot", Type: field.TypeBool, Nullable: true, Comment: "是否热卖推荐"},
		{Name: "recommend_benefit", Type: field.TypeBool, Nullable: true, Comment: "是否优惠推荐"},
		{Name: "recommend_best", Type: field.TypeBool, Nullable: true, Comment: "是否精品推荐"},
		{Name: "recommend_new", Type: field.TypeBool, Nullable: true, Comment: "是否新品推荐"},
		{Name: "recommend_good", Type: field.TypeBool, Nullable: true, Comment: "是否优品推荐"},
		{Name: "give_integral", Type: field.TypeInt32, Nullable: true, Comment: "赠送积分"},
		{Name: "give_coupon_template_ids", Type: field.TypeJSON, Nullable: true, Comment: "赠送积分"},
		{Name: "sub_commission_type", Type: field.TypeBool, Nullable: true, Comment: "赠送积分"},
		{Name: "activity_orders", Type: field.TypeJSON, Nullable: true, Comment: "赠送积分"},
		{Name: "sales_count", Type: field.TypeInt32, Nullable: true, Comment: "商品销量"},
		{Name: "virtual_sales_count", Type: field.TypeInt32, Nullable: true, Comment: "虚拟销量"},
		{Name: "browse_count", Type: field.TypeInt32, Nullable: true, Comment: "商品点击量"},
		{Name: "brand_id", Type: field.TypeUint64, Nullable: true, Comment: "商品品牌编号"},
		{Name: "category_id", Type: field.TypeUint64, Nullable: true, Comment: "商品分类编号"},
	}
	// ProductSpuTable holds the schema information for the "product_spu" table.
	ProductSpuTable = &schema.Table{
		Name:       "product_spu",
		Columns:    ProductSpuColumns,
		PrimaryKey: []*schema.Column{ProductSpuColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "product_spu_product_brand_spus",
				Columns:    []*schema.Column{ProductSpuColumns[33]},
				RefColumns: []*schema.Column{ProductBrandColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "product_spu_product_category_spus",
				Columns:    []*schema.Column{ProductSpuColumns[34]},
				RefColumns: []*schema.Column{ProductCategoryColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ProductBrandTable,
		ProductCategoryTable,
		ProductCommentTable,
		ProductPropertyTable,
		ProductPropertyValueTable,
		ProductSkuTable,
		ProductSpuTable,
	}
)

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