Documentation
¶
Index ¶
- Constants
- Variables
- func FormatType(t schema.Type) (string, error)
- func MarshalSpec(v any, marshaler schemahcl.Marshaler) ([]byte, error)
- func Open(db schema.ExecQuerier) (migrate.Driver, error)
- func Parse(raw string) (schema.Type, error)
- func ParseType(raw string, size, numericPrecision, numericScale int) (schema.Type, error)
- type AutoIncrement
- type BitType
- type CreateOptions
- type CreateStmt
- type DisplayWidth
- type Driver
- func (d *Driver) CheckClean(ctx context.Context, revT *migrate.TableIdent) error
- func (*Driver) FormatType(t schema.Type) (string, error)
- func (d *Driver) Lock(ctx context.Context, name string, timeout time.Duration) (schema.UnlockFunc, error)
- func (d *Driver) NormalizeRealm(ctx context.Context, r *schema.Realm) (*schema.Realm, error)
- func (d *Driver) NormalizeSchema(ctx context.Context, s *schema.Schema) (*schema.Schema, error)
- func (*Driver) ParseType(s string) (schema.Type, error)
- func (d *Driver) RealmRestoreFunc(desired *schema.Realm) migrate.RestoreFunc
- func (*Driver) ScanStmts(input string) ([]*migrate.Stmt, error)
- func (d *Driver) SchemaRestoreFunc(desired *schema.Schema) migrate.RestoreFunc
- func (d *Driver) Snapshot(ctx context.Context) (migrate.RestoreFunc, error)
- func (*Driver) StmtBuilder(opts migrate.PlanOptions) *sqlx.Builder
- func (d *Driver) Version() string
- type Enforced
- type Engine
- type IndexParser
- type IndexType
- type OnUpdate
- type SetType
- type SubPart
- type ZeroFill
Constants ¶
const ( // 常规数据类型 TypeChar = "CHAR" // 定长字符串,最大长度由数据库页面大小决定。 TypeCharacter = "CHARACTER" // 定长字符串,最大长度由数据库页面大小决定。 TypeVarchar = "VARCHAR" // 可变长字符串,最大长度由数据库页面大小决定。 TypeNumeric = "NUMERIC" // 用于存储零、正负定点数。精度范围1至38 TypeNumber = "NUMBER" // 跟NUMERIC相同 TypeDecimal = "DECIMAL" // 跟NUMERIC相似 TypeDec = "DEC" // 跟NUMERIC相似 TypeInteger = "INTEGER" // 用于存储有符号整数,精度为10 TypeInt = "INT" // 用于存储有符号整数,精度为10 TypeBigint = "BIGINT" // 用于存储有符号整数,精度为19,标度为0 TypeTinyint = "TINYINT" // 用于存储有符号整数,精度为3,标度为0。取值范围为:-128~+127 TypeByte = "BYTE" // 与TINYINT相似,精度为3,标度为0 TypeSmallint = "SMALLINT" // 用于存储有符号整数,精度为5,标度为0 TypeBinary = "BINARY" // 指定定长二进制数据 TypeVarbinary = "VARBINARY" // 指定变长二进制数据。用法类似BINARY数据类型 TypeReal = "REAL" // 带二进制的浮点数 TypeFloat = "FLOAT" // 二进制精度的浮点数,精度最大不超过53 TypeDouble = "DOUBLE" // 同FLOAT相似,精度最大不超过53 TypeDoublePrecision = "DOUBLE PRECISION" // 该类型指明双精度浮点数,其二进制精度为53,十进制精度为15 //位串数据类型 TypeBit = "BIT" // 用于存储整数数据1、0或null //日期时间数据类型 TypeDate = "DATE" // 包括年、月、日信息,定义了‘-4712-01-01’和‘9999-12-31’之间任何一个有效的格里高利日期 TypeTime = "TIME" // 包括时、分、秒信息 TypeTimestamp = "TIMESTAMP" // 包括年、月、日、时、分、秒信息 TypeDatetime = "DATETIME" // 包括年、月、日、时、分、秒信息 TypeTimeWithTimeZone = "TIME WITH TIME ZONE" // 描述一个带时区的TIME值 TypeTimestampWithTimeZone = "TIMESTAMP WITH TIME ZONE" // 描述一个带时区的TIMESTAMP值 TypeTimestampWithLocalTimeZone = "TIMESTAMP WITH LOCAL TIME ZONE" // 描述一个本地时区的TIMESTAMP值 //多媒体数据类型 TypeText = "TEXT" // 变长字符串类型,其字符串的长度最大为2G-1,可用于存储长的文本串 TypeLongvarchar = "LONGVARCHAR" // 变长字符串类型,其字符串的长度最大为2G-1,可用于存储长的文本串 TypeImage = "IMAGE" // 可用于存储多媒体信息中的图像类型 TypeLongvarbinary = "LONGVARBINARY" // 可用于存储多媒体信息中的图像类型 TypeBlob = "BLOB" // 用于指明变长的字符串,长度最大为2G-1字节 TypeClob = "CLOB" // 用于指明变长的字符串,长度最大为2G-1字节 TypeBfile = "BFILE" // 用于指明存储在操作系统中的二进制文件 )
const ( IndexTypeBTree = "BTREE" IndexTypeHash = "HASH" IndexTypeFullText = "FULLTEXT" IndexTypeSpatial = "SPATIAL" IndexParserNGram = "ngram" IndexParserMeCab = "mecab" EngineInnoDB = "InnoDB" EngineMyISAM = "MyISAM" EngineMemory = "Memory" EngineCSV = "CSV" EngineNDB = "NDB" // NDBCLUSTER )
Additional common constants in MySQL.
const DriverName = "dm"
DriverName holds the name used for registration.
Variables ¶
var ( // MarshalHCL marshals v into an Atlas HCL DDL document. MarshalHCL = schemahcl.MarshalerFunc(func(v any) ([]byte, error) { return MarshalSpec(v, hclState) }) // EvalHCL implements the schemahcl.Evaluator interface. EvalHCL = schemahcl.EvalFunc(evalSpec) // EvalHCLBytes is a helper that evaluates an HCL document from a byte slice instead // of from an hclparse.Parser instance. EvalHCLBytes = specutil.HCLBytesFunc(EvalHCL) )
var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{conn: noConn}}
DefaultDiff provides basic diffing capabilities for MySQL dialects. Note, it is recommended to call Open, create a new Driver and use its Differ when a database connection is available.
var ( // DefaultPlan provides basic planning capabilities for MySQL dialects. // Note, it is recommended to call Open, create a new Driver and use its // migrate.PlanApplier when a database connection is available. DefaultPlan migrate.PlanApplier = &planApply{conn: noConn} )
var TypeRegistry = schemahcl.NewRegistry( schemahcl.WithFormatter(FormatType), schemahcl.WithParser(Parse), schemahcl.WithSpecs( schemahcl.NewTypeSpec(TypeBit, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeInt, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeDecimal, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())), schemahcl.NewTypeSpec(TypeNumeric, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())), schemahcl.NewTypeSpec(TypeFloat, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())), schemahcl.NewTypeSpec(TypeDouble, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())), schemahcl.NewTypeSpec(TypeReal, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())), schemahcl.NewTypeSpec(TypeTimestamp, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr())), schemahcl.NewTypeSpec(TypeDate), schemahcl.NewTypeSpec(TypeTime, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr())), schemahcl.NewTypeSpec(TypeDatetime, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr())), schemahcl.NewTypeSpec(TypeVarchar, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(true))), schemahcl.NewTypeSpec(TypeChar, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeBinary, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeBlob, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeText, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeBigint), schemahcl.NewTypeSpec(TypeLongvarchar, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), schemahcl.NewTypeSpec(TypeLongvarbinary, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))), ), )
TypeRegistry contains the supported TypeSpecs for the mysql driver.
Functions ¶
func FormatType ¶
FormatType converts schema type to its column form in the database. An error is returned if the type cannot be recognized.
func MarshalSpec ¶
MarshalSpec marshals v into an Atlas DDL document using a schemahcl.Marshaler.
Types ¶
type AutoIncrement ¶
AutoIncrement attribute for columns with "AUTO_INCREMENT" as a default. V represent an optional start value for the counter.
type CreateOptions ¶
CreateOptions attribute for describing extra options used with CREATE TABLE.
type CreateStmt ¶
CreateStmt describes the SQL statement used to create a table.
type DisplayWidth ¶
The DisplayWidth represents a display width of an integer type.
type Driver ¶
type Driver struct { schema.Differ schema.Inspector migrate.PlanApplier // contains filtered or unexported fields }
Driver represents a MySQL driver for introspecting database schemas, generating diff between schema elements and apply migrations changes.
func (*Driver) CheckClean ¶
CheckClean implements migrate.CleanChecker.
func (*Driver) FormatType ¶
FormatType converts schema type to its column form in the database.
func (*Driver) Lock ¶
func (d *Driver) Lock(ctx context.Context, name string, timeout time.Duration) (schema.UnlockFunc, error)
Lock implements the schema.Locker interface.
func (*Driver) NormalizeRealm ¶
NormalizeRealm returns the normal representation of the given database.
func (*Driver) NormalizeSchema ¶
NormalizeSchema returns the normal representation of the given database.
func (*Driver) RealmRestoreFunc ¶
func (d *Driver) RealmRestoreFunc(desired *schema.Realm) migrate.RestoreFunc
RealmRestoreFunc returns a function that restores the given realm to its desired state.
func (*Driver) SchemaRestoreFunc ¶
func (d *Driver) SchemaRestoreFunc(desired *schema.Schema) migrate.RestoreFunc
SchemaRestoreFunc returns a function that restores the given schema to its desired state.
func (*Driver) StmtBuilder ¶
func (*Driver) StmtBuilder(opts migrate.PlanOptions) *sqlx.Builder
StmtBuilder is a helper method used to build statements with MySQL formatting.
type Engine ¶
type Engine struct { schema.Attr V string // InnoDB, MyISAM, etc. Default bool // The default engine used by the server. }
Engine attribute describes the storage engine used to create a table.
type IndexParser ¶
type IndexParser struct { schema.Attr P string // Name of the parser plugin. e.g., ngram or mecab. }
IndexParser defines the parser plugin used by a FULLTEXT index.