Skip to content

Commit

Permalink
Update schema and alembic so we only have unique metric names (#185)
Browse files Browse the repository at this point in the history
* Update schema and alembic so we only have unique metric names

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add constraint name

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
hamishteagle and pre-commit-ci[bot] authored Mar 27, 2024
1 parent 4a7e731 commit 97d631e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""add_metric_name_unique_constraint
Revision ID: 512d9168f6c2
Revises: eaf7bb3598af
Create Date: 2024-03-27 14:18:55.504729
"""

import sqlalchemy as sa
from alembic import op

# 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(
constraint_name="name-unique", table_name="metric", columns=["name"]
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(constraint_name="name-unique", table_name="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 97d631e

Please sign in to comment.