Documentation ¶
Index ¶
- func Migrate(d Driver, migrations []Migration, infoChan chan MigrationInfo) error
- func Validate(d Driver, migrations []Migration) error
- type Darwin
- type Dialect
- type Driver
- type DuplicateMigrationVersionError
- type GenericDriver
- type IllegalMigrationVersionError
- type InvalidChecksumError
- type Migration
- type MigrationInfo
- type MigrationRecord
- type MySQLDialect
- type PostgresDialect
- type QLDialect
- type RemovedMigrationError
- type SqliteDialect
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Darwin ¶
type Darwin struct {
// contains filtered or unexported fields
}
Darwin is a helper struct to access the Validate and migration functions
func New ¶
func New(driver Driver, migrations []Migration, infoChan chan MigrationInfo) Darwin
New returns a new Darwin struct
func (Darwin) Info ¶
func (d Darwin) Info() ([]MigrationInfo, error)
Info returns the status of all migrations
type Dialect ¶
type Dialect interface { // CreateTableSQL returns the SQL to create the schema table CreateTableSQL() string // InsertSQL returns the SQL to insert a new migration in the schema table InsertSQL() string // AllSQL returns a SQL to get all entries in the table AllSQL() string }
Dialect is used to use multiple databases
type Driver ¶
type Driver interface { Create() error Insert(e MigrationRecord) error All() ([]MigrationRecord, error) Exec(string) (time.Duration, error) }
Driver a database driver abstraction
type DuplicateMigrationVersionError ¶
type DuplicateMigrationVersionError struct {
Version float64
}
DuplicateMigrationVersionError is used to report when the migration list has duplicated entries
func (DuplicateMigrationVersionError) Error ¶
func (d DuplicateMigrationVersionError) Error() string
type GenericDriver ¶
GenericDriver is the default Driver, it can be configured to any database.
func NewGenericDriver ¶
func NewGenericDriver(db *sql.DB, dialect Dialect) *GenericDriver
NewGenericDriver creates a new GenericDriver configured with db and dialect. Panic if db or dialect is nil
func (*GenericDriver) All ¶
func (m *GenericDriver) All() ([]MigrationRecord, error)
All returns all migrations applied
func (*GenericDriver) Create ¶
func (m *GenericDriver) Create() error
Create create the table darwin_migrations if necessary
func (*GenericDriver) Exec ¶
func (m *GenericDriver) Exec(script string) (time.Duration, error)
Exec execute sql scripts into database
func (*GenericDriver) Insert ¶
func (m *GenericDriver) Insert(e MigrationRecord) error
Insert insert a migration entry into database
type IllegalMigrationVersionError ¶
type IllegalMigrationVersionError struct {
Version float64
}
IllegalMigrationVersionError is used to report when the migration has an illegal Version number
func (IllegalMigrationVersionError) Error ¶
func (i IllegalMigrationVersionError) Error() string
type InvalidChecksumError ¶
type InvalidChecksumError struct {
Version float64
}
InvalidChecksumError is used to report when a migration was modified
func (InvalidChecksumError) Error ¶
func (i InvalidChecksumError) Error() string
type MigrationInfo ¶
MigrationInfo is a struct used in the infoChan to inform clients about the migration being applied.
type MigrationRecord ¶
type MigrationRecord struct { Version float64 Description string Checksum string AppliedAt time.Time ExecutionTime time.Duration }
MigrationRecord is the entry in schema table
type MySQLDialect ¶
type MySQLDialect struct{}
MySQLDialect a Dialect configured for MySQL
func (MySQLDialect) AllSQL ¶
func (m MySQLDialect) AllSQL() string
AllSQL returns a SQL to get all entries in the table
func (MySQLDialect) CreateTableSQL ¶
func (m MySQLDialect) CreateTableSQL() string
CreateTableSQL returns the SQL to create the schema table
func (MySQLDialect) InsertSQL ¶
func (m MySQLDialect) InsertSQL() string
InsertSQL returns the SQL to insert a new migration in the schema table
type PostgresDialect ¶
type PostgresDialect struct{}
PostgresDialect a Dialect configured for PostgreSQL
func (PostgresDialect) AllSQL ¶
func (p PostgresDialect) AllSQL() string
AllSQL returns a SQL to get all entries in the table
func (PostgresDialect) CreateTableSQL ¶
func (p PostgresDialect) CreateTableSQL() string
CreateTableSQL returns the SQL to create the schema table
func (PostgresDialect) InsertSQL ¶
func (p PostgresDialect) InsertSQL() string
InsertSQL returns the SQL to insert a new migration in the schema table
type QLDialect ¶
type QLDialect struct { }
QLDialect implements Dialect interface for ql database
func (QLDialect) CreateTableSQL ¶
CreateTableSQL returns the SQL to create the schema table
type RemovedMigrationError ¶
type RemovedMigrationError struct {
Version float64
}
RemovedMigrationError is used to report when a migration is removed from the list
func (RemovedMigrationError) Error ¶
func (r RemovedMigrationError) Error() string
type SqliteDialect ¶
type SqliteDialect struct{}
SqliteDialect a Dialect configured for Sqlite3
func (SqliteDialect) AllSQL ¶
func (s SqliteDialect) AllSQL() string
AllSQL returns a SQL to get all entries in the table
func (SqliteDialect) CreateTableSQL ¶
func (s SqliteDialect) CreateTableSQL() string
CreateTableSQL returns the SQL to create the schema table
func (SqliteDialect) InsertSQL ¶
func (s SqliteDialect) InsertSQL() string
InsertSQL returns the SQL to insert a new migration in the schema table
type Status ¶
type Status int
Status is a migration status value
const ( // Ignored means that the migrations was not appied to the database Ignored Status = iota // Applied means that the migrations was successfully applied to the database Applied // Pending means that the migrations is a new migration and it is waiting to be applied to the database Pending // Error means that the migration could not be applied to the database Error )