Skip to content

Commit

Permalink
Merge b025dfc into eab73a8
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed May 14, 2024
2 parents eab73a8 + b025dfc commit 301c018
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions alembic/versions/92a0b4c8fe24_add_device_internal_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add_device_internal_id
Revision ID: 92a0b4c8fe24
Revises: 078884a6b2d2
Create Date: 2024-05-13 16:15:45.639070
"""

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "92a0b4c8fe24"
down_revision = "078884a6b2d2"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
table_name="run_device",
column=sa.Column(__name_pos="internal_id", __type_pos=sa.String(length=64), nullable=False),
)
op.create_unique_constraint(
constraint_name="uq_internal_id", table_name="run_device", columns=["internal_id"]
)


def downgrade():
op.drop_constraint(constraint_name="uq_internal_id", table_name="run_device", type_="unique")
op.drop_column(table_name="run_device", column_name="internal_id")
2 changes: 2 additions & 0 deletions cg/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

PrimaryKeyInt = Annotated[int, mapped_column(primary_key=True)]
UniqueStr = Annotated[str, mapped_column(String(32), unique=True)]
UniqueStr64 = Annotated[str, mapped_column(String(64), unique=True)]


class Base(DeclarativeBase):
Expand Down Expand Up @@ -967,6 +968,7 @@ class RunDevice(Base):

id: Mapped[PrimaryKeyInt]
type: Mapped[DeviceType]
internal_id: Mapped[UniqueStr64]

__mapper_args__ = {
"polymorphic_on": "type",
Expand Down

0 comments on commit 301c018

Please sign in to comment.