Skip to content

Commit

Permalink
Update the preset database model
Browse files Browse the repository at this point in the history
Add composite unique constraint on (username, name)

Signed-off-by: Devansh Singh <[email protected]>
  • Loading branch information
Devansh3712 committed Jul 31, 2024
1 parent 88ee986 commit c8d5b61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 6 additions & 1 deletion migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions migrations/versions/db0c0dc793f4_add_presets_table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Add presets table
Revision ID: db0c0dc793f4
Revises:
Revises:
Create Date: 2024-06-17 21:44:58.730544
"""
Expand Down Expand Up @@ -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 ###


Expand Down
8 changes: 5 additions & 3 deletions src/teuthology_api/models/presets.py
Original file line number Diff line number Diff line change
@@ -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"),)

0 comments on commit c8d5b61

Please sign in to comment.