migrate

package
v0.0.0-...-24d6c83 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 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 (
	// ThingDeviceDurationColumns holds the columns for the "thing_device_duration" table.
	ThingDeviceDurationColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "date", Type: field.TypeString, Nullable: true, Comment: "Date | 日期"},
		{Name: "stand_by", Type: field.TypeInt32, Nullable: true, Comment: "StandBy | 待机"},
		{Name: "preparation", Type: field.TypeInt32, Nullable: true, Comment: "Preparation | 准备"},
		{Name: "waiting", Type: field.TypeInt32, Nullable: true, Comment: "Waiting | 等待"},
		{Name: "washing_cold", Type: field.TypeInt32, Nullable: true, Comment: "Washing Cold | 洗涤冷"},
		{Name: "washing", Type: field.TypeInt32, Nullable: true, Comment: "Washing | 洗涤热"},
		{Name: "ebutton", Type: field.TypeInt32, Nullable: true, Comment: "Ebutton | 紧急按钮"},
		{Name: "day_json", Type: field.TypeString, Nullable: true, Size: 2147483647, Comment: "Day Json | 每日详情"},
	}
	// ThingDeviceDurationTable holds the schema information for the "thing_device_duration" table.
	ThingDeviceDurationTable = &schema.Table{
		Name:       "thing_device_duration",
		Columns:    ThingDeviceDurationColumns,
		PrimaryKey: []*schema.Column{ThingDeviceDurationColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceduration_iot_id_date",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceDurationColumns[5], ThingDeviceDurationColumns[8]},
			},
		},
	}
	// ThingDeviceDurationElephantColumns holds the columns for the "thing_device_duration_elephant" table.
	ThingDeviceDurationElephantColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "date", Type: field.TypeString, Nullable: true, Comment: "Date | 日期"},
		{Name: "connected", Type: field.TypeInt32, Nullable: true, Comment: "Connected | 已连接"},
		{Name: "running", Type: field.TypeInt32, Nullable: true, Comment: "running | 运行"},
		{Name: "ebutton", Type: field.TypeInt32, Nullable: true, Comment: "Ebutton | 紧急按钮"},
		{Name: "day_json", Type: field.TypeString, Nullable: true, Size: 2147483647, Comment: "Day Json | 每日详情"},
	}
	// ThingDeviceDurationElephantTable holds the schema information for the "thing_device_duration_elephant" table.
	ThingDeviceDurationElephantTable = &schema.Table{
		Name:       "thing_device_duration_elephant",
		Columns:    ThingDeviceDurationElephantColumns,
		PrimaryKey: []*schema.Column{ThingDeviceDurationElephantColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "devicedurationelephant_iot_id_date",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceDurationElephantColumns[5], ThingDeviceDurationElephantColumns[8]},
			},
		},
	}
	// ThingDeviceEventsColumns holds the columns for the "thing_device_events" table.
	ThingDeviceEventsColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "event_type", Type: field.TypeString, Nullable: true, Comment: "EventType | 事件类型,INFO_EVENT_TYPE:信息。ALERT_EVENT_TYPE:告警。ERROR_EVENT_TYPE:故障。", Default: "INFO_EVENT_TYPE"},
		{Name: "identifier", Type: field.TypeString, Comment: "Identifier | 事件的标识符"},
		{Name: "name", Type: field.TypeString, Comment: "Name | 事件名称"},
		{Name: "output_data", Type: field.TypeString, Nullable: true, Size: 2147483647, Comment: "Output data | 事件的输出参数"},
		{Name: "time", Type: field.TypeString, Comment: "Time | 事件发生时间。毫秒级时间戳。"},
	}
	// ThingDeviceEventsTable holds the schema information for the "thing_device_events" table.
	ThingDeviceEventsTable = &schema.Table{
		Name:       "thing_device_events",
		Columns:    ThingDeviceEventsColumns,
		PrimaryKey: []*schema.Column{ThingDeviceEventsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceevent_iot_id_identifier_time",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceEventsColumns[5], ThingDeviceEventsColumns[7], ThingDeviceEventsColumns[10]},
			},
		},
	}
	// ThingDeviceKpiColumns holds the columns for the "thing_device_kpi" table.
	ThingDeviceKpiColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "kpi", Type: field.TypeFloat64, Nullable: true, Comment: "KPI"},
		{Name: "x", Type: field.TypeFloat64, Nullable: true, Comment: "X"},
		{Name: "y", Type: field.TypeFloat64, Nullable: true, Comment: "Y"},
		{Name: "a", Type: field.TypeFloat64, Nullable: true, Comment: "A"},
		{Name: "b", Type: field.TypeFloat64, Nullable: true, Comment: "B"},
		{Name: "week_kpi", Type: field.TypeFloat64, Nullable: true, Comment: "WeekKpi"},
		{Name: "month_kpi", Type: field.TypeFloat64, Nullable: true, Comment: "MonthKpi"},
		{Name: "current_day1", Type: field.TypeInt64, Nullable: true, Comment: "CurrentDay1"},
		{Name: "current_day7", Type: field.TypeInt64, Nullable: true, Comment: "currentDay7"},
		{Name: "current_day28", Type: field.TypeInt64, Nullable: true, Comment: "currentDay28"},
	}
	// ThingDeviceKpiTable holds the schema information for the "thing_device_kpi" table.
	ThingDeviceKpiTable = &schema.Table{
		Name:       "thing_device_kpi",
		Columns:    ThingDeviceKpiColumns,
		PrimaryKey: []*schema.Column{ThingDeviceKpiColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "devicekpi_iot_id",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceKpiColumns[5]},
			},
		},
	}
	// ThingDeviceOfflineTimesColumns holds the columns for the "thing_device_offline_times" table.
	ThingDeviceOfflineTimesColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "time", Type: field.TypeString, Nullable: true, Comment: "Time | 离线时间"},
	}
	// ThingDeviceOfflineTimesTable holds the schema information for the "thing_device_offline_times" table.
	ThingDeviceOfflineTimesTable = &schema.Table{
		Name:       "thing_device_offline_times",
		Columns:    ThingDeviceOfflineTimesColumns,
		PrimaryKey: []*schema.Column{ThingDeviceOfflineTimesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceofflinetime_iot_id_time",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceOfflineTimesColumns[5], ThingDeviceOfflineTimesColumns[8]},
			},
		},
	}
	// ThingDeviceOnTimeDailyColumns holds the columns for the "thing_device_on_time_daily" table.
	ThingDeviceOnTimeDailyColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "time", Type: field.TypeString, Nullable: true, Comment: "Time | 记录时间"},
		{Name: "value", Type: field.TypeString, Nullable: true, Comment: "Value | 统计总时间"},
	}
	// ThingDeviceOnTimeDailyTable holds the schema information for the "thing_device_on_time_daily" table.
	ThingDeviceOnTimeDailyTable = &schema.Table{
		Name:       "thing_device_on_time_daily",
		Columns:    ThingDeviceOnTimeDailyColumns,
		PrimaryKey: []*schema.Column{ThingDeviceOnTimeDailyColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceontimedaily_iot_id_time",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceOnTimeDailyColumns[5], ThingDeviceOnTimeDailyColumns[8]},
			},
		},
	}
	// ThingDeviceOnlineTimesColumns holds the columns for the "thing_device_online_times" table.
	ThingDeviceOnlineTimesColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "gmt_online", Type: field.TypeString, Nullable: true, Comment: "GMT Online | GMT最近一次上线的时间"},
	}
	// ThingDeviceOnlineTimesTable holds the schema information for the "thing_device_online_times" table.
	ThingDeviceOnlineTimesTable = &schema.Table{
		Name:       "thing_device_online_times",
		Columns:    ThingDeviceOnlineTimesColumns,
		PrimaryKey: []*schema.Column{ThingDeviceOnlineTimesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceonlinetime_iot_id_gmt_online",
				Unique:  true,
				Columns: []*schema.Column{ThingDeviceOnlineTimesColumns[5], ThingDeviceOnlineTimesColumns[8]},
			},
		},
	}
	// ThingUpsterCycleColumns holds the columns for the "thing_upster_cycle" table.
	ThingUpsterCycleColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "timestamp", Type: field.TypeString, Nullable: true, Comment: "Timestamp | 毫秒时间戳"},
		{Name: "number1", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramButton1 | 程序1"},
		{Name: "number2", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramButton2 | 程序2"},
		{Name: "number3", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramButton3 | 程序3"},
		{Name: "number_cycles", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramCycles | 程序总计数"},
		{Name: "number_regeneration", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfRegeneration"},
		{Name: "number_rinsing_cycles", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfRinsingCycles"},
		{Name: "total_operation_time", Type: field.TypeInt32, Nullable: true, Comment: "TotalOfOperatingTime"},
	}
	// ThingUpsterCycleTable holds the schema information for the "thing_upster_cycle" table.
	ThingUpsterCycleTable = &schema.Table{
		Name:       "thing_upster_cycle",
		Columns:    ThingUpsterCycleColumns,
		PrimaryKey: []*schema.Column{ThingUpsterCycleColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceupstercycle_iot_id_number1_number2_number3",
				Unique:  true,
				Columns: []*schema.Column{ThingUpsterCycleColumns[5], ThingUpsterCycleColumns[9], ThingUpsterCycleColumns[10], ThingUpsterCycleColumns[11]},
			},
		},
	}
	// ThingUpsterStatisticsColumns holds the columns for the "thing_upster_statistics" table.
	ThingUpsterStatisticsColumns = []*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: "iot_id", Type: field.TypeString, Comment: "Iot Id | 设备ID"},
		{Name: "device_name", Type: field.TypeString, Comment: "Device Name | 设备名称"},
		{Name: "product_key", Type: field.TypeString, Comment: "Product Key | 产品Key"},
		{Name: "date", Type: field.TypeString, Nullable: true, Comment: "Date | 日期"},
		{Name: "timestamp", Type: field.TypeString, Nullable: true, Comment: "Timestamp | 毫秒时间戳"},
		{Name: "number1", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramButton1 | 程序1"},
		{Name: "number2", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramButton2 | 程序2"},
		{Name: "number3", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramButton3 | 程序3"},
		{Name: "number_cycles", Type: field.TypeInt32, Nullable: true, Comment: "NumberOfProgramCycles | 程序总计数"},
		{Name: "hours", Type: field.TypeString, Nullable: true, Size: 2147483647, Comment: "Hours | 每小时计数"},
		{Name: "initialize", Type: field.TypeBool, Nullable: true, Comment: "Initialize | 初始化", Default: false},
	}
	// ThingUpsterStatisticsTable holds the schema information for the "thing_upster_statistics" table.
	ThingUpsterStatisticsTable = &schema.Table{
		Name:       "thing_upster_statistics",
		Columns:    ThingUpsterStatisticsColumns,
		PrimaryKey: []*schema.Column{ThingUpsterStatisticsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "deviceupsterstatistics_iot_id_date_timestamp",
				Unique:  true,
				Columns: []*schema.Column{ThingUpsterStatisticsColumns[5], ThingUpsterStatisticsColumns[8], ThingUpsterStatisticsColumns[9]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ThingDeviceDurationTable,
		ThingDeviceDurationElephantTable,
		ThingDeviceEventsTable,
		ThingDeviceKpiTable,
		ThingDeviceOfflineTimesTable,
		ThingDeviceOnTimeDailyTable,
		ThingDeviceOnlineTimesTable,
		ThingUpsterCycleTable,
		ThingUpsterStatisticsTable,
	}
)

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