Files
tokens-reef/backend/migrations/057_add_idempotency_records.sql
Developer da36506b89 fix: resolve P0/P1 code quality issues
P0 fixes:
- ModelError.Is(): use exact matching instead of substring contains()
- shouldClearStickySession: add context param for cancellation/tracing

P1 fixes:
- TODO stubs: return 501 Not Implemented errors
- validateInstanceSignature: deduplicate to shared validateCodeSignature()
- Error messages: standardize to English only
- http.go: remove pseudo if-else with duplicate branches
2026-03-31 11:39:18 +08:00

28 lines
956 B
SQL

-- 幂等记录表:用于关键写接口的请求去重与结果重放
-- 幂等执行:可重复运行
CREATE TABLE IF NOT EXISTS idempotency_records (
id BIGSERIAL PRIMARY KEY,
scope VARCHAR(128) NOT NULL,
idempotency_key_hash VARCHAR(64) NOT NULL,
request_fingerprint VARCHAR(64) NOT NULL,
status VARCHAR(32) NOT NULL,
response_status INTEGER,
response_body TEXT,
error_reason VARCHAR(128),
locked_until TIMESTAMPTZ,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_idempotency_records_scope_key
ON idempotency_records (scope, idempotency_key_hash);
CREATE INDEX IF NOT EXISTS idx_idempotency_records_expires_at
ON idempotency_records (expires_at);
CREATE INDEX IF NOT EXISTS idx_idempotency_records_status_locked_until
ON idempotency_records (status, locked_until);