Documentation ¶
Overview ¶
Package sqlmigr provides primitives and functions to work with SQL sqlmigrs.
Index ¶
- func Flog(logger log.Logger, migrations []*Migration)
- func Ftable(w io.Writer, migrations []*Migration)
- func IsNotExist(err error) bool
- func RunAll(db *sqlx.DB, storage FileSystem) error
- type Content
- type Executor
- func (m *Executor) Create(name string) (*Migration, error)
- func (m *Executor) Migrations() ([]*Migration, error)
- func (m *Executor) Revert(step int) (int, error)
- func (m *Executor) RevertAll() (int, error)
- func (m *Executor) Run(step int) (int, error)
- func (m *Executor) RunAll() (int, error)
- func (m *Executor) Setup() error
- type FileSystem
- type Generator
- type Migration
- type MigrationGenerator
- type MigrationProvider
- type MigrationRunner
- type Provider
- type Runner
- type RunnerError
- type WriteFileSystem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotExist ¶
IsNotExist reports if the error is because of migration table not exists
Types ¶
type Content ¶
type Content struct { // UpCommand is the content for upgrade operation. UpCommand io.Reader // DownCommand is the content for rollback operation. DownCommand io.Reader }
Content represents a migration content.
type Executor ¶
type Executor struct { // Logger logs each execution step Logger log.Logger // Provider provides all migrations for the current project. Provider MigrationProvider // Runner runs or reverts migrations for the current project. Runner MigrationRunner // Generator generates a migration file. Generator MigrationGenerator }
Executor provides a group of operations that works with migrations.
func (*Executor) Create ¶
Create creates a migration script successfully if the project has already been setup, otherwise returns an error.
func (*Executor) Migrations ¶
Migrations returns all migrations.
func (*Executor) Revert ¶
Revert reverts an applied migration for given count. If the count is negative number, it will revert all applied migrations.
func (*Executor) Run ¶
Run runs a pending migration for given count. If the count is negative number, it will execute all pending migrations.
type FileSystem ¶
FileSystem provides with primitives to work with the underlying file system
type Generator ¶
type Generator struct { // FileSystem is the file system where all sqlmigrs are created. FileSystem WriteFileSystem }
Generator generates a new sqlmigr file for given directory.
type Migration ¶
type Migration struct { // Id is the primary key for this sqlmigr ID string `db:"id"` // Description is the short description of this sqlmigr. Description string `db:"description"` // CreatedAt returns the time of sqlmigr execution. CreatedAt time.Time `db:"created_at"` // Drivers return all supported drivers Drivers []string `db:"-"` }
Migration represents a single migration record.
type MigrationGenerator ¶
type MigrationGenerator interface { // Create creates a new sqlmigr. Create(m *Migration) error // Write creates a new sqlmigr for given content. Write(m *Migration, content *Content) error }
MigrationGenerator generates a migration item file.
type MigrationProvider ¶
type MigrationProvider interface { // Migrations returns all sqlmigr items. Migrations() ([]*Migration, error) // Insert inserts executed sqlmigr item in the sqlmigrs table. Insert(item *Migration) error // Delete deletes applied sqlmigr item from sqlmigrs table. Delete(item *Migration) error // Exists returns true if the sqlmigr exists Exists(item *Migration) bool }
MigrationProvider provides all items.
type MigrationRunner ¶
type MigrationRunner interface { // Run runs a given sqlmigr item. Run(item *Migration) error // Revert reverts a given sqlmigr item. Revert(item *Migration) error }
MigrationRunner runs or reverts a given sqlmigr item.
type Provider ¶
type Provider struct { // FileSystem represents the project directory file system. FileSystem FileSystem // DB is a client to underlying database. DB *sqlx.DB }
Provider provides all migration for given project.
func (*Provider) Migrations ¶
Migrations returns the project migrations.
type Runner ¶
type Runner struct { // FileSystem represents the project directory file system. FileSystem FileSystem // DB is a client to underlying database. DB *sqlx.DB }
Runner runs or reverts a given migration item.
type RunnerError ¶
type RunnerError struct { // Err the actual error Err error // Statement that cause the issue Statement string }
RunnerError represents a runner error
type WriteFileSystem ¶
type WriteFileSystem interface { FileSystem // OpenFile opens a new file OpenFile(string, int, fs.FileMode) (fs.File, error) }
WriteFileSystem represents a wriable file system