Documentation ¶
Index ¶
- Constants
- func RetryTimeout(timeout uint64) time.Duration
- func SQLCollectorFilename() string
- func SortedScripts(services map[string]*Module) []moduleScript
- type Block
- type DSNParameters
- type Equal
- type HistoryModel
- type Migrator
- type Module
- func (m *Module) BaselineEqualCloud(tx *gorm.DB) *Equal
- func (m *Module) BaselineSchema() *Schema
- func (m *Module) BaselineTableNames() []string
- func (m *Module) Filenames() []string
- func (m *Module) FilterFreshBaseline(db *gorm.DB) *Module
- func (m *Module) GetScriptByFilename(filename string) (*Script, bool)
- func (m *Module) Schema() *Schema
- func (m *Module) Sort()
- func (m *Module) TableNames() []string
- type Parameters
- type SQLCollectorDir
- type Schema
- type Script
- type ScriptType
- type Scripts
- func (s *Scripts) AlterPermissionLint() error
- func (s *Scripts) FreshBaselineModules(db *gorm.DB) map[string]*Module
- func (s *Scripts) Get(serviceName string) ([]*Script, bool)
- func (s *Scripts) GetPatches() *Module
- func (s *Scripts) GetScriptByFilename(filename string) (*Module, *Script, bool)
- func (s *Scripts) IgnoreMarkPending()
- func (s *Scripts) InstalledChangesLint(ctx *context.Context, db *gorm.DB) error
- func (s *Scripts) Lint() error
- func (s *Scripts) MarkPending(tx *gorm.DB)
- func (s *Scripts) SameNameLint() error
- type ScriptsParameters
- type StmtType
- type TableDefinition
Constants ¶
const ( DDL = "DDL" DML = "DML" )
const CreateTableHistoryModel = `` /* 834-byte string literal not displayed */
const SchemaMigrationHistory = `schema_migration_history`
Variables ¶
This section is empty.
Functions ¶
func RetryTimeout ¶ added in v1.3.0
func SQLCollectorFilename ¶ added in v1.3.0
func SQLCollectorFilename() string
func SortedScripts ¶
SortedScripts 对所有脚本进行总排序
Types ¶
type Block ¶ added in v1.3.0
type Block struct {
// contains filtered or unexported fields
}
func AppendBlock ¶ added in v1.3.0
type DSNParameters ¶
type DSNParameters struct { Username string Password string Host string Port int Database string ParseTime bool Timeout time.Duration }
func (DSNParameters) Format ¶
func (c DSNParameters) Format(database bool) (dsn string)
type HistoryModel ¶
type HistoryModel struct { ID uint64 `gorm:"primary key"` CreatedAt time.Time `json:"createdAt" gorm:"created_at"` UpdatedAt time.Time `json:"updatedAt" gorm:"updated_at"` ServiceName string `json:"serviceName" gorm:"service_name"` Filename string `json:"filename" gorm:"filename"` Checksum string `json:"checksum" gorm:"checksum"` InstalledBy string `json:"installedBy" gorm:"installed_by"` InstalledOn string `json:"installedOn" gorm:"install_on"` LanguageType string `json:"languageType" gorm:"language_type"` Reversed string `json:"reversed" gorm:"reversed"` }
func (HistoryModel) CreateTable ¶
func (m HistoryModel) CreateTable(db *gorm.DB)
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) (mig *Migrator, err error)
func (*Migrator) ClearSandbox ¶
func (mig *Migrator) ClearSandbox()
ClearSandbox if you want to do a new migration in a clean sandbox, you should ClearSandbox to clear all changes on last migration
type Module ¶
type Module struct { // Name is the name of the module Name string // Scripts contains all sql or python scripts in the module Scripts []*Script // PythonRequirementsText is the text of python requirements file in the module. // it is used to install dependencies of python package by "pip install -r requirements.txt -v" PythonRequirementsText []byte }
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) FilterFreshBaseline ¶ added in v1.3.0
func (*Module) GetScriptByFilename ¶ added in v1.3.0
func (*Module) TableNames ¶
type Parameters ¶
type Parameters interface { ScriptsParameters // MySQLParameters returns MySQL DSN configuration MySQLParameters() *DSNParameters // SandboxParameters returns Sandbox DSN configuration SandboxParameters() *DSNParameters // DebugSQL gets weather to debug SQL executing DebugSQL() bool // RetryTimeout unit: second RetryTimeout() uint64 SkipMigrationLint() bool SkipSandbox() bool SkipPreMigrate() bool SkipMigrate() bool }
type SQLCollectorDir ¶ added in v1.3.0
type SQLCollectorDir interface {
SQLCollectorDir() string
}
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 Blocks []Block Pending bool Record *HistoryModel Workdir string Type ScriptType // 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 NewScriptFromData ¶ added in v1.3.0
func (*Script) IsBaseline ¶
type ScriptType ¶
type ScriptType string
const ( ScriptTypeSQL ScriptType = ".sql" ScriptTypePython ScriptType = ".py" )
type Scripts ¶
type Scripts struct { Workdir string Dirname string ServicesNames []string Services map[string]*Module Patches *Module // contains filtered or unexported fields }
Scripts is the set of Module
func NewScripts ¶
func NewScripts(parameters ScriptsParameters) (*Scripts, error)
NewScripts range the directory
func (*Scripts) AlterPermissionLint ¶
func (*Scripts) FreshBaselineModules ¶ added in v1.3.0
func (*Scripts) GetPatches ¶ added in v1.3.0
func (*Scripts) GetScriptByFilename ¶ added in v1.3.0
func (*Scripts) IgnoreMarkPending ¶
func (s *Scripts) IgnoreMarkPending()
func (*Scripts) InstalledChangesLint ¶
func (*Scripts) MarkPending ¶
func (*Scripts) SameNameLint ¶
SameNameLint lint whether there is same script name in different directories
type ScriptsParameters ¶
type ScriptsParameters interface { // Workdir gets pipeline node workdir Workdir() 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 LintConfig() map[string]sqllint.Config }
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