lib

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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 Debug

func Debug(content string, options Options)

Debug writes a debug level log

func Debugf

func Debugf(content string, options Options, a ...interface{})

Debugf writes a formatted debug level log

func Error

func Error(content string, options Options)

Error writes an error level log

func Errorf

func Errorf(content string, options Options, a ...interface{})

Errorf writes a formatted error level log

func FetchDirFileNames

func FetchDirFileNames(dirPath string) (dirs []string, e error)

FetchDirFileNames fetches returns a slice of strings of the name of the files in a directory (non-recursive)

func FetchFile

func FetchFile(filePath string) (changesetFileString string, e error)

FetchFile fetches a file contents

func FetchNonDirFileNames

func FetchNonDirFileNames(dirPath string) (files []string, e error)

FetchNonDirFileNames returns a list of files in a directory that are only regular files

func HashFileMd5

func HashFileMd5(filePath string) (string, error)

HashFileMd5 returns an MD5 checksum of the file at `filePath`

func Info

func Info(content string, options Options)

Info writes an info level log

func Infof

func Infof(content string, options Options, a ...interface{})

Infof writes a formatted info level log

func Log

func Log(content string, logLevel LogLevel, options Options)

Log writes to a log based on its log level and the runtime options passed

func RunCommand added in v1.1.0

func RunCommand(name string, args ...string) (stdout string, stderr string, exitCode int)

func Warn

func Warn(content string, options Options)

Warn writes a warn level log

func Warnf

func Warnf(content string, options Options, a ...interface{})

Warnf writes a formatted warn level log

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 Command

type Command struct {
	Options Options
}

Command is the command line functionality

type Config

type Config struct {
	ChangeSetPath string   `toml:"changesetPath"`
	DatabaseType  string   `toml:"databaseType"`
	BasePackage   string   `toml:"basePackage"`
	Enums         []string `toml:"enums"`

	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"`
	}

	Dirs struct {
		Repos      string `toml:"repos"`
		Cache      string `toml:"cache"`
		Models     string `toml:"models"`
		Schema     string `toml:"schema"`
		Typescript string `toml:"typescript"`
		Services   string `toml:"services"`
	}
}

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

func ReadSchemaFromFile(filePath string) (database *Database, e error)

ReadSchemaFromFile Unmarshal's database json to a Database object

func (*Database) FindTableByName

func (d *Database) FindTableByName(tableName string) (table *Table, e error)

FindTableByName finds a table by its name in the database

type DatabaseType added in v1.1.1

type DatabaseType string
const (
	DatabaseTypeMysql  DatabaseType = "mysql"
	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

func (f *Files) FetchLocalChangesetList(rootPath string) (sqlPaths []string, e error)

FetchLocalChangesetList gets the contents of the changesets.json file and returns a collection of paths ([]string)

func (*Files) ScanDir

func (f *Files) ScanDir(rootPath string, extension string) (paths []string, e error)

ScanDir scans the changeset directory for any file with an extension

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 Options

type Options uint

Options are the available runtime flags

type Query

type Query struct{}

Query contains functionality for generating sql queries

func (*Query) AddIndex

func (q *Query) AddIndex(table *Table, column *Column) (sql string, e error)

AddIndex returns an alter table sql statement that adds an index to a table

func (*Query) AddUniqueIndex

func (q *Query) AddUniqueIndex(table *Table, column *Column) (sql string, e error)

AddUniqueIndex returns an alter table sql statement that adds a unique index to a table

func (*Query) AlterTableCreateColumn

func (q *Query) AlterTableCreateColumn(table *Table, column *Column) (sql string, e error)

AlterTableCreateColumn returns an alter table sql statement that adds a column

func (*Query) AlterTableDropColumn

func (q *Query) AlterTableDropColumn(table *Table, column *Column) (sql string, e error)

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

func (q *Query) CreateColumn(column *Column) (sql string, e error)

CreateColumn returns a table column sql segment

func (*Query) CreateTable

func (q *Query) CreateTable(table *Table) (sql string, e error)

CreateTable returns a create table sql statement

func (*Query) CreateTableChangeSQL

func (q *Query) CreateTableChangeSQL(localTable *Table, remoteTable *Table) (sql string, e error)

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.

func (*Query) DropIndex

func (q *Query) DropIndex(table *Table, column *Column) (sql string, e error)

DropIndex returns an alter table sql statement that drops an index

func (*Query) DropTable

func (q *Query) DropTable(table *Table) (sql string, e error)

DropTable returns a drop table sql statement

func (*Query) DropUniqueIndex

func (q *Query) DropUniqueIndex(table *Table, column *Column) (sql string, e error)

DropUniqueIndex returns an alter table sql statement that drops a unique index

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

func (s *Server) DatabaseExists(databaseName string) bool

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) Len

func (c SortedColumns) Len() int

Len is part of sort.Interface.

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

func (SortedColumns) Swap

func (c SortedColumns) Swap(i, j int)

Swap is part of sort.Interface.

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

Jump to

Keyboard shortcuts

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