完善证书管理与初始化流程
This commit is contained in:
1 parent
07636abe44
commit
c74372284a
84 files changed
+10151
-3502
No files matched your search
@@ -25,7 +25,7 @@ func TestOpenAndMigrateSQLite(t *testing.T) {
|
||||
if err := db.DB.QueryRow("SELECT COUNT(*) FROM schema_migrations").Scan(&count); err != nil {
|
||||
t.Fatalf("读取迁移版本失败:%v", err)
|
||||
}
|
||||
if count != 2 {
|
||||
if count != 3 {
|
||||
t.Fatalf("迁移版本数量错误:%d", count)
|
||||
}
|
||||
var autoRenew bool
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed migrations/sqlite/0001_initial.sql migrations/sqlite/0002_domain_options.sql migrations/mysql/0001_initial.sql migrations/mysql/0002_domain_options.sql
|
||||
//go:embed migrations/sqlite/0001_initial.sql migrations/sqlite/0002_domain_options.sql migrations/sqlite/0003_deployment.sql migrations/mysql/0001_initial.sql migrations/mysql/0002_domain_options.sql migrations/mysql/0003_deployment.sql
|
||||
var migrationFiles embed.FS
|
||||
|
||||
func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
@@ -37,7 +37,7 @@ func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const latestMigrationVersion = 2
|
||||
const latestMigrationVersion = 3
|
||||
|
||||
func applyMigration(ctx context.Context, db *sql.DB, driver string, version int) error {
|
||||
path := fmt.Sprintf("migrations/%s/%04d_%s.sql", driver, version, migrationName(version))
|
||||
@@ -83,6 +83,8 @@ func migrationName(version int) string {
|
||||
return "initial"
|
||||
case 2:
|
||||
return "domain_options"
|
||||
case 3:
|
||||
return "deployment"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE IF NOT EXISTS servers (
|
||||
id VARCHAR(36) NOT NULL PRIMARY KEY,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
address VARCHAR(253) NOT NULL,
|
||||
port INT NOT NULL,
|
||||
username VARCHAR(128) NOT NULL,
|
||||
private_key_ref VARCHAR(255) NOT NULL,
|
||||
host_key_fingerprint VARCHAR(255) NOT NULL,
|
||||
certificate_path VARCHAR(1024) NOT NULL,
|
||||
private_key_path VARCHAR(1024) NOT NULL,
|
||||
certificate_chain_path VARCHAR(1024) NOT NULL,
|
||||
web_server VARCHAR(32) NOT NULL,
|
||||
reload_command_json TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_servers_name (name)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS domain_servers (
|
||||
domain_id VARCHAR(36) NOT NULL,
|
||||
server_id VARCHAR(36) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (domain_id, server_id),
|
||||
INDEX idx_domain_servers_server_id (server_id)
|
||||
);
|
||||
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE IF NOT EXISTS servers (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
port INTEGER NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
private_key_ref TEXT NOT NULL,
|
||||
host_key_fingerprint TEXT NOT NULL,
|
||||
certificate_path TEXT NOT NULL,
|
||||
private_key_path TEXT NOT NULL,
|
||||
certificate_chain_path TEXT NOT NULL,
|
||||
web_server TEXT NOT NULL,
|
||||
reload_command_json TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS domain_servers (
|
||||
domain_id TEXT NOT NULL,
|
||||
server_id TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (domain_id, server_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_domain_servers_server_id ON domain_servers(server_id);
|
||||
@@ -52,14 +52,14 @@ func TestSQLiteMigrationIsIdempotentAndCreatesBaseTables(t *testing.T) {
|
||||
if err := db.DB.QueryRow("SELECT COUNT(*) FROM schema_migrations").Scan(&versions); err != nil {
|
||||
t.Fatalf("读取迁移版本失败:%v", err)
|
||||
}
|
||||
if versions != 2 {
|
||||
if versions != 3 {
|
||||
t.Fatalf("重复迁移写入了多条版本记录:%d", versions)
|
||||
}
|
||||
var tables int
|
||||
if err := db.DB.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name IN ('settings', 'domains', 'tasks', 'audit_logs')`).Scan(&tables); err != nil {
|
||||
if err := db.DB.QueryRow(`SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name IN ('settings', 'domains', 'tasks', 'audit_logs', 'servers', 'domain_servers')`).Scan(&tables); err != nil {
|
||||
t.Fatalf("检查基础数据表失败:%v", err)
|
||||
}
|
||||
if tables != 4 {
|
||||
if tables != 6 {
|
||||
t.Fatalf("基础数据表数量不正确:%d", tables)
|
||||
}
|
||||
if err := Migrate(context.Background(), db.DB, "postgres"); err == nil {
|
||||
|
||||
Reference in new issue
Block a user