25 lines
889 B
Python
25 lines
889 B
Python
"""Durable HTTP write idempotency; no changes to the Agent-only idempotency table."""
|
|||
|
|
from alembic import op
|
||
|
|
|
||
|
|
revision = "20260909_api_receipt"
|
||
|
|
down_revision = "20260909_session"
|
||
|
|
branch_labels = None
|
||
|
|
depends_on = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
op.execute("""CREATE TABLE api_request_receipt (
|
||
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
||
|
|
scope_hash CHAR(64) NOT NULL,
|
||
|
|
idempotency_key VARCHAR(128) NOT NULL,
|
||
|
|
request_hash CHAR(64) NOT NULL,
|
||
|
|
response_json JSON NULL,
|
||
|
|
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||
|
|
UNIQUE KEY uk_api_receipt (user_id, scope_hash, idempotency_key)
|
||
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci""")
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
raise RuntimeError("不自动删除幂等回执;请使用前向兼容迁移")
|