保存人工处置持久化与实库回归检查点
This commit is contained in:
1 parent
ed0c97b957
commit
17eb2fc295
25 files changed
+1070
-3
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMySQLRealRecoveryDispositionMigrationRecovery(t *testing.T) {
|
||||
f := startRealMySQL(t)
|
||||
baseline := f.database(t)
|
||||
if err := Migrate(t.Context(), baseline.DB, "mysql"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := mysqlSchemaSnapshot(t, baseline.DB)
|
||||
for _, item := range []struct {
|
||||
version int
|
||||
table string
|
||||
seed string
|
||||
conflict string
|
||||
}{
|
||||
{22, "recovery_dispositions", `INSERT INTO recovery_dispositions VALUES
|
||||
('kept', 'transaction', 'server', 'unix:0', 'record_inspection', 'request', 'record', 'server', 'observation', 'running', '', NOW(), NOW())`,
|
||||
`ALTER TABLE recovery_dispositions DROP INDEX uq_recovery_request`},
|
||||
{23, "recovery_claims", `INSERT INTO recovery_claims VALUES ('transaction', 'kept', NOW())`,
|
||||
`ALTER TABLE recovery_claims DROP PRIMARY KEY`},
|
||||
{24, "recovery_events", `INSERT INTO recovery_events VALUES ('kept', 'started', '', NOW())`,
|
||||
`ALTER TABLE recovery_events DROP PRIMARY KEY, ADD PRIMARY KEY (event_type, disposition_id)`},
|
||||
} {
|
||||
for _, boundary := range []string{"before_create", "after_create", "with_record", "conflict"} {
|
||||
t.Run(fmt.Sprintf("%d/%s", item.version, boundary), func(t *testing.T) {
|
||||
db := f.database(t)
|
||||
mysqlPrepareVersion(t, db.DB, item.version-1)
|
||||
if boundary != "before_create" {
|
||||
mysqlDeploymentExec(t, db.DB, mysqlDeploymentStatements(t, item.version)[0])
|
||||
}
|
||||
if boundary == "with_record" || boundary == "conflict" {
|
||||
mysqlDeploymentExec(t, db.DB, item.seed)
|
||||
}
|
||||
if boundary == "conflict" {
|
||||
mysqlDeploymentExec(t, db.DB, item.conflict)
|
||||
before := fmt.Sprint(mysqlSchemaSnapshot(t, db.DB))
|
||||
assertMySQLDeploymentMigrationRejected(t, db.DB, item.version-1)
|
||||
if after := fmt.Sprint(mysqlSchemaSnapshot(t, db.DB)); after != before {
|
||||
t.Fatal("结构冲突不得自动修复或覆盖")
|
||||
}
|
||||
} else {
|
||||
mysqlAssertUpgrade(t, db.DB, expected)
|
||||
}
|
||||
if boundary == "with_record" || boundary == "conflict" {
|
||||
var count int
|
||||
if err := db.DB.QueryRowContext(t.Context(), "SELECT COUNT(*) FROM "+item.table).Scan(&count); err != nil || count != 1 {
|
||||
t.Fatal("迁移或冲突拒绝丢失已有处置记录", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user