From bd0347b152775a792a686256d2c299113ddcf23d Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Thu, 19 Dec 2024 15:53:02 -0800 Subject: [PATCH] Cleanup UQs and Add Migration --- .../versions/2024-12-19-23-46_ab04810d4d7c.py | 36 +++++++++++++++++++ .../admin_adjustment/AdminAdjustment.py | 1 - .../AdminAdjustmentHistory.py | 1 - .../lcfs/db/models/comment/InternalComment.py | 3 +- backend/lcfs/db/models/document/Document.py | 1 - .../InitiativeAgreement.py | 1 - .../InitiativeAgreementHistory.py | 1 - .../lcfs/db/models/transaction/Transaction.py | 1 - backend/lcfs/db/models/transfer/Transfer.py | 1 - .../db/models/transfer/TransferCategory.py | 5 +-- 10 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 backend/lcfs/db/migrations/versions/2024-12-19-23-46_ab04810d4d7c.py diff --git a/backend/lcfs/db/migrations/versions/2024-12-19-23-46_ab04810d4d7c.py b/backend/lcfs/db/migrations/versions/2024-12-19-23-46_ab04810d4d7c.py new file mode 100644 index 000000000..2ce5f6430 --- /dev/null +++ b/backend/lcfs/db/migrations/versions/2024-12-19-23-46_ab04810d4d7c.py @@ -0,0 +1,36 @@ +"""Add UQ to TCI + +Revision ID: ab04810d4d7c +Revises: 851e09cf8661 +Create Date: 2024-12-19 23:46:37.505166 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "ab04810d4d7c" +down_revision = "851e09cf8661" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_unique_constraint( + "uq_target_carbon_intensity_compliance_fuel", + "target_carbon_intensity", + ["compliance_period_id", "fuel_category_id"], + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint( + "uq_target_carbon_intensity_compliance_fuel", + "target_carbon_intensity", + type_="unique", + ) + # ### end Alembic commands ### diff --git a/backend/lcfs/db/models/admin_adjustment/AdminAdjustment.py b/backend/lcfs/db/models/admin_adjustment/AdminAdjustment.py index 49443d9d2..f410f114e 100644 --- a/backend/lcfs/db/models/admin_adjustment/AdminAdjustment.py +++ b/backend/lcfs/db/models/admin_adjustment/AdminAdjustment.py @@ -7,7 +7,6 @@ class AdminAdjustment(BaseModel, Auditable, EffectiveDates): __tablename__ = "admin_adjustment" __table_args__ = ( - UniqueConstraint("admin_adjustment_id"), {"comment": "Goverment to organization compliance units admin_adjustment"}, ) diff --git a/backend/lcfs/db/models/admin_adjustment/AdminAdjustmentHistory.py b/backend/lcfs/db/models/admin_adjustment/AdminAdjustmentHistory.py index 36fbf0d6f..581880e0f 100644 --- a/backend/lcfs/db/models/admin_adjustment/AdminAdjustmentHistory.py +++ b/backend/lcfs/db/models/admin_adjustment/AdminAdjustmentHistory.py @@ -7,7 +7,6 @@ class AdminAdjustmentHistory(BaseModel, Auditable, EffectiveDates): __tablename__ = "admin_adjustment_history" __table_args__ = ( - UniqueConstraint("admin_adjustment_history_id"), {"comment": "History record for admin_adjustment status change."}, ) diff --git a/backend/lcfs/db/models/comment/InternalComment.py b/backend/lcfs/db/models/comment/InternalComment.py index 56dcecbc9..2ed0684d7 100644 --- a/backend/lcfs/db/models/comment/InternalComment.py +++ b/backend/lcfs/db/models/comment/InternalComment.py @@ -12,7 +12,6 @@ class InternalComment(BaseModel, Auditable): __tablename__ = "internal_comment" __table_args__ = ( - UniqueConstraint("internal_comment_id"), {"comment": "Stores internal comments with scope and related metadata."}, ) @@ -42,4 +41,4 @@ class InternalComment(BaseModel, Auditable): ) compliance_report_internal_comments = relationship( "ComplianceReportInternalComment", back_populates="internal_comment" - ) \ No newline at end of file + ) diff --git a/backend/lcfs/db/models/document/Document.py b/backend/lcfs/db/models/document/Document.py index 865df76ee..3c39ef3c6 100644 --- a/backend/lcfs/db/models/document/Document.py +++ b/backend/lcfs/db/models/document/Document.py @@ -11,7 +11,6 @@ class Document(BaseModel, Auditable): __tablename__ = "document" __table_args__ = ( - UniqueConstraint("document_id"), {"comment": "Main document table for storing base document information"}, ) diff --git a/backend/lcfs/db/models/initiative_agreement/InitiativeAgreement.py b/backend/lcfs/db/models/initiative_agreement/InitiativeAgreement.py index 63d5a9817..98594b6bd 100644 --- a/backend/lcfs/db/models/initiative_agreement/InitiativeAgreement.py +++ b/backend/lcfs/db/models/initiative_agreement/InitiativeAgreement.py @@ -7,7 +7,6 @@ class InitiativeAgreement(BaseModel, Auditable, EffectiveDates): __tablename__ = "initiative_agreement" __table_args__ = ( - UniqueConstraint("initiative_agreement_id"), {"comment": "Goverment to organization compliance units initiative agreement"}, ) diff --git a/backend/lcfs/db/models/initiative_agreement/InitiativeAgreementHistory.py b/backend/lcfs/db/models/initiative_agreement/InitiativeAgreementHistory.py index 868c96f8d..65f45acb8 100644 --- a/backend/lcfs/db/models/initiative_agreement/InitiativeAgreementHistory.py +++ b/backend/lcfs/db/models/initiative_agreement/InitiativeAgreementHistory.py @@ -7,7 +7,6 @@ class InitiativeAgreementHistory(BaseModel, Auditable, EffectiveDates): __tablename__ = "initiative_agreement_history" __table_args__ = ( - UniqueConstraint("initiative_agreement_history_id"), {"comment": "History record for initiative agreement status change."}, ) diff --git a/backend/lcfs/db/models/transaction/Transaction.py b/backend/lcfs/db/models/transaction/Transaction.py index 10042ab68..40e9696fc 100644 --- a/backend/lcfs/db/models/transaction/Transaction.py +++ b/backend/lcfs/db/models/transaction/Transaction.py @@ -16,7 +16,6 @@ class TransactionActionEnum(enum.Enum): class Transaction(BaseModel, Auditable, EffectiveDates): __tablename__ = "transaction" __table_args__ = ( - UniqueConstraint("transaction_id"), { "comment": "Contains a list of all of the government to organization and Organization to Organization transaction." }, diff --git a/backend/lcfs/db/models/transfer/Transfer.py b/backend/lcfs/db/models/transfer/Transfer.py index 5869dce0b..f9f6c55e5 100644 --- a/backend/lcfs/db/models/transfer/Transfer.py +++ b/backend/lcfs/db/models/transfer/Transfer.py @@ -13,7 +13,6 @@ class TransferRecommendationEnum(enum.Enum): class Transfer(BaseModel, Auditable, EffectiveDates): __tablename__ = "transfer" __table_args__ = ( - UniqueConstraint("transfer_id"), {"comment": "Records of tranfer from Organization to Organization"}, ) diff --git a/backend/lcfs/db/models/transfer/TransferCategory.py b/backend/lcfs/db/models/transfer/TransferCategory.py index 8bab13e73..6b41e1510 100644 --- a/backend/lcfs/db/models/transfer/TransferCategory.py +++ b/backend/lcfs/db/models/transfer/TransferCategory.py @@ -14,10 +14,7 @@ class TransferCategoryEnum(enum.Enum): class TransferCategory(BaseModel, Auditable, EffectiveDates): __tablename__ = "transfer_category" - __table_args__ = ( - UniqueConstraint("transfer_category_id"), - {"comment": "Transfer Category"}, - ) + __table_args__ = ({"comment": "Transfer Category"},) transfer_category_id = Column( Integer,