保存不确定部署处置重新核查实现及测试检查点
This commit is contained in:
1 parent
7fa5e9b3d2
commit
f9cd19f631
29 files changed
+907
-49
No files matched your search
@@ -25,6 +25,7 @@ import (
|
||||
//go:embed migrations/sqlite/0022_recovery_dispositions.sql migrations/mysql/0022_recovery_dispositions.sql migrations/postgres/0022_recovery_dispositions.sql
|
||||
//go:embed migrations/sqlite/0023_recovery_claims.sql migrations/mysql/0023_recovery_claims.sql migrations/postgres/0023_recovery_claims.sql
|
||||
//go:embed migrations/sqlite/0024_recovery_events.sql migrations/mysql/0024_recovery_events.sql migrations/postgres/0024_recovery_events.sql
|
||||
//go:embed migrations/sqlite/0025_recovery_reconciliation.sql migrations/mysql/0025_recovery_reconciliation.sql migrations/postgres/0025_recovery_reconciliation.sql
|
||||
var migrationFiles embed.FS
|
||||
|
||||
func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
@@ -49,7 +50,7 @@ func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const latestMigrationVersion = 24
|
||||
const latestMigrationVersion = 25
|
||||
|
||||
// currentMigrationVersion 在执行业务迁移前拒绝新版数据库及不连续的迁移历史。
|
||||
func currentMigrationVersion(ctx context.Context, db *sql.DB) (int, error) {
|
||||
@@ -114,6 +115,14 @@ func applyMigration(ctx context.Context, db *sql.DB, driver string, version int)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if version == 25 {
|
||||
var compatible int
|
||||
if err := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE()
|
||||
AND table_name = 'recovery_dispositions' AND column_name = 'source_disposition_id'
|
||||
AND data_type = 'varchar' AND character_maximum_length = 64 AND is_nullable = 'NO' AND column_default = ''`).Scan(&compatible); err != nil || compatible != 1 {
|
||||
return fmt.Errorf("人工处置来源字段与预期不一致,拒绝记录迁移版本")
|
||||
}
|
||||
}
|
||||
if _, err := db.ExecContext(ctx, "INSERT INTO schema_migrations (version) VALUES (?)", version); err != nil {
|
||||
return fmt.Errorf("记录迁移版本失败:%w", err)
|
||||
}
|
||||
@@ -252,6 +261,8 @@ func migrationName(version int) string {
|
||||
return "recovery_claims"
|
||||
case 24:
|
||||
return "recovery_events"
|
||||
case 25:
|
||||
return "recovery_reconciliation"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE recovery_dispositions ADD COLUMN source_disposition_id VARCHAR(64) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE recovery_dispositions ADD COLUMN source_disposition_id VARCHAR(64) NOT NULL DEFAULT '';
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE recovery_dispositions ADD COLUMN source_disposition_id TEXT NOT NULL DEFAULT '';
|
||||
@@ -25,6 +25,10 @@ func TestMySQLRealRecoveryDispositionMigrationRecovery(t *testing.T) {
|
||||
`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)`},
|
||||
{25, "recovery_dispositions", `INSERT INTO recovery_dispositions (id, transaction_id, server_id, operator_id, action, request_key,
|
||||
record_digest, server_digest, observation_digest, status, result_code, created_at, updated_at) VALUES
|
||||
('kept', 'transaction', 'server', 'unix:0', 'finish_commit', 'request', 'record', 'server', 'observation', 'uncertain', 'uncertain', NOW(), NOW())`,
|
||||
`ALTER TABLE recovery_dispositions MODIFY COLUMN source_disposition_id VARCHAR(8) NOT NULL DEFAULT ''`},
|
||||
} {
|
||||
for _, boundary := range []string{"before_create", "after_create", "with_record", "conflict"} {
|
||||
t.Run(fmt.Sprintf("%d/%s", item.version, boundary), func(t *testing.T) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func TestPostgresRealRecoveryDispositionMigration(t *testing.T) {
|
||||
server := postgrestest.New(t)
|
||||
for version := 22; version <= 24; version++ {
|
||||
for version := 22; version <= 25; version++ {
|
||||
t.Run(fmt.Sprint(version), func(t *testing.T) {
|
||||
cfg := server.Database(t)
|
||||
db, err := Open(t.Context(), cfg)
|
||||
|
||||
Reference in new issue
Block a user