Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultGoMigrationLoader = &GoMigrationLoader{ m: []Migration{}, }
View Source
var GoDefaultTemplateData = `` /* 1093-byte string literal not displayed */
View Source
var SQLDownDefaultTemplateData = `-- DOWN: {{.version.name}}
`
View Source
var SQLUpDefaultTemplateData = `-- UP: {{.version.name}}
`
View Source
var VersionDefaultTemplateData = `1.0.0.{{.timestamp}}`
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type GoMigrationLoader ¶
type GoMigrationLoader struct {
// contains filtered or unexported fields
}
func (*GoMigrationLoader) Add ¶
func (l *GoMigrationLoader) Add(m Migration)
func (*GoMigrationLoader) Clear ¶
func (l *GoMigrationLoader) Clear()
func (*GoMigrationLoader) Load ¶
func (l *GoMigrationLoader) Load() ([]Migration, error)
type Migrate ¶
type Migrate struct {
// contains filtered or unexported fields
}
Migrate is entry point struct that can trigger database updating or downgrading
func NewMigrate ¶
func NewMigrate(c Connection, loaders ...MigrationLoader) *Migrate
NewMigrate creates new struct that can start migration. `c` is a connection to database, you can use gorm connection. `loaders` is migrations loaders, it can be `sql` or `go` migrations loader
func (*Migrate) ApplyLostAndPanic ¶
func (*Migrate) ApplyLostIfAny ¶ added in v1.0.1
func (*Migrate) DownWithSteps ¶
DownWithSteps runs migrations to downgrade database version. `steps` is number of latest migrations that needs to be unapplied.
func (*Migrate) SetConncetion ¶
func (m *Migrate) SetConncetion(c Connection)
SetConncetion sets database connection that will be used for migration
func (*Migrate) UpToLatest ¶
UpToLatest loads all needed migrations, filters migrations that already applied, and starts migration process.
type Migration ¶
type Migration interface { SetConnection(c Connection) Version() Version SetVersion(v *Version) Up() error Down() error }
type MigrationLoader ¶
type MigrationsLoader ¶
type SQLMigration ¶
type SQLMigration struct { UpFile *os.File DownFile *os.File // contains filtered or unexported fields }
func (*SQLMigration) Down ¶
func (m *SQLMigration) Down() error
func (*SQLMigration) SetConnection ¶
func (m *SQLMigration) SetConnection(c Connection)
func (*SQLMigration) SetVersion ¶
func (m *SQLMigration) SetVersion(v *Version)
func (*SQLMigration) Up ¶
func (m *SQLMigration) Up() error
func (*SQLMigration) Version ¶
func (m *SQLMigration) Version() Version
type SQLMigrationsLoader ¶
type SQLMigrationsLoader struct {
// contains filtered or unexported fields
}
func NewSQLMigrationLoader ¶
func NewSQLMigrationLoader(path string) *SQLMigrationsLoader
func (*SQLMigrationsLoader) Load ¶
func (l *SQLMigrationsLoader) Load() ([]Migration, error)
type Template ¶
type Template struct { Type TemplateType // contains filtered or unexported fields }
func (*Template) BuildVersion ¶
type TemplateType ¶
type TemplateType string
const ( TemplateTypeSQLUp TemplateType = "sql-up" TemplateTypeSQLDown TemplateType = "sql-down" TemplateTypeGo TemplateType = "go" TemplateTypeVersion TemplateType = "version" )
type Templater ¶
type Templater struct {
// contains filtered or unexported fields
}
func (*Templater) ContentForTemplateType ¶
func (t *Templater) ContentForTemplateType(tmplType TemplateType, v *Version) ([]byte, error)
func (*Templater) LoadTemplates ¶
func (*Templater) TampleteWithType ¶
func (t *Templater) TampleteWithType(tmplType TemplateType) *Template
type Transaction ¶
type Version ¶
type Version struct { Name string // contains filtered or unexported fields }
func GreatestVersion ¶
func StringsToVersions ¶
func VersionFromString ¶
func (Version) GreaterThan ¶
func (Version) GreaterThanOrEqual ¶
func (Version) StringWithoutName ¶ added in v1.0.2
Source Files ¶
Click to show internal directories.
Click to hide internal directories.