2022-03-06 05:47:40 +00:00
|
|
|
package model
|
2020-07-16 05:56:08 +00:00
|
|
|
|
2023-04-08 01:36:34 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-11-23 09:45:38 +00:00
|
|
|
// SchemaMigration represents an intended migration.
|
|
|
|
type SchemaMigration struct {
|
|
|
|
Version int
|
|
|
|
Name string
|
|
|
|
Provider string
|
|
|
|
Up bool
|
|
|
|
Query string
|
|
|
|
}
|
2020-07-16 05:56:08 +00:00
|
|
|
|
2023-04-08 01:36:34 +00:00
|
|
|
// NotEmpty returns true if the SchemaMigration is not an empty string.
|
|
|
|
func (m SchemaMigration) NotEmpty() bool {
|
|
|
|
return len(strings.TrimSpace(m.Query)) != 0
|
|
|
|
}
|
|
|
|
|
2021-11-23 09:45:38 +00:00
|
|
|
// Before returns the version the schema should be at Before the migration is applied.
|
|
|
|
func (m SchemaMigration) Before() (before int) {
|
|
|
|
if m.Up {
|
|
|
|
return m.Version - 1
|
|
|
|
}
|
2020-07-16 05:56:08 +00:00
|
|
|
|
2021-11-23 09:45:38 +00:00
|
|
|
return m.Version
|
2020-07-16 05:56:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-23 09:45:38 +00:00
|
|
|
// After returns the version the schema will be at After the migration is applied.
|
|
|
|
func (m SchemaMigration) After() (after int) {
|
|
|
|
if m.Up {
|
|
|
|
return m.Version
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.Version - 1
|
2020-07-16 05:56:08 +00:00
|
|
|
}
|