Skip to content

Commit

Permalink
Bugfix/pdct 664 update primary key constraint for physical document l…
Browse files Browse the repository at this point in the history
…anguage table (#195)

* PDCT-664 Updated primary key for physical doc language to include source.

* PDCT-664 Created migration to add source to physical doc language PK.
  • Loading branch information
katybaulch authored Dec 7, 2023
1 parent 1ca3848 commit 688eedc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
47 changes: 47 additions & 0 deletions alembic/versions/0026_updated_family_doc_primary_key_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Updated family doc primary key constraint to include language source
Revision ID: 0026
Revises: 0025
Create Date: 2023-12-07 10:58:25.326939
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "0026"
down_revision = "0025"
branch_labels = None
depends_on = None


def upgrade():
op.execute(
"""
ALTER TABLE physical_document_language
DROP CONSTRAINT pk_physical_document_language;
"""
)
op.execute(
"""
ALTER TABLE physical_document_language
ADD CONSTRAINT pk_physical_document_language
PRIMARY KEY (language_id, document_id, source);
"""
)


def downgrade():
op.execute(
"""
ALTER TABLE physical_document_language
DROP CONSTRAINT pk_physical_document_language;
"""
)
op.execute(
"""
ALTER TABLE physical_document_language
ADD CONSTRAINT pk_physical_document_language
PRIMARY KEY (language_id, document_id);
"""
)
3 changes: 2 additions & 1 deletion app/db/models/document/physical_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sqlalchemy as sa
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship

from app.db.models.app.enum import BaseModelEnum
from app.db.session import Base

Expand Down Expand Up @@ -78,4 +79,4 @@ class PhysicalDocumentLanguage(Base):
visible = sa.Column(sa.Boolean, default=False, nullable=False)
language = relationship("Language", viewonly=True, lazy="joined")

sa.PrimaryKeyConstraint(language_id, document_id)
sa.PrimaryKeyConstraint(language_id, document_id, source)

0 comments on commit 688eedc

Please sign in to comment.