From 3e56436f85220c2bf789712b2b1a37492759301e Mon Sep 17 00:00:00 2001 From: liberty-rising Date: Mon, 11 Dec 2023 15:35:58 +0100 Subject: [PATCH] add UniqueConstraint to 'name' and 'organization_id' in DataProfile model --- backend/models/data_profile.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/models/data_profile.py b/backend/models/data_profile.py index 3757a8c..b836af8 100644 --- a/backend/models/data_profile.py +++ b/backend/models/data_profile.py @@ -1,10 +1,10 @@ from sqlalchemy import Column, Integer, String, ForeignKey from pydantic import BaseModel from .base import Base +from sqlalchemy import UniqueConstraint class DataProfile(Base): - """ DataProfile Model ----------------- @@ -20,11 +20,15 @@ class DataProfile(Base): __tablename__ = "data_profiles" id = Column(Integer, primary_key=True) - name = Column(String) + name = Column(String, unique=True) file_type = Column(String) organization_id = Column(Integer, ForeignKey("organizations.id")) description = Column(String) # New description column + __table_args__ = ( + UniqueConstraint("name", "organization_id", name="uq_name_organization_id"), + ) + def to_dict(self): """ Converts the DataProfile instance into a dictionary.