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 DVC
- type Database
- 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 Gen
- func (g *Gen) EnsureDir(dir string) (e error)
- func (g *Gen) GenerateCacheBootstrapFile(dir string, database *Database) (e error)
- func (g *Gen) GenerateCacheBootstrapGoCodeFromDatabase(database *Database) (goCode string, e error)
- func (g *Gen) GenerateGoCache(table *Table, fileFoot string, imports []string) (goCode string, e error)
- func (g *Gen) GenerateGoCacheFile(dir string, table *Table) (e error)
- func (g *Gen) GenerateGoCacheFiles(reposDir string, database *Database) (e error)
- func (g *Gen) GenerateGoModel(table *Table, imports []string) (goCode string, e error)
- func (g *Gen) GenerateGoModelFile(dir string, table *Table) (e error)
- func (g *Gen) GenerateGoModels(database *Database) (goCode string, e error)
- func (g *Gen) GenerateGoRepo(table *Table, fileFoot string, imports []string) (goCode string, e error)
- func (g *Gen) GenerateGoRepoFile(dir string, table *Table) (e error)
- func (g *Gen) GenerateGoRepoFiles(reposDir string, database *Database) (e error)
- func (g *Gen) GenerateGoSchema(database *Database) (goCode string, e error)
- func (g *Gen) GenerateGoSchemaFile(dir string, database *Database) (e error)
- func (g *Gen) GenerateReposBootstrapFile(dir string, database *Database) (e error)
- func (g *Gen) GenerateReposBootstrapGoCodeFromDatabase(database *Database) (goCode string, e error)
- func (g *Gen) GenerateTypescriptType(table *Table) (goCode string, e error)
- func (g *Gen) GenerateTypescriptTypes(database *Database) (goCode string, e error)
- func (g *Gen) GenerateTypescriptTypesFile(dir string, database *Database) (e error)
- func (g *Gen) WriteGoCodeToFile(goCode string, filePath 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
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"`
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 `tomls: "repos"`
}
Dirs struct {
Repos string `toml:"repos"`
Cache string `toml:"cache"`
Models string `toml:"models"`
Schema string `toml:"schema"`
Typescript string `toml:"typescript"`
}
}
Config contains a set of configuration values used throughout the application
type DVC ¶
type DVC struct {
Config *Config // Config is the config object
LocalSQLPaths []string // LocalSQLPaths is a list of paths pulled from the changesets.json file
ChangesetSignature string // ChangesetSignature is a SHA signature for the changesets.json file
LocalChangeFiles []ChangeFile // LocalChangeFiles is a list of paths to local change files
Files *Files // Files is the injected file manager
Connector IConnector // IConnector is the injected server manager
Databases map[string]*Database // A map of databases
}
DVC is the core object for running Database Version Control
func NewDVC ¶
NewDVC creates a new DVC instance Can be called 2 ways:
- NewDvc(filePath)
- NewDvc(host, databaseName, username, password, changesetPath, databaseType)
func (*DVC) ApplyChangeset ¶
ApplyChangeset runs the sql produced by the `CompareSchema` command against the target database @command compare [reverse] apply
func (*DVC) CompareSchema ¶
CompareSchema returns a string that contains a new line (`\n`) separated list of sql statements This comparison assumes the local `schemaFile` is the authority and the remote database is the schema to be updated @param reverse bool If true, the remote and local schema comparison is flipped in that the remote schema is treated as the authority
and the local schema is treated as the schema to be updated.
@command compare [reverse]
func (*DVC) ExportSchemaToSQL ¶ added in v1.1.0
func (*DVC) ImportSchema ¶
ImportSchema calles `FetchSchema` and then marshal's it into a JSON object, writing it to the default schema.json file @command import
type Database ¶
type Database struct {
RunID int64
Name string
Host string `json:"-"`
// Sets map[string]*ChangeSet
SortedSetKeys []string
Tables map[string]*Table
}
Database represents a database
func ReadSchemaFromFile ¶
ReadSchemaFromFile Unmarshal's database json to a Database object
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 Gen ¶
type Gen struct {
Options Options
}
Gen conntains all of the generator functionality
func (*Gen) GenerateCacheBootstrapFile ¶ added in v1.1.0
GenerateCacheBootstrapFile generates a repos bootstrap file in golang
func (*Gen) GenerateCacheBootstrapGoCodeFromDatabase ¶ added in v1.1.0
GenerateCacheBootstrapGoCodeFromDatabase generates golang code for a Repo Bootstrap file from a database object
func (*Gen) GenerateGoCache ¶ added in v1.1.0
func (g *Gen) GenerateGoCache(table *Table, fileFoot string, imports []string) (goCode string, e error)
GenerateGoCache returns a string for a repo in golang
func (*Gen) GenerateGoCacheFile ¶ added in v1.1.0
GenerateGoCacheFile generates a repo file in golang
func (*Gen) GenerateGoCacheFiles ¶ added in v1.1.0
GenerateGoCacheFiles generates go repository files based on the database schema
func (*Gen) GenerateGoModel ¶
GenerateGoModel returns a string for a model in golang
func (*Gen) GenerateGoModelFile ¶
GenerateGoModelFile generates a model file in golang
func (*Gen) GenerateGoModels ¶
GenerateGoModels generates models for golang
func (*Gen) GenerateGoRepo ¶
func (g *Gen) GenerateGoRepo(table *Table, fileFoot string, imports []string) (goCode string, e error)
GenerateGoRepo returns a string for a repo in golang
func (*Gen) GenerateGoRepoFile ¶
GenerateGoRepoFile generates a repo file in golang
func (*Gen) GenerateGoRepoFiles ¶
GenerateGoRepoFiles generates go repository files based on the database schema
func (*Gen) GenerateGoSchema ¶
GenerateGoSchema generates golang code for a schema file
func (*Gen) GenerateGoSchemaFile ¶
GenerateGoSchemaFile generates a schema file in golang
func (*Gen) GenerateReposBootstrapFile ¶
GenerateReposBootstrapFile generates a repos bootstrap file in golang
func (*Gen) GenerateReposBootstrapGoCodeFromDatabase ¶
GenerateReposBootstrapGoCodeFromDatabase generates golang code for a Repo Bootstrap file from a database object
func (*Gen) GenerateTypescriptType ¶
GenerateTypescriptType returns a string for a type in typescript
func (*Gen) GenerateTypescriptTypes ¶
GenerateTypescriptTypes returns a string for a typscript types file
func (*Gen) GenerateTypescriptTypesFile ¶
GenerateTypescriptTypesFile generates a typescript type file
type IConnector ¶
type IConnector interface {
Connect() (server *Server, e error)
FetchDatabases(server *Server) (databases map[string]*Database, e error)
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)
}
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