Documentation ¶
Index ¶
- Variables
- func New1() *cli.Command
- func Open(driverName, dataSourceName string) (*sql.Driver, error)
- type Config
- type GoMigrate
- func (g *GoMigrate) Close() error
- func (g *GoMigrate) Cmd() *cli.Command
- func (g *GoMigrate) Create(tables []*schema.Table) error
- func (g *GoMigrate) List() ([]*MigrationWrap, error)
- func (g *GoMigrate) Migrate() error
- func (g *GoMigrate) MigrateTo(name string) error
- func (g *GoMigrate) RollbackLast() error
- func (g *GoMigrate) RollbackTo(name string) error
- type MigrateFunc
- type Migration
- type MigrationWrap
- type RollbackFunc
- type Tx
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrRollbackImpossible is returned when trying to rollback a migration // that has no rollback function. ErrRollbackImpossible = errors.New("ormigrate: It's impossible to rollback this migration") // ErrNoMigrationDefined is returned when no migration is defined. ErrNoMigrationDefined = errors.New("ormigrate: No migration defined") // ErrMissingID is returned when the ID od migration is equal to "" ErrMissingID = errors.New("ormigrate: Missing ID in migration") // ErrNoRunMigration is returned when any run migration was found while // running RollbackLast ErrNoRunMigration = errors.New("ormigrate: Could not find last run migration") // ErrMigrationIDDoesNotExist is returned when migrating or rolling back to a migration ID that // does not exist in the list of migrations ErrMigrationIDDoesNotExist = errors.New("ormigrate: Tried to migrate to an ID that doesn't exist") // ErrUnknownPastMigration is returned if a migration exists in the DB that doesn't exist in the code ErrUnknownPastMigration = errors.New("ormigrate: Found migration in DB that does not exist in code") )
View Source
var DefaultConfig = Config{
TableName: "migrations",
ColumnName: "id",
ColumnSize: 255,
MigrationPath: "./internal/schema/migrations",
}
DefaultConfig can be used if you don't want to think about config.
Functions ¶
Types ¶
type Config ¶
type Config struct { GenTx func(db *entsql.Driver) Tx `yaml:"-" json:"-"` // TableName is the migration table. TableName string `yaml:"table_name"` // ColumnName is the name of column where the migration id will be stored. ColumnName string `yaml:"column_name"` // ColumnSize is the length of the migration id column ColumnSize int `yaml:"column_size"` MigrationPath string `yaml:"migration_path"` }
Config define config for all migrations.
type GoMigrate ¶
type GoMigrate struct {
// contains filtered or unexported fields
}
GoMigrate represents a collection of all migrations of a database schema.
func New ¶
func New(db *entsql.Driver, cfg *Config, migrations []*Migration, tables []*schema.Table) *GoMigrate
New returns a new GoMigrate.
func (*GoMigrate) List ¶
func (g *GoMigrate) List() ([]*MigrationWrap, error)
func (*GoMigrate) RollbackLast ¶
RollbackLast undo the last migration
func (*GoMigrate) RollbackTo ¶
RollbackTo undoes migrations up to the given migration that matches the `migrationID`. Migration with the matching `name` is not rolled back.
type MigrateFunc ¶
MigrateFunc is the func signature for migrating.
type Migration ¶
type Migration struct { Name string Description string SchemaSqlFile string // DataMigrate is a function that will br executed while running this migration. DataMigrate MigrateFunc // DataRollback will be executed on rollback. Can be nil. DataRollback RollbackFunc }
Migration represents a database migration
type MigrationWrap ¶
type RollbackFunc ¶
RollbackFunc is the func signature for rollbacking.
Click to show internal directories.
Click to hide internal directories.