Skip to content

Commit

Permalink
Update schema and alembic so we only have unique metric names
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishteagle committed Mar 27, 2024
1 parent 4a7e731 commit 0d55b3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""add_metric_name_unique_constraint
Revision ID: 512d9168f6c2
Revises: eaf7bb3598af
Create Date: 2024-03-27 14:18:55.504729
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '512d9168f6c2'
down_revision = 'eaf7bb3598af'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(None, 'metric', ['name'])
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'metric', type_='unique')
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion src/insight/database/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Metric(Base):
__tablename__ = "metric"

id = mapped_column(INTEGER, primary_key=True)
name = mapped_column(VARCHAR(100), nullable=False)
name = mapped_column(VARCHAR(100), nullable=False, unique=True)
category = mapped_column(VARCHAR(100))
created_at = mapped_column(TIMESTAMP, default=func.now())

Expand Down

0 comments on commit 0d55b3b

Please sign in to comment.