forked from mtusi2026/mtusi2026lab3
feat: add idempotency keys database migration
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
"""add idempotency keys
|
||||||
|
|
||||||
|
Revision ID: b7965b0447f4
|
||||||
|
Revises: 44ea9d3b68ac
|
||||||
|
Create Date: 2026-10-28 23:34:43.564839
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'b7965b0447f4'
|
||||||
|
down_revision: Union[str, None] = '44ea9d3b68ac'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('idempotency_keys',
|
||||||
|
sa.Column('id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('user_id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('key', sa.String(length=128), nullable=False),
|
||||||
|
sa.Column('request_hash', sa.String(length=64), nullable=False),
|
||||||
|
sa.Column('response_body', sa.Text(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('user_id', 'key', name='uq_idempotency_user_key')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('idempotency_keys')
|
||||||
|
# ### end Alembic commands ###
|
||||||
Reference in New Issue
Block a user