Removing dev migration feature and checks (#892)
This commit is contained in:
1 parent
955ae41215
commit
57d4bf2bfd
7 files changed
+6
-85
No files matched your search
@@ -239,7 +239,6 @@ func TestManager_SharedLock(t *testing.T) {
|
||||
// Creates a new migrationState only with the versions <= the provided maxVer
|
||||
func createPartialMigrationState(om migrationState, maxVer int) migrationState {
|
||||
nState := migrationState{
|
||||
devMigration: om.devMigration,
|
||||
upMigrations: make(map[int][]byte),
|
||||
}
|
||||
for k := range om.upMigrations {
|
||||
|
||||
@@ -35,23 +35,14 @@ func generate(dialect string) {
|
||||
}
|
||||
var upContents []ContentValues
|
||||
|
||||
isDev := false
|
||||
var lRelVer, largestSchemaVersion int
|
||||
var largestSchemaVersion int
|
||||
for _, ver := range versions {
|
||||
var verVal int
|
||||
switch ver {
|
||||
case "dev":
|
||||
verVal = lRelVer + 1
|
||||
default:
|
||||
v, err := strconv.Atoi(ver)
|
||||
if err != nil {
|
||||
fmt.Printf("error reading major schema version directory %q. Must be a number or 'dev'\n", ver)
|
||||
os.Exit(1)
|
||||
}
|
||||
verVal = v
|
||||
if verVal > lRelVer {
|
||||
lRelVer = verVal
|
||||
}
|
||||
|
||||
verVal, err := strconv.Atoi(ver)
|
||||
if err != nil {
|
||||
fmt.Printf("error reading major schema version directory %q. Must be a number: %v\n", ver, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dir, err := os.Open(fmt.Sprintf("%s/%s/%s", srcDir, dialect, ver))
|
||||
@@ -65,10 +56,6 @@ func generate(dialect string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if ver == "dev" && len(names) > 0 {
|
||||
isDev = true
|
||||
}
|
||||
|
||||
sort.Strings(names)
|
||||
for _, name := range names {
|
||||
if !strings.HasSuffix(name, ".sql") {
|
||||
@@ -121,12 +108,10 @@ func generate(dialect string) {
|
||||
if err := migrationsTemplate.Execute(outBuf, struct {
|
||||
Type string
|
||||
UpValues []ContentValues
|
||||
DevMigration bool
|
||||
BinarySchemaVersion int
|
||||
}{
|
||||
Type: dialect,
|
||||
UpValues: upContents,
|
||||
DevMigration: isDev,
|
||||
BinarySchemaVersion: largestSchemaVersion,
|
||||
}); err != nil {
|
||||
fmt.Printf("error executing migrations value template for dialect %s: %s", dialect, err)
|
||||
@@ -148,7 +133,6 @@ var migrationsTemplate = template.Must(template.Must(template.New("Content").Par
|
||||
|
||||
func init() {
|
||||
migrationStates["{{ .Type }}"] = migrationState{
|
||||
devMigration: {{ .DevMigration }},
|
||||
binarySchemaVersion: {{ .BinarySchemaVersion }},
|
||||
upMigrations: map[int][]byte{
|
||||
{{range .UpValues }}{{ template "Content" . }}{{end}}
|
||||
|
||||
@@ -4,7 +4,6 @@ package schema
|
||||
|
||||
func init() {
|
||||
migrationStates["postgres"] = migrationState{
|
||||
devMigration: false,
|
||||
binarySchemaVersion: 1003,
|
||||
upMigrations: map[int][]byte{
|
||||
1: []byte(`
|
||||
|
||||
@@ -5,11 +5,6 @@ const nilVersion = -1
|
||||
// migrationState is meant to be populated by the generated migration code and
|
||||
// contains the internal representation of a schema in the current binary.
|
||||
type migrationState struct {
|
||||
// devMigration is true if the database schema that would be applied by
|
||||
// MigrateStore would be from files in the /dev directory which indicates it would
|
||||
// not be safe to run in a non dev environment.
|
||||
devMigration bool
|
||||
|
||||
// binarySchemaVersion provides the database schema version supported by
|
||||
// this binary.
|
||||
binarySchemaVersion int
|
||||
@@ -28,12 +23,6 @@ func getUpMigration(dialect string) map[int][]byte {
|
||||
return ms.upMigrations
|
||||
}
|
||||
|
||||
// DevMigration returns true iff the provided dialect has changes which are still in development.
|
||||
func DevMigration(dialect string) bool {
|
||||
ms, ok := migrationStates[dialect]
|
||||
return ok && ms.devMigration
|
||||
}
|
||||
|
||||
// BinarySchemaVersion provides the schema version that this binary supports for the provided dialect.
|
||||
// If the binary doesn't support this dialect -1 is returned.
|
||||
func BinarySchemaVersion(dialect string) int {
|
||||
|
||||
@@ -12,12 +12,3 @@ func TestBinarySchemaVersion(t *testing.T) {
|
||||
assert.Equal(t, 3, BinarySchemaVersion(dialect))
|
||||
assert.Equal(t, nilVersion, BinarySchemaVersion("unknown_dialect"))
|
||||
}
|
||||
|
||||
func TestDevMigration(t *testing.T) {
|
||||
dialect := "test_devmigrations"
|
||||
migrationStates[dialect] = migrationState{devMigration: true}
|
||||
assert.True(t, DevMigration(dialect))
|
||||
migrationStates[dialect] = migrationState{devMigration: false}
|
||||
assert.False(t, DevMigration(dialect))
|
||||
assert.False(t, DevMigration("unknown_dialect"))
|
||||
}
|
||||
Reference in new issue
Block a user