forked from mtusi2026/mtusi2026lab4
Carry source f591fa64e525679a31c9db7f942d36c789e1a12f forward from 72a1e57. Preserve lab4 attachment transactions, reconciliation locks, quarantine, and existing schema data through verified legacy adoption. Keep report and evidence work in progress untouched.
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "0002_idempotency_keys"
|
|
down_revision = "0001_init"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"idempotency_keys",
|
|
sa.Column("chat_id", sa.Uuid(), nullable=False),
|
|
sa.Column("user_id", sa.Uuid(), nullable=False),
|
|
sa.Column("key", sa.Text(), nullable=False),
|
|
sa.Column("fingerprint", sa.LargeBinary(), nullable=False),
|
|
sa.Column("message_id", sa.Uuid(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.CheckConstraint("key ~ '^[A-Za-z0-9._:-]{1,128}$'", name="idempotency_keys_key_check"),
|
|
sa.CheckConstraint(
|
|
"octet_length(fingerprint) = 32", name="idempotency_keys_fingerprint_check"
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["chat_id", "user_id"],
|
|
["chat_members.chat_id", "chat_members.user_id"],
|
|
),
|
|
sa.ForeignKeyConstraint(["message_id"], ["messages.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("chat_id", "user_id", "key"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
raise RuntimeError("Downgrade would delete application data")
|