Documentation ¶
Index ¶
- Constants
- func Exec(mydb *sql.DB, query string) (sql.Result, error)
- func NewMyTimer() *myTimer
- func ParseJSON(content string, val interface{}) error
- type AlterIgnoreTable
- type AlterType
- type Comparer
- type Config
- func (cfg *Config) CheckMatchTables(name string) bool
- func (cfg *Config) IsIgnoreField(table string, name string) bool
- func (cfg *Config) IsIgnoreForeignKey(table string, name string) bool
- func (cfg *Config) IsIgnoreIndex(table string, name string) bool
- func (cfg *Config) IsSkipTables(name string) bool
- func (cfg *Config) SQLPreprocessor() func(string) string
- func (cfg *Config) SendMailFail(errStr string)
- func (cfg *Config) SetComparer(comparer Comparer)
- func (cfg *Config) SetSQLPreprocessor(fn func(string) string)
- func (cfg *Config) String() string
- type DBOperator
- type DbIndex
- type EmailStruct
- type IndexType
- type MyCompare
- type MyDb
- type MySchema
- type SchemaDiff
- type SchemaSync
- type SendEmail
- type Statics
- func (s *Statics) ChangeTableNum() int
- func (s *Statics) ChangeTables() []string
- func (s *Statics) Diff(on bool) *Statics
- func (s *Statics) Elapsed() time.Duration
- func (s *Statics) EndTime() time.Time
- func (s *Statics) FailedNum() int
- func (s *Statics) StartTime() time.Time
- func (s *Statics) String() string
- type TableAlterData
Constants ¶
View Source
const ( AlterTypeNo AlterType = 0 AlterTypeCreate = 1 AlterTypeDrop = 2 AlterTypeAlter = 3 )
View Source
const ( IndexTypePrimary IndexType = "PRIMARY" IndexTypeIndex = "INDEX" IndexTypeForeignKey = "FOREIGN KEY" )
View Source
const AppURL = "https://github.com/admpub/mysql-schema-sync/"
AppURL site
View Source
const Version = "0.4"
Version version
Variables ¶
This section is empty.
Functions ¶
func NewMyTimer ¶ added in v0.0.5
func NewMyTimer() *myTimer
Types ¶
type AlterIgnoreTable ¶
type AlterIgnoreTable struct { Column []string `json:"column"` Index []string `json:"index"` ForeignKey []string `json:"foreign"` //外键 }
AlterIgnoreTable table's ignore info
type Comparer ¶ added in v0.0.5
type Comparer interface {
AlterData(sc *SchemaSync, tableName string) *TableAlterData
}
type Config ¶
type Config struct { SourceDSN string `json:"source"` DestDSN string `json:"dest"` AlterIgnore map[string]*AlterIgnoreTable `json:"alter_ignore"` Tables []string `json:"tables"` SkipTables []string `json:"skip_tables"` Email *EmailStruct `json:"email"` ConfigPath string Sync bool Drop bool // contains filtered or unexported fields }
Config config struct
func (*Config) CheckMatchTables ¶
CheckMatchTables check table is match
func (*Config) IsIgnoreField ¶
IsIgnoreField isIgnore
func (*Config) IsIgnoreForeignKey ¶
IsIgnoreForeignKey 检查外键是否忽略掉
func (*Config) IsIgnoreIndex ¶
IsIgnoreIndex is index ignore
func (*Config) IsSkipTables ¶
IsSkipTables check table is skip
func (*Config) SQLPreprocessor ¶ added in v0.0.3
func (*Config) SendMailFail ¶
SendMailFail send fail mail
func (*Config) SetComparer ¶ added in v0.0.5
func (*Config) SetSQLPreprocessor ¶ added in v0.0.3
type DBOperator ¶
type DbIndex ¶
DbIndex db index
func (*DbIndex) AddRelationTable ¶ added in v0.0.5
func (*DbIndex) AlterAddSQL ¶ added in v0.0.5
func (*DbIndex) AlterDropSQL ¶ added in v0.0.5
type EmailStruct ¶
type EmailStruct struct { SendMailAble bool `json:"send_mail"` SMTPHost string `json:"smtp_host"` From string `json:"from"` Password string `json:"password"` To string `json:"to"` }
EmailStruct email conf info
func (*EmailStruct) SendMail ¶
func (m *EmailStruct) SendMail(title string, body string)
SendMail send mail
type MyCompare ¶ added in v0.0.5
type MyCompare struct { }
func NewMyCompare ¶ added in v0.0.5
func NewMyCompare() *MyCompare
func (*MyCompare) AlterData ¶ added in v0.0.5
func (my *MyCompare) AlterData(sc *SchemaSync, table string) *TableAlterData
type MyDb ¶
MyDb db struct
func (*MyDb) GetTableSchema ¶
GetTableSchema table schema
type MySchema ¶
type MySchema struct { SchemaRaw string Fields map[string]string IndexAll map[string]*DbIndex ForeignAll map[string]*DbIndex }
MySchema table schema
func (*MySchema) GetFieldNames ¶
GetFieldNames table names
func (*MySchema) RelationTables ¶
type SchemaDiff ¶
func NewSchemaDiff ¶ added in v0.0.5
func NewSchemaDiff(table string, source *MySchema, dest *MySchema) *SchemaDiff
func (*SchemaDiff) RelationTables ¶
func (sdiff *SchemaDiff) RelationTables() []string
type SchemaSync ¶
type SchemaSync struct { Config *Config SourceDb DBOperator DestDb DBOperator Comparer Comparer }
SchemaSync 配置文件
func NewSchemaSync ¶
func NewSchemaSync(config *Config, dbOperators ...DBOperator) *SchemaSync
NewSchemaSync 对一个配置进行同步 dbOperators: 0: source; 1: destination
func (*SchemaSync) Close ¶
func (sc *SchemaSync) Close() error
func (*SchemaSync) GetNewTableNames ¶
func (sc *SchemaSync) GetNewTableNames() []string
GetNewTableNames 获取所有新增加的表名
func (*SchemaSync) SetComparer ¶ added in v0.0.5
func (sc *SchemaSync) SetComparer(comparer Comparer) *SchemaSync
func (*SchemaSync) SyncSQL4Dest ¶
func (sc *SchemaSync) SyncSQL4Dest(sqlStr string) error
SyncSQL4Dest sync schema change
type Statics ¶
type Statics struct { Config *Config // contains filtered or unexported fields }
func CheckSchemaDiff ¶
func CheckSchemaDiff(cfg *Config, dbOperators ...DBOperator) *Statics
CheckSchemaDiff 执行最终的diff
func (*Statics) ChangeTableNum ¶
func (*Statics) ChangeTables ¶
type TableAlterData ¶
type TableAlterData struct { Table string Type AlterType SQL string SchemaDiff *SchemaDiff }
TableAlterData 表的变更情况
func NewAlterData ¶ added in v0.0.5
func NewAlterData(tableName string) *TableAlterData
func (*TableAlterData) String ¶
func (ta *TableAlterData) String() string
Click to show internal directories.
Click to hide internal directories.