feat: strengthen risk controls and review workflows

This commit is contained in:
hectorzhao
2026-07-26 13:08:12 +08:00
parent b461532075
commit 2ce682c3fc
34 changed files with 2167 additions and 390 deletions
@@ -0,0 +1,39 @@
-- Risk thresholds now inherit from global rules and may be overridden per application.
-- Existing maxPhonesPerTask values are intentionally discarded because this environment
-- contains test-only application data and the product owner explicitly declined migration.
ALTER TABLE "RiskRule" ADD COLUMN "applicationId" TEXT;
-- Retain historical rules and hit records for audit, but remove them from the
-- effective rule set and configuration page.
UPDATE "RiskRule"
SET "status" = 'deleted'
WHERE "code" IN (
'DUPLICATE_PHONE_RATIO',
'ILLEGAL_PHONE_RATIO',
'BLACKLIST_HIT_RATIO',
'TEMPLATE_VARIABLE_ANOMALY'
);
UPDATE "RiskRule"
SET "status" = 'deleted'
WHERE "tenantId" IS NOT NULL AND "applicationId" IS NULL;
DROP INDEX IF EXISTS "RiskRule_tenantId_code_key";
DROP INDEX IF EXISTS "RiskRule_tenantId_status_priority_idx";
CREATE UNIQUE INDEX "RiskRule_applicationId_code_key"
ON "RiskRule"("applicationId", "code");
CREATE UNIQUE INDEX "RiskRule_global_code_key"
ON "RiskRule"("code")
WHERE "applicationId" IS NULL AND "status" <> 'deleted';
CREATE INDEX "RiskRule_tenantId_applicationId_status_priority_idx"
ON "RiskRule"("tenantId", "applicationId", "status", "priority");
ALTER TABLE "RiskRule"
ADD CONSTRAINT "RiskRule_applicationId_fkey"
FOREIGN KEY ("applicationId") REFERENCES "SmsApplication"("id")
ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "SmsApplication" DROP COLUMN "maxPhonesPerTask";