Documentation
¶
Index ¶
- Constants
- func Debug(content string, options Options)
- func Debugf(content string, options Options, a ...interface{})
- func Error(content string, options Options)
- func Errorf(content string, options Options, a ...interface{})
- func FetchDirFileNames(dirPath string) (dirs []string, e error)
- func FetchFile(filePath string) (changesetFileString string, e error)
- func FetchNonDirFileNames(dirPath string) (files []string, e error)
- func HashFileMd5(filePath string) (string, error)
- func Info(content string, options Options)
- func Infof(content string, options Options, a ...interface{})
- func Log(content string, logLevel LogLevel, options Options)
- func RunCommand(name string, args ...string) (stdout string, stderr string, exitCode int)
- func Warn(content string, options Options)
- func Warnf(content string, options Options, a ...interface{})
- type ChangeFile
- type Changeset
- type Column
- type Command
- type Config
- type Database
- type DatabaseType
- type Files
- func (f *Files) BuildChangeFile(sqlPath string, ordinal int) (changeFile *ChangeFile, e error)
- func (f *Files) BuildChangeFiles(sqlPaths []string) (changeFiles []ChangeFile, e error)
- func (f *Files) FetchLocalChangesetList(rootPath string) (sqlPaths []string, e error)
- func (f *Files) ScanDir(rootPath string, extension string) (paths []string, e error)
- type IConnector
- type LogLevel
- type Options
- type Query
- func (q *Query) AddIndex(table *Table, column *Column) (sql string, e error)
- func (q *Query) AddUniqueIndex(table *Table, column *Column) (sql string, e error)
- func (q *Query) AlterTableCreateColumn(table *Table, column *Column) (sql string, e error)
- func (q *Query) AlterTableDropColumn(table *Table, column *Column) (sql string, e error)
- func (q *Query) ChangeColumn(table *Table, localColumn *Column, remoteColumn *Column) (sql string, e error)
- func (q *Query) CreateChangeSQL(localSchema *Database, remoteSchema *Database) (sql string, e error)
- func (q *Query) CreateColumn(column *Column) (sql string, e error)
- func (q *Query) CreateTable(table *Table) (sql string, e error)
- func (q *Query) CreateTableChangeSQL(localTable *Table, remoteTable *Table) (sql string, e error)
- func (q *Query) DropIndex(table *Table, column *Column) (sql string, e error)
- func (q *Query) DropTable(table *Table) (sql string, e error)
- func (q *Query) DropUniqueIndex(table *Table, column *Column) (sql string, e error)
- type Server
- type SortedColumns
- type Table
Constants ¶
const ( // OptLogInfo triggers verbose logging OptLogInfo = 1 << iota // OptLogDebug triggers extremely verbose logging OptLogDebug // OptSilent suppresses all logging OptSilent // OptReverse reverses the function OptReverse // OptSummary shows a summary of the actions instead of a raw stdout dump OptSummary // OptClean cleans OptClean )
Variables ¶
This section is empty.
Functions ¶
func FetchDirFileNames ¶
FetchDirFileNames fetches returns a slice of strings of the name of the files in a directory (non-recursive)
func FetchNonDirFileNames ¶
FetchNonDirFileNames returns a list of files in a directory that are only regular files
func HashFileMd5 ¶
HashFileMd5 returns an MD5 checksum of the file at `filePath`
func RunCommand ¶ added in v1.1.0
RunCommand runs a system command
Types ¶
type ChangeFile ¶
type ChangeFile struct {
ID int64
DateCreated int64
Hash string
Name string
DVCSetID int64
IsRun bool
IsDeleted bool
Content string
FullPath string
Ordinal int
}
ChangeFile represents both a physical file on the local file system along with the entry in the changefile database
type Changeset ¶
type Changeset struct {
ChangeFiles map[string]ChangeFile
Signature string
}
Changeset represents all of the changes in an environment and their changes
type Column ¶
type Column struct {
Name string `json:"column"`
Position int `json:"position"`
Default string `json:"default"`
IsNullable bool `json:"isNullable"`
IsUnsigned bool `json:"isUnsigned"`
DataType string `json:"dataType"`
MaxLength int `json:"maxLength"`
Precision int `json:"precision"`
CharSet string `json:"charSet"`
Type string `json:"type"`
ColumnKey string `json:"columnKey"`
NumericScale int `json:"numericScale"`
Extra string `json:"extra"`
}
Column represents a column in a table
type Config ¶
type Config struct {
ChangeSetPath string `toml:"changesetPath"`
DatabaseType string `toml:"databaseType"`
BasePackage string `toml:"basePackage"`
Enums []string `toml:"enums"`
OneToMany map[string]string `toml:"onetomany"`
OneToOne map[string]string `toml:"onetoone"`
ManyToOne map[string]string `toml:"manytoone"`
Connection struct {
Host string `toml:"host"`
DatabaseName string `toml:"databaseName"`
Username string `toml:"username"`
Password string `toml:"password"`
}
Packages struct {
Cache string `toml:"cache"`
Models string `toml:"models"`
Schema string `toml:"schema"`
Repos string `toml:"repos"`
Services string `toml:"services"`
API string `toml:"api"`
}
Dirs struct {
Dal string `toml:"dal"`
Repos string `toml:"repos"`
Cache string `toml:"cache"`
Models string `toml:"models"`
Schema string `toml:"schema"`
Typescript string `toml:"typescript"`
Services string `toml:"services"`
Definitions string `toml:"definitions"`
API string `toml:"api"`
}
}
Config contains a set of configuration values used throughout the application
type Database ¶
type Database struct {
RunID int64
Name string
Host string `json:"-"`
SortedSetKeys []string
Tables map[string]*Table
Enums map[string][]map[string]interface{}
}
Database represents a database
func ReadSchemaFromFile ¶
ReadSchemaFromFile Unmarshal's database json to a Database object
type DatabaseType ¶ added in v1.1.1
type DatabaseType string
DatabaseType is the type of database to be used.
const ( // DatabaseTypeMysql is the MySQL flavor of database DatabaseTypeMysql DatabaseType = "mysql" // DatabaseTypeSqlite is the Sqlite flavor of database DatabaseTypeSqlite DatabaseType = "sqlite" )
type Files ¶
type Files struct {
}
Files contains functionality pertaining to files
func (*Files) BuildChangeFile ¶
func (f *Files) BuildChangeFile(sqlPath string, ordinal int) (changeFile *ChangeFile, e error)
BuildChangeFile builds a changeFile object based on a path and an ordinal
func (*Files) BuildChangeFiles ¶
func (f *Files) BuildChangeFiles(sqlPaths []string) (changeFiles []ChangeFile, e error)
BuildChangeFiles returns a collection of ChangeFile objects based on a collection of sql paths
func (*Files) FetchLocalChangesetList ¶
FetchLocalChangesetList gets the contents of the changesets.json file and returns a collection of paths ([]string)
type IConnector ¶
type IConnector interface {
Connect() (server *Server, e error)
FetchDatabases(server *Server) (databases map[string]*Database, e error)
FetchEnums(server *Server) (enums map[string][]map[string]interface{})
UseDatabase(server *Server, databaseName string) (e error)
FetchDatabaseTables(server *Server, databaseName string) (tables map[string]*Table, e error)
FetchTableColumns(server *Server, databaseName string, tableName string) (columns map[string]*Column, e error)
CreateChangeSQL(localSchema *Database, remoteSchema *Database) (sql string, e error)
CompareEnums(remoteSchema *Database, localSchema *Database, tableName string) (sql string)
}
IConnector defines the shape of a connector to a database
type LogLevel ¶
type LogLevel uint
LogLevel is a custom type for passing the level of logging specified by runtime flags
const ( // LogLevelAlways indicates that a log should always be printed regardless of flags LogLevelAlways LogLevel = 0 // LogLevelError indicates that a log should LogLevelError LogLevel = 1 // LogLevelWarning indicates a potential problem in the system. LogLevelWarning LogLevel = 2 // LogLevelInfo indicates that a log should be shown if the OptVerbose flag is passed LogLevelInfo LogLevel = 3 // LogLevelDebug indicates that a log should be written if the OptVerboseDebug flag is passed LogLevelDebug LogLevel = 4 )
type Query ¶
type Query struct{}
Query contains functionality for generating sql queries
func (*Query) AddIndex ¶
AddIndex returns an alter table sql statement that adds an index to a table
func (*Query) AddUniqueIndex ¶
AddUniqueIndex returns an alter table sql statement that adds a unique index to a table
func (*Query) AlterTableCreateColumn ¶
AlterTableCreateColumn returns an alter table sql statement that adds a column
func (*Query) AlterTableDropColumn ¶
AlterTableDropColumn returns an alter table sql statement that drops a column
func (*Query) ChangeColumn ¶
func (q *Query) ChangeColumn(table *Table, localColumn *Column, remoteColumn *Column) (sql string, e error)
ChangeColumn returns an alter table sql statement that adds or removes an index from a column if and only if the one (e.g. local) has a column and the other (e.g. remote) does not Truth table
Remote | Local | Result
--------------------------------------------------------- 1. MUL | none | Drop index 2. UNI | none | Drop unique index 3. none | MUL | Create index 4. none | UNI | Create unique index 5. MUL | UNI | Drop index; Create unique index 6. UNI | MUL | Drop unique index; Create index 7. none | none | Do nothing 8. MUL | MUL | Do nothing 9. UNI | UNI | Do nothing
func (*Query) CreateChangeSQL ¶
func (q *Query) CreateChangeSQL(localSchema *Database, remoteSchema *Database) (sql string, e error)
CreateChangeSQL generates sql statements based off of comparing two database objects localSchema is authority, remoteSchema will be upgraded to match localSchema
func (*Query) CreateColumn ¶
CreateColumn returns a table column sql segment
func (*Query) CreateTable ¶
CreateTable returns a create table sql statement
func (*Query) CreateTableChangeSQL ¶
CreateTableChangeSQL returns a set of statements that alter a table's structure if and only if there is a difference between the local and remote tables If no change is found, an empty string is returned.
type Server ¶
type Server struct {
Name string `json:"name"`
Host string `json:"host"`
Databases map[string]*Database
Connection *sql.DB
CurrentDatabase string
}
Server represents a server
func (*Server) DatabaseExists ¶
DatabaseExists checks if the database `databaseName` exists in its list of databases
type SortedColumns ¶
type SortedColumns []*Column
SortedColumns is a slice of Column objects
func (SortedColumns) Less ¶
func (c SortedColumns) Less(i, j int) bool
Less is part of sort.Interface. We use count as the value to sort by
type Table ¶
type Table struct {
Name string `json:"name"`
Engine string `json:"engine"`
Version int `json:"version"`
RowFormat string `json:"rowFormat"`
Rows int64 `json:"-"`
DataLength int64 `json:"-"`
Collation string `json:"collation"`
AutoIncrement int64 `json:"-"`
Columns map[string]*Column `json:"columns"`
}
Table represents a table in a database