保存证书校验后台任务及独立结果的修复前基线
校验结果事务持久化、三库迁移及前端详情接线已实现,完整回归仍在执行。审查发现前端校验幂等键包含路径分隔符,下一批补回归并修复;本提交不是正式发布或生产验收结论。
This commit is contained in:
1 parent
fce5a84dd4
commit
24a9683c43
27 files changed
+803
-23
No files matched your search
@@ -21,6 +21,7 @@ import (
|
||||
//go:embed migrations/sqlite/0017_deployment_transactions.sql migrations/mysql/0017_deployment_transactions.sql migrations/postgres/0017_deployment_transactions.sql
|
||||
//go:embed migrations/sqlite/0018_recovery_evidence.sql migrations/mysql/0018_recovery_evidence.sql migrations/postgres/0018_recovery_evidence.sql migrations/sqlite/0019_password_auth_only.sql migrations/mysql/0019_password_auth_only.sql migrations/postgres/0019_password_auth_only.sql
|
||||
//go:embed migrations/sqlite/0020_task_deployment_reports.sql migrations/mysql/0020_task_deployment_reports.sql migrations/postgres/0020_task_deployment_reports.sql
|
||||
//go:embed migrations/sqlite/0021_task_validation_results.sql migrations/mysql/0021_task_validation_results.sql migrations/postgres/0021_task_validation_results.sql
|
||||
var migrationFiles embed.FS
|
||||
|
||||
func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
@@ -45,7 +46,7 @@ func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const latestMigrationVersion = 20
|
||||
const latestMigrationVersion = 21
|
||||
|
||||
// currentMigrationVersion 在执行业务迁移前拒绝新版数据库及不连续的迁移历史。
|
||||
func currentMigrationVersion(ctx context.Context, db *sql.DB) (int, error) {
|
||||
@@ -85,7 +86,7 @@ func applyMigration(ctx context.Context, db *sql.DB, driver string, version int)
|
||||
return applySQLiteTaskMigration(ctx, db, statements, version)
|
||||
}
|
||||
if driver == "mysql" {
|
||||
if (version >= 15 && version <= 17) || version == 20 {
|
||||
if (version >= 15 && version <= 17) || version == 20 || version == 21 {
|
||||
return applyMySQLDeploymentMigration(ctx, db, version, statements)
|
||||
}
|
||||
if version == 14 {
|
||||
@@ -240,6 +241,8 @@ func migrationName(version int) string {
|
||||
return "password_auth_only"
|
||||
case 20:
|
||||
return "task_deployment_reports"
|
||||
case 21:
|
||||
return "task_validation_results"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE task_validation_results (
|
||||
task_id VARCHAR(36) NOT NULL,
|
||||
attempt_id VARCHAR(36) NOT NULL,
|
||||
attempt_number INT NOT NULL,
|
||||
validation_json MEDIUMTEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (task_id, attempt_id)
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE task_validation_results (
|
||||
task_id TEXT NOT NULL,
|
||||
attempt_id TEXT NOT NULL,
|
||||
attempt_number INTEGER NOT NULL,
|
||||
validation_json TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (task_id, attempt_id)
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE task_validation_results (
|
||||
task_id TEXT NOT NULL,
|
||||
attempt_id TEXT NOT NULL,
|
||||
attempt_number INTEGER NOT NULL,
|
||||
validation_json TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (task_id, attempt_id)
|
||||
);
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMySQLDeploymentShapeDefinitions(t *testing.T) {
|
||||
for _, version := range []int{15, 16, 17, 20} {
|
||||
for _, version := range []int{15, 16, 17, 20, 21} {
|
||||
statements := mysqlDeploymentStatements(t, version)
|
||||
shape, err := parseMySQLDeploymentShape(statements[0])
|
||||
if err != nil || len(shape.Columns) == 0 || len(shape.Indexes) == 0 {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMySQLRealTaskValidationMigrationRecovery(t *testing.T) {
|
||||
f := startRealMySQL(t)
|
||||
baseline := f.database(t)
|
||||
if err := Migrate(t.Context(), baseline.DB, "mysql"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expectedSchema := mysqlSchemaSnapshot(t, baseline.DB)
|
||||
const validation = `{"domains":["example.test"],"fingerprint_sha256":"retained-validation"}`
|
||||
for _, boundary := range []string{"before_create", "after_create", "with_validation"} {
|
||||
t.Run(boundary, func(t *testing.T) {
|
||||
db := f.database(t)
|
||||
mysqlPrepareVersion(t, db.DB, 20)
|
||||
if boundary != "before_create" {
|
||||
mysqlDeploymentExec(t, db.DB, mysqlDeploymentStatements(t, 21)[0])
|
||||
}
|
||||
if boundary == "with_validation" {
|
||||
if _, err := db.DB.ExecContext(t.Context(), `INSERT INTO task_validation_results
|
||||
(task_id, attempt_id, attempt_number, validation_json) VALUES ('validation-task', 'validation-attempt', 1, ?)`, validation); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
mysqlAssertUpgrade(t, db.DB, expectedSchema)
|
||||
if boundary == "with_validation" {
|
||||
var stored string
|
||||
if err := db.DB.QueryRowContext(t.Context(), `SELECT validation_json FROM task_validation_results
|
||||
WHERE task_id = 'validation-task' AND attempt_id = 'validation-attempt'`).Scan(&stored); err != nil || stored != validation {
|
||||
t.Fatalf("恢复迁移后校验详情被改写:%v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, invalid := range []struct{ name, statement string }{
|
||||
{"short_result", "ALTER TABLE task_validation_results MODIFY COLUMN validation_json TEXT NOT NULL"},
|
||||
{"wrong_primary_order", "ALTER TABLE task_validation_results DROP PRIMARY KEY, ADD PRIMARY KEY (attempt_id, task_id)"},
|
||||
{"nullable_attempt", "ALTER TABLE task_validation_results MODIFY COLUMN attempt_number INT NULL"},
|
||||
{"wrong_engine", "ALTER TABLE task_validation_results ENGINE=MyISAM"},
|
||||
{"extra_column", "ALTER TABLE task_validation_results ADD COLUMN unexpected INT NOT NULL DEFAULT 0"},
|
||||
} {
|
||||
t.Run(invalid.name, func(t *testing.T) {
|
||||
db := f.database(t)
|
||||
mysqlPrepareVersion(t, db.DB, 20)
|
||||
mysqlDeploymentExec(t, db.DB, mysqlDeploymentStatements(t, 21)[0])
|
||||
if _, err := db.DB.ExecContext(t.Context(), `INSERT INTO task_validation_results
|
||||
(task_id, attempt_id, attempt_number, validation_json) VALUES ('kept-task', 'kept-attempt', 1, ?)`, validation); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mysqlDeploymentExec(t, db.DB, invalid.statement)
|
||||
before := fmt.Sprint(mysqlSchemaSnapshot(t, db.DB))
|
||||
assertMySQLDeploymentMigrationRejected(t, db.DB, 20)
|
||||
if after := fmt.Sprint(mysqlSchemaSnapshot(t, db.DB)); after != before {
|
||||
t.Fatal("校验结果表冲突不得被自动覆盖或修复")
|
||||
}
|
||||
var stored string
|
||||
if err := db.DB.QueryRowContext(t.Context(), `SELECT validation_json FROM task_validation_results
|
||||
WHERE task_id = 'kept-task' AND attempt_id = 'kept-attempt'`).Scan(&stored); err != nil || stored != validation {
|
||||
t.Fatalf("拒绝迁移时不得修改已有校验结果:%v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user