开发前检查点:增加部署事务持久化骨架
为后续接入部署事务恢复流程保留数据库迁移、事务模型和仓储实现检查点。
This commit is contained in:
1 parent
4683a436f0
commit
3a0e1d8769
6 files changed
+369
-1
No files matched your search
@@ -18,6 +18,7 @@ import (
|
||||
//go:embed migrations/sqlite/0014_project_members.sql migrations/mysql/0014_project_members.sql migrations/postgres/0014_project_members.sql
|
||||
//go:embed migrations/sqlite/0015_task_idempotency.sql migrations/mysql/0015_task_idempotency.sql migrations/postgres/0015_task_idempotency.sql
|
||||
//go:embed migrations/sqlite/0016_task_deployment_results.sql migrations/mysql/0016_task_deployment_results.sql migrations/postgres/0016_task_deployment_results.sql
|
||||
//go:embed migrations/sqlite/0017_deployment_transactions.sql migrations/mysql/0017_deployment_transactions.sql migrations/postgres/0017_deployment_transactions.sql
|
||||
var migrationFiles embed.FS
|
||||
|
||||
func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
@@ -42,7 +43,7 @@ func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const latestMigrationVersion = 16
|
||||
const latestMigrationVersion = 17
|
||||
|
||||
// currentMigrationVersion 在执行业务迁移前拒绝新版数据库及不连续的迁移历史。
|
||||
func currentMigrationVersion(ctx context.Context, db *sql.DB) (int, error) {
|
||||
@@ -226,6 +227,8 @@ func migrationName(version int) string {
|
||||
return "task_idempotency"
|
||||
case 16:
|
||||
return "task_deployment_results"
|
||||
case 17:
|
||||
return "deployment_transactions"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE deployment_transactions (
|
||||
id VARCHAR(128) NOT NULL PRIMARY KEY,
|
||||
task_id VARCHAR(36) NOT NULL,
|
||||
attempt_id VARCHAR(36) NOT NULL,
|
||||
attempt_number INT NOT NULL,
|
||||
result_index INT NOT NULL,
|
||||
server_id VARCHAR(36) NOT NULL,
|
||||
server_name VARCHAR(255) NOT NULL,
|
||||
certificate_path TEXT NOT NULL,
|
||||
certificate_chain_path TEXT NOT NULL,
|
||||
private_key_path TEXT NOT NULL,
|
||||
temporary_paths_json TEXT NOT NULL,
|
||||
installed_paths_json TEXT NOT NULL,
|
||||
backups_json TEXT NOT NULL,
|
||||
lock_paths_json TEXT NOT NULL,
|
||||
reload_attempted INT NOT NULL DEFAULT 0,
|
||||
phase VARCHAR(64) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_deployment_transactions_status (status, updated_at),
|
||||
INDEX idx_deployment_transactions_task_id (task_id)
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE deployment_transactions (
|
||||
id VARCHAR(128) NOT NULL PRIMARY KEY,
|
||||
task_id VARCHAR(36) NOT NULL,
|
||||
attempt_id VARCHAR(36) NOT NULL,
|
||||
attempt_number INTEGER NOT NULL,
|
||||
result_index INTEGER NOT NULL,
|
||||
server_id VARCHAR(36) NOT NULL,
|
||||
server_name VARCHAR(255) NOT NULL,
|
||||
certificate_path TEXT NOT NULL,
|
||||
certificate_chain_path TEXT NOT NULL,
|
||||
private_key_path TEXT NOT NULL,
|
||||
temporary_paths_json TEXT NOT NULL,
|
||||
installed_paths_json TEXT NOT NULL,
|
||||
backups_json TEXT NOT NULL,
|
||||
lock_paths_json TEXT NOT NULL,
|
||||
reload_attempted INTEGER NOT NULL DEFAULT 0,
|
||||
phase VARCHAR(64) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_deployment_transactions_status ON deployment_transactions(status, updated_at);
|
||||
CREATE INDEX idx_deployment_transactions_task_id ON deployment_transactions(task_id);
|
||||
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE deployment_transactions (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
task_id TEXT NOT NULL,
|
||||
attempt_id TEXT NOT NULL,
|
||||
attempt_number INTEGER NOT NULL,
|
||||
result_index INTEGER NOT NULL,
|
||||
server_id TEXT NOT NULL,
|
||||
server_name TEXT NOT NULL,
|
||||
certificate_path TEXT NOT NULL,
|
||||
certificate_chain_path TEXT NOT NULL,
|
||||
private_key_path TEXT NOT NULL,
|
||||
temporary_paths_json TEXT NOT NULL,
|
||||
installed_paths_json TEXT NOT NULL,
|
||||
backups_json TEXT NOT NULL,
|
||||
lock_paths_json TEXT NOT NULL,
|
||||
reload_attempted INTEGER NOT NULL DEFAULT 0,
|
||||
phase TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_deployment_transactions_status ON deployment_transactions(status, updated_at);
|
||||
CREATE INDEX idx_deployment_transactions_task_id ON deployment_transactions(task_id);
|
||||
Reference in new issue
Block a user