保存 DNS 多账户数据层与实库故障夹具修复前检查点
基础模型和迁移已完成;增量竞态暴露 MySQL 审计故障注入权限问题,后续修复,不代表完整功能或验收通过。
This commit is contained in:
1 parent
26b8c3c5c0
commit
02e039984a
19 files changed
+1000
-11
No files matched your search
@@ -0,0 +1,164 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/config"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/testsupport/mysqltest"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/testsupport/postgrestest"
|
||||
)
|
||||
|
||||
func TestSQLiteDNSAccountProjectGuards(t *testing.T) {
|
||||
for _, foreignKeys := range []int{0, 1} {
|
||||
for _, recursive := range []int{0, 1} {
|
||||
t.Run(fmt.Sprintf("foreign_keys_%d_recursive_%d", foreignKeys, recursive), func(t *testing.T) {
|
||||
cfg := sqliteBusinessUpgradeConfig(t)
|
||||
cfg.MaxOpenConns, cfg.MaxIdleConns = 1, 1
|
||||
db, err := Open(t.Context(), cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
for _, statement := range []string{fmt.Sprintf("PRAGMA foreign_keys=%d", foreignKeys), fmt.Sprintf("PRAGMA recursive_triggers=%d", recursive)} {
|
||||
if _, err := db.DB.ExecContext(t.Context(), statement); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := Migrate(t.Context(), db.DB, "sqlite"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.DB.ExecContext(t.Context(), `INSERT INTO projects (id,name,description) VALUES ('dns-only','账户项目','')`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.DB.ExecContext(t.Context(), `INSERT INTO dns_accounts VALUES ('kept','账户','dns-only','retired-owner','aliyun','secret://dns/kept','active','unverified',1,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, statement := range []string{
|
||||
`INSERT INTO dns_accounts VALUES ('orphan','账户','missing','owner','aliyun','secret://dns/orphan','active','unverified',1,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)`,
|
||||
`UPDATE dns_accounts SET project_id='missing' WHERE id='kept'`,
|
||||
`DELETE FROM projects WHERE id='dns-only'`,
|
||||
`UPDATE projects SET id='moved' WHERE id='dns-only'`,
|
||||
`INSERT OR REPLACE INTO projects (id,name,description) VALUES ('dns-only','覆盖','')`,
|
||||
} {
|
||||
if _, err := db.DB.ExecContext(t.Context(), statement); err == nil {
|
||||
t.Fatal("项目保护没有拒绝破坏引用的操作")
|
||||
}
|
||||
}
|
||||
for name, want := range map[string]int{"foreign_keys": foreignKeys, "recursive_triggers": recursive} {
|
||||
var value int
|
||||
if err := db.DB.QueryRowContext(t.Context(), "PRAGMA "+name).Scan(&value); err != nil || value != want {
|
||||
t.Fatal("迁移改变用户连接参数", name, value, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDNSAccountMigration(t *testing.T) {
|
||||
for _, driver := range []string{"sqlite", "mysql", "postgres"} {
|
||||
t.Run(driver, func(t *testing.T) {
|
||||
var cfg config.DatabaseConfig
|
||||
switch driver {
|
||||
case "sqlite":
|
||||
cfg = sqliteBusinessUpgradeConfig(t)
|
||||
case "mysql":
|
||||
cfg = mysqltest.New(t).Database(t)
|
||||
case "postgres":
|
||||
cfg = postgrestest.New(t).Database(t)
|
||||
}
|
||||
db, err := Open(t.Context(), cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
if _, err := db.DB.ExecContext(t.Context(), migrationTableSQL(driver)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for version := 1; version <= 26; version++ {
|
||||
if err := applyMigration(t.Context(), db.DB, driver, version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := db.DB.ExecContext(t.Context(), `INSERT INTO domains (id,name,certificate_type,sans_json,status,challenge_type)
|
||||
VALUES ('legacy-dns','legacy.example.com','single','[]','valid','http-01')`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Migrate(t.Context(), db.DB, driver); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
query := `INSERT INTO dns_accounts (id,name,project_id,owner_user_id,provider,credential_ref,status,verification_state,revision,created_at,updated_at)
|
||||
VALUES ('kept','保留账户','default','missing-owner','aliyun','secret://dns/kept','disabled','unverified',9,?,?)`
|
||||
if driver == "postgres" {
|
||||
query = `INSERT INTO dns_accounts (id,name,project_id,owner_user_id,provider,credential_ref,status,verification_state,revision,created_at,updated_at)
|
||||
VALUES ('kept','保留账户','default','missing-owner','aliyun','secret://dns/kept','disabled','unverified',9,$1,$2)`
|
||||
}
|
||||
if _, err := db.DB.ExecContext(t.Context(), query, time.Now().UTC(), time.Now().UTC()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Migrate(t.Context(), db.DB, driver); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var status, challenge string
|
||||
if err := db.DB.QueryRowContext(t.Context(), `SELECT status,challenge_type FROM domains WHERE id='legacy-dns'`).Scan(&status, &challenge); err != nil || status != "valid" || challenge != "http-01" {
|
||||
t.Fatal("升级改变历史域名", err)
|
||||
}
|
||||
var revision int
|
||||
if err := db.DB.QueryRowContext(t.Context(), `SELECT status,revision FROM dns_accounts WHERE id='kept'`).Scan(&status, &revision); err != nil || status != "disabled" || revision != 9 {
|
||||
t.Fatal("重入覆盖已有账户", err)
|
||||
}
|
||||
if _, err := db.DB.ExecContext(t.Context(), `UPDATE dns_accounts SET project_id='missing' WHERE id='kept'`); err == nil {
|
||||
t.Fatal("项目外键没有生效")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMySQLDNSAccountInterruptedMigration(t *testing.T) {
|
||||
f := startRealMySQL(t)
|
||||
for _, boundary := range []string{"before_create", "after_create", "after_constraint", "with_record", "bad_column", "bad_index", "bad_foreign_key", "bad_collation"} {
|
||||
t.Run(boundary, func(t *testing.T) {
|
||||
db := f.database(t)
|
||||
mysqlPrepareVersion(t, db.DB, 26)
|
||||
statements := mysqlDeploymentStatements(t, 27)
|
||||
if boundary != "before_create" {
|
||||
mysqlDeploymentExec(t, db.DB, statements[0])
|
||||
}
|
||||
if boundary == "after_constraint" || boundary == "with_record" {
|
||||
mysqlDeploymentExec(t, db.DB, statements[1])
|
||||
}
|
||||
conflict := true
|
||||
switch boundary {
|
||||
case "bad_column":
|
||||
mysqlDeploymentExec(t, db.DB, "ALTER TABLE dns_accounts MODIFY COLUMN revision INT NULL")
|
||||
case "bad_index":
|
||||
mysqlDeploymentExec(t, db.DB, "ALTER TABLE dns_accounts DROP INDEX uq_dns_accounts_credential")
|
||||
case "bad_foreign_key":
|
||||
mysqlDeploymentExec(t, db.DB, "ALTER TABLE dns_accounts ADD CONSTRAINT fk_dns_accounts_project FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE")
|
||||
case "bad_collation":
|
||||
mysqlDeploymentExec(t, db.DB, "ALTER TABLE dns_accounts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
|
||||
default:
|
||||
conflict = false
|
||||
}
|
||||
if boundary == "with_record" {
|
||||
mysqlDeploymentExec(t, db.DB, `INSERT INTO dns_accounts VALUES ('kept','保留账户','default','owner','aliyun','secret://dns/kept','disabled','unverified',7,NOW(),NOW())`)
|
||||
}
|
||||
err := Migrate(t.Context(), db.DB, "mysql")
|
||||
if (err != nil) != conflict {
|
||||
t.Fatal("中断恢复或冲突拒绝错误", err)
|
||||
}
|
||||
version, err := currentMigrationVersion(t.Context(), db.DB)
|
||||
if err != nil || (conflict && version != 26) || (!conflict && version != latestMigrationVersion) {
|
||||
t.Fatal("迁移版本错误", version, err)
|
||||
}
|
||||
if boundary == "with_record" {
|
||||
var revision int
|
||||
if err := db.DB.QueryRowContext(t.Context(), `SELECT revision FROM dns_accounts WHERE id='kept'`).Scan(&revision); err != nil || revision != 7 {
|
||||
t.Fatal("中断恢复丢失原有账户", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
//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
|
||||
//go:embed migrations/sqlite/0026_domain_challenge.sql migrations/mysql/0026_domain_challenge.sql migrations/postgres/0026_domain_challenge.sql
|
||||
//go:embed migrations/sqlite/0027_dns_accounts.sql migrations/mysql/0027_dns_accounts.sql migrations/postgres/0027_dns_accounts.sql
|
||||
var migrationFiles embed.FS
|
||||
|
||||
func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
@@ -51,7 +52,7 @@ func Migrate(ctx context.Context, db *sql.DB, driver string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const latestMigrationVersion = 26
|
||||
const latestMigrationVersion = 27
|
||||
|
||||
// currentMigrationVersion 在执行业务迁移前拒绝新版数据库及不连续的迁移历史。
|
||||
func currentMigrationVersion(ctx context.Context, db *sql.DB) (int, error) {
|
||||
@@ -91,6 +92,9 @@ func applyMigration(ctx context.Context, db *sql.DB, driver string, version int)
|
||||
return applySQLiteTaskMigration(ctx, db, statements, version)
|
||||
}
|
||||
if driver == "mysql" {
|
||||
if version == 27 {
|
||||
return applyMySQLDNSAccountMigration(ctx, db, version, statements)
|
||||
}
|
||||
if (version >= 15 && version <= 17) || (version >= 20 && version <= 24) {
|
||||
return applyMySQLDeploymentMigration(ctx, db, version, statements)
|
||||
}
|
||||
@@ -171,6 +175,12 @@ func applyMigration(ctx context.Context, db *sql.DB, driver string, version int)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if driver == "sqlite" && version == 27 {
|
||||
if err := installSQLiteDNSAccountConstraints(ctx, tx); err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
migrationVersionInsert := "INSERT INTO schema_migrations (version) VALUES (?)"
|
||||
if driver == "postgres" {
|
||||
migrationVersionInsert = "INSERT INTO schema_migrations (version) VALUES ($1)"
|
||||
@@ -274,6 +284,8 @@ func migrationName(version int) string {
|
||||
return "recovery_reconciliation"
|
||||
case 26:
|
||||
return "domain_challenge"
|
||||
case 27:
|
||||
return "dns_accounts"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE dns_accounts (
|
||||
id VARCHAR(36) NOT NULL PRIMARY KEY,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
project_id VARCHAR(36) NOT NULL,
|
||||
owner_user_id VARCHAR(36) NOT NULL,
|
||||
provider VARCHAR(36) NOT NULL,
|
||||
credential_ref VARCHAR(255) NOT NULL,
|
||||
status VARCHAR(16) NOT NULL,
|
||||
verification_state VARCHAR(16) NOT NULL,
|
||||
revision INT NOT NULL,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
UNIQUE KEY uq_dns_accounts_credential (credential_ref),
|
||||
INDEX idx_dns_accounts_project (project_id, id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
ALTER TABLE dns_accounts ADD CONSTRAINT fk_dns_accounts_project FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE RESTRICT;
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE dns_accounts (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE RESTRICT,
|
||||
owner_user_id TEXT NOT NULL,
|
||||
provider TEXT NOT NULL,
|
||||
credential_ref TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
verification_state TEXT NOT NULL,
|
||||
revision INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX uq_dns_accounts_credential ON dns_accounts (credential_ref);
|
||||
CREATE INDEX idx_dns_accounts_project ON dns_accounts (project_id, id);
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE dns_accounts (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE RESTRICT,
|
||||
owner_user_id TEXT NOT NULL,
|
||||
provider TEXT NOT NULL,
|
||||
credential_ref TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
verification_state TEXT NOT NULL,
|
||||
revision INTEGER NOT NULL,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX uq_dns_accounts_credential ON dns_accounts (credential_ref);
|
||||
CREATE INDEX idx_dns_accounts_project ON dns_accounts (project_id, id);
|
||||
@@ -50,9 +50,10 @@ type mysqlDeploymentColumn struct {
|
||||
}
|
||||
|
||||
type mysqlDeploymentShape struct {
|
||||
Table string
|
||||
Columns []mysqlDeploymentColumn
|
||||
Indexes []string
|
||||
Table string
|
||||
Collation string
|
||||
Columns []mysqlDeploymentColumn
|
||||
Indexes []string
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -70,7 +71,13 @@ func parseMySQLDeploymentShape(statement string) (mysqlDeploymentShape, error) {
|
||||
return shape, fmt.Errorf("部署迁移表定义不完整")
|
||||
}
|
||||
match := mysqlDeploymentTablePattern.FindStringSubmatch(strings.TrimSpace(lines[0]))
|
||||
if len(match) != 2 || strings.TrimSpace(lines[len(lines)-1]) != ")" {
|
||||
closing := strings.TrimSpace(lines[len(lines)-1])
|
||||
if closing == ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" {
|
||||
shape.Collation = "utf8mb4_bin"
|
||||
} else if closing != ")" {
|
||||
return shape, fmt.Errorf("迁移表结尾定义不受支持")
|
||||
}
|
||||
if len(match) != 2 {
|
||||
return shape, fmt.Errorf("部署迁移表定义不受支持")
|
||||
}
|
||||
shape.Table = match[1]
|
||||
@@ -108,7 +115,11 @@ func validateMySQLDeploymentShape(ctx context.Context, db *sql.DB, expected mysq
|
||||
WHERE t.table_schema = DATABASE() AND t.table_name = ?`, expected.Table).Scan(&tableCollation, &schemaCollation); err != nil {
|
||||
return err
|
||||
}
|
||||
if tableCollation != schemaCollation {
|
||||
expectedCollation := schemaCollation
|
||||
if expected.Collation != "" {
|
||||
expectedCollation = expected.Collation
|
||||
}
|
||||
if tableCollation != expectedCollation {
|
||||
return fmt.Errorf("部署迁移表排序规则与数据库默认定义不匹配:%s", expected.Table)
|
||||
}
|
||||
var engine, tableType string
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMySQLDeploymentShapeDefinitions(t *testing.T) {
|
||||
for _, version := range []int{15, 16, 17, 20, 21, 22, 23, 24} {
|
||||
for _, version := range []int{15, 16, 17, 20, 21, 22, 23, 24, 27} {
|
||||
statements := mysqlDeploymentStatements(t, version)
|
||||
shape, err := parseMySQLDeploymentShape(statements[0])
|
||||
if err != nil || len(shape.Columns) == 0 || len(shape.Indexes) == 0 {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// MySQL 的建表和外键各自提交;重入时逐项比对,结构冲突不覆盖历史数据。
|
||||
func applyMySQLDNSAccountMigration(ctx context.Context, db *sql.DB, version int, statements []string) error {
|
||||
if len(statements) != 2 {
|
||||
return fmt.Errorf("DNS 账户迁移语句不完整")
|
||||
}
|
||||
shape, err := parseMySQLDeploymentShape(statements[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := db.ExecContext(ctx, strings.Replace(statements[0], "CREATE TABLE ", "CREATE TABLE IF NOT EXISTS ", 1)); err != nil {
|
||||
return fmt.Errorf("创建 DNS 账户表失败:%w", err)
|
||||
}
|
||||
if err := validateMySQLDeploymentShape(ctx, db, shape); err != nil {
|
||||
return err
|
||||
}
|
||||
// 先检查已有外键,避免把同名但不同语义的外键当作迁移成功。
|
||||
count, err := validateMySQLDNSAccountForeignKey(ctx, db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
if _, err := db.ExecContext(ctx, statements[1]); err != nil {
|
||||
return fmt.Errorf("创建 DNS 账户项目约束失败:%w", err)
|
||||
}
|
||||
}
|
||||
if count, err = validateMySQLDNSAccountForeignKey(ctx, db); err != nil || count != 1 {
|
||||
return fmt.Errorf("DNS 账户项目约束校验失败:%v", err)
|
||||
}
|
||||
if _, err := db.ExecContext(ctx, "INSERT INTO schema_migrations (version) VALUES (?)", version); err != nil {
|
||||
return fmt.Errorf("记录 DNS 账户迁移版本失败:%w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateMySQLDNSAccountForeignKey(ctx context.Context, db *sql.DB) (int, error) {
|
||||
rows, err := db.QueryContext(ctx, `SELECT r.constraint_name, r.delete_rule, r.update_rule,
|
||||
k.column_name, k.referenced_table_schema, k.referenced_table_name, k.referenced_column_name,
|
||||
k.ordinal_position, DATABASE()
|
||||
FROM information_schema.referential_constraints r
|
||||
JOIN information_schema.key_column_usage k ON k.constraint_schema = r.constraint_schema
|
||||
AND k.table_name = r.table_name AND k.constraint_name = r.constraint_name
|
||||
WHERE r.constraint_schema = DATABASE() AND r.table_name = 'dns_accounts'`)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
count := 0
|
||||
for rows.Next() {
|
||||
var name, onDelete, onUpdate, column, schema, table, target, currentSchema string
|
||||
var position int
|
||||
if err := rows.Scan(&name, &onDelete, &onUpdate, &column, &schema, &table, &target, &position, ¤tSchema); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
count++
|
||||
if count != 1 || name != "fk_dns_accounts_project" || onDelete != "RESTRICT" || (onUpdate != "RESTRICT" && onUpdate != "NO ACTION") || column != "project_id" || schema != currentSchema || table != "projects" || target != "id" || position != 1 {
|
||||
return 0, fmt.Errorf("DNS 账户项目外键与预期不一致,拒绝记录迁移版本")
|
||||
}
|
||||
}
|
||||
return count, rows.Err()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 与已有资源约束一致,不依赖连接的外键开关,不修改用户的连接参数。
|
||||
func installSQLiteDNSAccountConstraints(ctx context.Context, tx *sql.Tx) error {
|
||||
statements := []string{
|
||||
`CREATE TRIGGER scert_dns_accounts_project_insert BEFORE INSERT ON dns_accounts
|
||||
WHEN NOT EXISTS (SELECT 1 FROM projects WHERE id = NEW.project_id)
|
||||
BEGIN SELECT RAISE(ABORT, 'DNS 账户所属项目不存在'); END`,
|
||||
`CREATE TRIGGER scert_dns_accounts_project_update BEFORE UPDATE OF project_id ON dns_accounts
|
||||
WHEN NOT EXISTS (SELECT 1 FROM projects WHERE id = NEW.project_id)
|
||||
BEGIN SELECT RAISE(ABORT, 'DNS 账户所属项目不存在'); END`,
|
||||
`CREATE TRIGGER scert_dns_accounts_project_delete BEFORE DELETE ON projects
|
||||
WHEN EXISTS (SELECT 1 FROM dns_accounts WHERE project_id = OLD.id)
|
||||
BEGIN SELECT RAISE(ABORT, '项目仍有 DNS 账户,不能删除'); END`,
|
||||
`CREATE TRIGGER scert_dns_accounts_project_rekey BEFORE UPDATE OF id ON projects
|
||||
WHEN NEW.id <> OLD.id AND EXISTS (SELECT 1 FROM dns_accounts WHERE project_id = OLD.id)
|
||||
BEGIN SELECT RAISE(ABORT, '项目仍有 DNS 账户,不能更换标识'); END`,
|
||||
`CREATE TRIGGER scert_dns_accounts_project_replace BEFORE INSERT ON projects
|
||||
WHEN EXISTS (SELECT 1 FROM dns_accounts WHERE project_id = NEW.id)
|
||||
BEGIN SELECT RAISE(ABORT, '项目仍有 DNS 账户,不能替换'); END`,
|
||||
}
|
||||
for _, statement := range statements {
|
||||
if _, err := tx.ExecContext(ctx, statement); err != nil {
|
||||
return fmt.Errorf("安装 DNS 账户项目保护失败:%w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user