Add resumable checked migrations and explicit schema administration commands. Port ML budgets, namespaces, identity and group persistence with three-backend contracts. Keep MySQL unavailable as the full application backend.
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package db
|
|
|
|
import "testing"
|
|
|
|
func TestMySQLMigrationPlanValidation(t *testing.T) {
|
|
valid := func() MySQLMigration {
|
|
return MySQLMigration{Version: 1, Name: "initial", Operations: []MySQLOperation{{SQL: "CREATE TABLE example(id BIGINT)", Check: "SELECT 0", ReplaySafe: true}}, Assertions: []string{"SELECT 1"}}
|
|
}
|
|
if e := validateMySQLPlan("machine-learning", []MySQLMigration{valid()}); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
for _, component := range []string{"", "../schema", "has space", "MixedCase"} {
|
|
if e := validateMySQLPlan(component, []MySQLMigration{valid()}); e == nil {
|
|
t.Fatal("invalid component accepted", component)
|
|
}
|
|
}
|
|
for _, mutate := range []func(*MySQLMigration){
|
|
func(m *MySQLMigration) { m.Version = 2 },
|
|
func(m *MySQLMigration) { m.Name = "" },
|
|
func(m *MySQLMigration) { m.Operations = nil },
|
|
func(m *MySQLMigration) { m.Operations[0].SQL = " " },
|
|
func(m *MySQLMigration) { m.Operations[0].Check = " " },
|
|
func(m *MySQLMigration) { m.Assertions = nil },
|
|
func(m *MySQLMigration) { m.Assertions[0] = " " },
|
|
} {
|
|
m := valid()
|
|
mutate(&m)
|
|
if e := validateMySQLPlan("test", []MySQLMigration{m}); e == nil {
|
|
t.Fatal("invalid plan accepted", m)
|
|
}
|
|
}
|
|
before := valid()
|
|
after := valid()
|
|
after.Operations[0].ReplaySafe = false
|
|
if mysqlMigrationHash(before) == mysqlMigrationHash(after) {
|
|
t.Fatal("replay policy not covered by checksum")
|
|
}
|
|
if mysqlMigrationHash(before) != mysqlMigrationHash(valid()) {
|
|
t.Fatal("unstable checksum")
|
|
}
|
|
}
|