fix: keep setup available without active DingTalk app

This commit is contained in:
姚章浩
2026-08-13 13:55:25 +08:00
parent b207ee4089
commit 44d9398c78
4 changed files with 181 additions and 7 deletions
+6 -3
View File
@@ -237,14 +237,17 @@ func (r *SettingsRepository) PrepareDingTalkRuntimeStart(ctx context.Context, te
return true, tx.Commit(ctx)
case "runtime_starting":
var oldID string
if err = tx.QueryRow(ctx, `SELECT id FROM system_config_revisions WHERE tenant_key=$1 AND kind='dingtalk_app' AND state='retired' AND validation_status='ok' ORDER BY revision DESC LIMIT 1 FOR UPDATE`, tenant).Scan(&oldID); err != nil {
err = tx.QueryRow(ctx, `SELECT id FROM system_config_revisions WHERE tenant_key=$1 AND kind='dingtalk_app' AND state='retired' AND validation_status='ok' ORDER BY revision DESC LIMIT 1 FOR UPDATE`, tenant).Scan(&oldID)
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
return false, err
}
if _, err = tx.Exec(ctx, `UPDATE system_config_revisions SET state='failed',validation_status='failed',validation_code='runtime_start_failed' WHERE id=$1`, activeID); err != nil {
return false, err
}
if _, err = tx.Exec(ctx, `UPDATE system_config_revisions SET state='active',validation_code='rollback_restored',activated_at=NOW() WHERE id=$1`, oldID); err != nil {
return false, err
if oldID != "" {
if _, err = tx.Exec(ctx, `UPDATE system_config_revisions SET state='active',validation_code='rollback_restored',activated_at=NOW() WHERE id=$1`, oldID); err != nil {
return false, err
}
}
return false, tx.Commit(ctx)
default: