R56 A1-A6:费用标准管控

这个提交包含在:
2026-04-08 12:47:40 +08:00
父节点 40c3b7632a
当前提交 845558ab17
共修改 25 个文件,包含 2993 行新增和 10 行删除
@@ -0,0 +1,34 @@
CREATE TABLE "expense_standards" (
"id" UUID NOT NULL,
"expense_type_id" UUID NOT NULL,
"name" VARCHAR(100) NOT NULL,
"max_amount" DECIMAL(14,2) NOT NULL,
"per_unit" VARCHAR(20) NOT NULL DEFAULT 'item',
"control_mode" VARCHAR(16) NOT NULL DEFAULT 'warn',
"scope_type" VARCHAR(32) NOT NULL DEFAULT 'global',
"scope_key" UUID,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"note" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" UUID,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_by" UUID,
CONSTRAINT "expense_standards_pkey" PRIMARY KEY ("id")
);
ALTER TABLE "expense_standards"
ADD CONSTRAINT "expense_standards_expense_type_id_fkey"
FOREIGN KEY ("expense_type_id") REFERENCES "expense_types"("id")
ON DELETE RESTRICT ON UPDATE CASCADE;
CREATE INDEX "idx_expense_standards_enabled_type"
ON "expense_standards"("enabled", "expense_type_id");
CREATE UNIQUE INDEX "expense_standards_type_scope_global_ux"
ON "expense_standards"("expense_type_id", "scope_type")
WHERE "scope_key" IS NULL;
CREATE UNIQUE INDEX "expense_standards_type_scope_scoped_ux"
ON "expense_standards"("expense_type_id", "scope_type", "scope_key")
WHERE "scope_key" IS NOT NULL;