internal

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const AppURL = "https://github.com/hidu/mysql-schema-sync/"

AppURL site

View Source
const Version = "0.3"

Version version

Variables

This section is empty.

Functions

func ParseJSON

func ParseJSON(content string, val interface{}) error

ParseJSON parse json

Types

type AlterIgnoreTable

type AlterIgnoreTable struct {
	Column     []string `json:"column"`
	Index      []string `json:"index"`
	ForeignKey []string `json:"foreign"` //外键
}

AlterIgnoreTable table's ignore info

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 LoadConfig

func LoadConfig(confPath string) *Config

LoadConfig load config file

func (*Config) CheckMatchTables

func (cfg *Config) CheckMatchTables(name string) bool

CheckMatchTables check table is match

func (*Config) IsIgnoreField

func (cfg *Config) IsIgnoreField(table string, name string) bool

IsIgnoreField isIgnore

func (*Config) IsIgnoreForeignKey

func (cfg *Config) IsIgnoreForeignKey(table string, name string) bool

IsIgnoreForeignKey 检查外键是否忽略掉

func (*Config) IsIgnoreIndex

func (cfg *Config) IsIgnoreIndex(table string, name string) bool

IsIgnoreIndex is index ignore

func (*Config) IsSkipTables

func (cfg *Config) IsSkipTables(name string) bool

IsSkipTables check table is skip

func (*Config) SQLPreprocessor added in v0.0.3

func (cfg *Config) SQLPreprocessor() func(string) string

func (*Config) SendMailFail

func (cfg *Config) SendMailFail(errStr string)

SendMailFail send fail mail

func (*Config) SetSQLPreprocessor added in v0.0.3

func (cfg *Config) SetSQLPreprocessor(fn func(string) string)

func (*Config) String

func (cfg *Config) String() string

type DBOperator

type DBOperator interface {
	GetTableNames() []string
	GetTableSchema(name string) (schema string)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	Begin() (*sql.Tx, error)
	Close() error
}

type DbIndex

type DbIndex struct {
	IndexType      indexType
	Name           string
	SQL            string
	RelationTables []string //相关联的表
}

DbIndex db index

func (*DbIndex) String

func (idx *DbIndex) String() string

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 MyDb

type MyDb struct {
	*sql.DB
	// contains filtered or unexported fields
}

MyDb db struct

func NewMyDb

func NewMyDb(dsn string, dbType string) *MyDb

NewMyDb parse dsn

func (*MyDb) GetTableNames

func (mydb *MyDb) GetTableNames() []string

GetTableNames table names

func (*MyDb) GetTableSchema

func (mydb *MyDb) GetTableSchema(name string) (schema string)

GetTableSchema table schema

func (*MyDb) Query

func (mydb *MyDb) Query(query string, args ...interface{}) (*sql.Rows, error)

Query execute sql query

type MySchema

type MySchema struct {
	SchemaRaw  string
	Fields     map[string]string
	IndexAll   map[string]*DbIndex
	ForeignAll map[string]*DbIndex
}

MySchema table schema

func ParseSchema

func ParseSchema(schema string) *MySchema

ParseSchema parse table's schema

func (*MySchema) GetFieldNames

func (mys *MySchema) GetFieldNames() []string

GetFieldNames table names

func (*MySchema) RelationTables

func (mys *MySchema) RelationTables() []string

func (*MySchema) String

func (mys *MySchema) String() string

type SchemaDiff

type SchemaDiff struct {
	Table  string
	Source *MySchema
	Dest   *MySchema
}

func (*SchemaDiff) RelationTables

func (sdiff *SchemaDiff) RelationTables() []string

type SchemaSync

type SchemaSync struct {
	Config   *Config
	SourceDb DBOperator
	DestDb   DBOperator
}

SchemaSync 配置文件

func NewSchemaSync

func NewSchemaSync(config *Config, dbOperators ...DBOperator) *SchemaSync

NewSchemaSync 对一个配置进行同步

func (*SchemaSync) Close

func (sc *SchemaSync) Close() error

func (*SchemaSync) GetNewTableNames

func (sc *SchemaSync) GetNewTableNames() []string

GetNewTableNames 获取所有新增加的表名

func (*SchemaSync) SyncSQL4Dest

func (sc *SchemaSync) SyncSQL4Dest(sqlStr string, sqls []string) error

SyncSQL4Dest sync schema change

type SendEmail

type SendEmail interface {
	SendEmail(string, string)
}

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 (s *Statics) ChangeTableNum() int

func (*Statics) ChangeTables

func (s *Statics) ChangeTables() []string

func (*Statics) Diff

func (s *Statics) Diff(on bool) *Statics

func (*Statics) Elapsed

func (s *Statics) Elapsed() time.Duration

func (*Statics) EndTime

func (s *Statics) EndTime() time.Time

func (*Statics) FailedNum

func (s *Statics) FailedNum() int

func (*Statics) StartTime

func (s *Statics) StartTime() time.Time

func (*Statics) String

func (s *Statics) String() string

type TableAlterData

type TableAlterData struct {
	Table      string
	Type       alterType
	SQL        string
	SchemaDiff *SchemaDiff
}

TableAlterData 表的变更情况

func (*TableAlterData) String

func (ta *TableAlterData) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL