diff --git a/migrations/env.py b/migrations/env.py index 18b3c06..bd414bc 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -46,6 +46,7 @@ def run_migrations_offline() -> None: target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, + render_as_batch=True, ) with context.begin_transaction(): @@ -66,7 +67,11 @@ def run_migrations_online() -> None: ) with connectable.connect() as connection: - context.configure(connection=connection, target_metadata=target_metadata) + context.configure( + connection=connection, + target_metadata=target_metadata, + render_as_batch=True, + ) with context.begin_transaction(): context.run_migrations() diff --git a/migrations/versions/db0c0dc793f4_add_presets_table.py b/migrations/versions/db0c0dc793f4_add_presets_table.py index e2cc7ae..df60e7d 100644 --- a/migrations/versions/db0c0dc793f4_add_presets_table.py +++ b/migrations/versions/db0c0dc793f4_add_presets_table.py @@ -1,7 +1,7 @@ """Add presets table Revision ID: db0c0dc793f4 -Revises: +Revises: Create Date: 2024-06-17 21:44:58.730544 """ @@ -30,9 +30,9 @@ def upgrade() -> None: sa.Column("suite", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column("cmd", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.PrimaryKeyConstraint("id"), - sa.UniqueConstraint("name"), + sa.UniqueConstraint("username", "name"), ) - op.create_index(op.f("ix_presets_username"), "presets", ["username"], unique=True) + op.create_index(op.f("ix_presets_username"), "presets", ["username"]) # ### end Alembic commands ### diff --git a/src/teuthology_api/models/presets.py b/src/teuthology_api/models/presets.py index fe28b22..cdd7f17 100644 --- a/src/teuthology_api/models/presets.py +++ b/src/teuthology_api/models/presets.py @@ -1,9 +1,11 @@ -from sqlmodel import Field, SQLModel +from sqlmodel import Field, SQLModel, UniqueConstraint class Presets(SQLModel, table=True): id: int = Field(primary_key=True) - username: str = Field(index=True, unique=True) - name: str = Field(unique=True) + username: str = Field(index=True) + name: str suite: str cmd: str + + __table_args__ = (UniqueConstraint("username", "name"),)