"""run.idempotency_key Submitting is a POST, so a client that retries one after a timeout cannot know whether the first attempt landed. A key the caller mints per submission makes the answer a lookup: the same key returns the run it already created. Revision ID: f2c6a8d15e93 Revises: d1f7a3c8b204 Create Date: 2026-08-26 """ import sqlalchemy as sa import sqlmodel.sql.sqltypes from alembic import op # revision identifiers, used by Alembic. revision = "f2c6a8d15e93" down_revision = "d1f7a3c8b204" branch_labels = None depends_on = None def upgrade(): op.add_column( "run", sa.Column( "idempotency_key", sqlmodel.sql.sqltypes.AutoString(length=64), nullable=True, ), ) # Nullable and unique: every run submitted without a key stays NULL, and # both SQLite and Postgres allow as many of those as there are runs. op.create_index("ix_run_idempotency_key", "run", ["idempotency_key"], unique=True) def downgrade(): op.drop_index("ix_run_idempotency_key", table_name="run") op.drop_column("run", "idempotency_key")