Documentation
¶
Index ¶
- Constants
- func Begin() *gorm.DB
- func ClearSandbox()
- func DB() *gorm.DB
- func Exec(sql string, values ...interface{}) (tx *gorm.DB)
- func Find(dest interface{}, cond ...interface{}) (tx *gorm.DB)
- func First(dest interface{}, cond ...interface{}) (tx *gorm.DB)
- func Raw(sql string, values ...interface{}) (tx *gorm.DB)
- func SandBox() *gorm.DB
- func SchemaMigrationHistoryExists() bool
- func ShowCreateTables(tableNames ...string) (creates []string, err error)
- type Equal
- type HistoryModel
- type Migrator
- type Module
- type Parameters
- type Schema
- type Script
- type Scripts
- func (s *Scripts) AlterPermissionLint() error
- func (s *Scripts) Get(serviceName string) ([]*Script, bool)
- func (s *Scripts) HasDestructiveOperationInPending() bool
- func (s *Scripts) InstalledChangesLint() error
- func (s *Scripts) Lint() error
- func (s *Scripts) MarkPending(tx *gorm.DB)
- func (s *Scripts) SameNameLint() error
- type TableDefinition
Constants ¶
const SchemaMigrationHistory = `schema_migration_history`
Variables ¶
This section is empty.
Functions ¶
func ClearSandbox ¶
func ClearSandbox()
ClearSandbox if you want to do a new migration in a clean sandbox, you should ClearSandbox to clear all changes on last migration
func SchemaMigrationHistoryExists ¶
func SchemaMigrationHistoryExists() bool
SchemaMigrationHistoryExists returns whether schema_migration_history exists
func ShowCreateTables ¶
ShowCreateTables select table's DDL if tableNames is nil returns all tables DDL
Types ¶
type HistoryModel ¶
type HistoryModel struct { ID uint64 `gorm:"primarykey"` CreatedAt time.Time `json:"createdAt" gorm:"created_at;type:datetime;not null;default CURRENT_TIMESTAMP"` UpdatedAt time.Time `json:"updatedAt" gorm:"updated_at;type:datetime;not null;default CURRENT_TIMESTAMP; on update CURRENT_TIMESTAMP"` ServiceName string `json:"serviceName" gorm:"service_name;type:varchar(32);not null;comment:微服务名"` Filename string `json:"filename" gorm:"filename;type:varchar(191);not null;comment:脚本类型"` Checksum string `json:"checksum" gorm:"checksum;type:char(128);not null;comment:rawtext 的 md5 值"` InstalledBy string `json:"installedBy" gorm:"installed_by;type:varchar(32);not null;comment:执行人"` InstalledOn string `json:"installedOn" gorm:"install_on;type:varchar(32);not null;comment:执行平台"` LanguageType string `json:"languageType" gorm:"language_type;type:varchar(16);not null;comment:SQL, Go, Java"` Reversed string `json:"reversed" gorm:"reversed;type:longtext;not null;comment:反转的 DDL"` }
func (HistoryModel) TableName ¶
func (m HistoryModel) TableName() string
type Migrator ¶
type Migrator struct { Parameters LocalScripts *Scripts // contains filtered or unexported fields }
func New ¶
func New(parameters Parameters) (*Migrator, error)
type Module ¶
type Module []*Script
Module is the list of Script
func (Module) BaselineEqualCloud ¶
BaselineEqualCloud check baseline script schema is equal with cloud schema or not
func (Module) BaselineSchema ¶
func (Module) BaselineTableNames ¶
func (Module) TableNames ¶
type Parameters ¶
type Parameters interface { // DSN gets MySQL DSN DSN() string // SandboxDSN gets sandbox DSN SandboxDSN() string // database name Database() string // MigrationDir gets migration scripts direction from repo, like .dice/migrations or 4.1/sqls MigrationDir() string // Modules is the modules for installing. // if is nil, to install all modules in the MigrationDir() Modules() []string // Workdir gets pipeline node workdir Workdir() string // DebugSQL gets weather to debug SQL executing DebugSQL() bool NeedErdaMySQLLint() bool Rules() []rules.Ruler }
type Schema ¶
type Schema struct {
TableDefinitions map[string]*TableDefinition
}
Schema is the set of TableDefinitions. Is presents the status of the set of some tables.
type Script ¶
type Script struct { // path from repo root, filepath.Base(script.Name) for base filename Name string Rawtext []byte Reversing []string Nodes []ast.StmtNode Pending bool Record *HistoryModel Workdir string // contains filtered or unexported fields }
Script is the object from a SQL script file, it contains many statements.
func NewScript ¶
NewScript read the local file, parse data as SQL AST nodes, and mark script IsBase or not
func (*Script) IsBaseline ¶
type Scripts ¶
type Scripts struct { Workdir string Dirname string ServicesNames []string Services map[string]Module // contains filtered or unexported fields }
Scripts is the set of Module
func NewScripts ¶
func NewScripts(parameters Parameters) (*Scripts, error)
NewScripts range the directory
func (*Scripts) AlterPermissionLint ¶
func (*Scripts) HasDestructiveOperationInPending ¶
func (*Scripts) InstalledChangesLint ¶
func (*Scripts) MarkPending ¶
func (*Scripts) SameNameLint ¶
SameNameLint lint whether there is same script name in different directories
type TableDefinition ¶
type TableDefinition struct {
CreateStmt *ast.CreateTableStmt
}
TableDefinition is the table definition (CreateTableStmt) object. It can be accepted by SQL AST Node and then to update it's status.
func NewTableDefinition ¶
func NewTableDefinition(stmt *ast.CreateTableStmt) *TableDefinition
func (*TableDefinition) Equal ¶
func (d *TableDefinition) Equal(o *TableDefinition) *Equal