feat(supply-api): 完成核心模块实现
新增/修改内容: - config: 添加配置管理(config.example.yaml, config.go) - cache: 添加Redis缓存层(redis.go) - domain: 添加invariants不变量验证及测试 - middleware: 添加auth认证和idempotency幂等性中间件及测试 - repository: 添加完整数据访问层(account, package, settlement, idempotency, db) - sql: 添加幂等性表DDL脚本 代码覆盖: - auth middleware实现凭证边界验证 - idempotency middleware实现请求幂等性 - invariants实现业务不变量检查 - repository层实现完整的数据访问逻辑 关联issue: Round-1 R1-ISSUE-006 凭证边界硬门禁
This commit is contained in:
47
supply-api/sql/postgresql/supply_idempotency_record_v1.sql
Normal file
47
supply-api/sql/postgresql/supply_idempotency_record_v1.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
-- Supply Idempotency Record Schema
|
||||
-- Based on: XR-001 (supply_technical_design_enhanced_v1_2026-03-25.md)
|
||||
-- Updated: 2026-03-27
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS supply_idempotency_records (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
operator_id BIGINT NOT NULL,
|
||||
api_path VARCHAR(200) NOT NULL,
|
||||
idempotency_key VARCHAR(128) NOT NULL,
|
||||
request_id VARCHAR(64) NOT NULL,
|
||||
payload_hash CHAR(64) NOT NULL, -- SHA256 of request body
|
||||
response_code INT,
|
||||
response_body JSONB,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'processing'
|
||||
CHECK (status IN ('processing', 'succeeded', 'failed')),
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE (tenant_id, operator_id, api_path, idempotency_key)
|
||||
);
|
||||
|
||||
-- 高频查询索引
|
||||
CREATE INDEX IF NOT EXISTS idx_idempotency_tenant_operator_path_key
|
||||
ON supply_idempotency_records (tenant_id, operator_id, api_path, idempotency_key)
|
||||
WHERE expires_at > CURRENT_TIMESTAMP;
|
||||
|
||||
-- RequestID 反查索引
|
||||
CREATE INDEX IF NOT EXISTS idx_idempotency_request_id
|
||||
ON supply_idempotency_records (request_id);
|
||||
|
||||
-- 过期清理索引
|
||||
CREATE INDEX IF NOT EXISTS idx_idempotency_expires_at
|
||||
ON supply_idempotency_records (expires_at)
|
||||
WHERE status != 'processing';
|
||||
|
||||
-- 状态查询索引
|
||||
CREATE INDEX IF NOT EXISTS idx_idempotency_status_expires
|
||||
ON supply_idempotency_records (status, expires_at);
|
||||
|
||||
COMMENT ON TABLE supply_idempotency_records IS '幂等记录表 - XR-001';
|
||||
COMMENT ON COLUMN supply_idempotency_records.payload_hash IS '请求体SHA256摘要,用于检测异参重放';
|
||||
COMMENT ON COLUMN supply_idempotency_records.expires_at IS '过期时间,默认24小时,提现类72小时';
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user