Skip to content

Commit

Permalink
Make loan.patron_id and hold.patron_id fields non-nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Dec 2, 2024
1 parent 14b4315 commit 69cd3e4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Make Loan.patron_id and Hold.patron_id non-nullable.
Revision ID: 58b0ae7f5b67
Revises: 272da5f400de
Create Date: 2024-11-19 18:04:24.182444+00:00
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "58b0ae7f5b67"
down_revision = "272da5f400de"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column(
table_name="loans",
column_name="patron_id",
nullable=False,
)

op.alter_column(
table_name="holds",
column_name="patron_id",
nullable=False,
)


def downgrade() -> None:
op.alter_column(
table_name="loans",
column_name="patron_id",
nullable=True,
)

op.alter_column(
table_name="holds",
column_name="patron_id",
nullable=True,
)
4 changes: 2 additions & 2 deletions src/palace/manager/sqlalchemy/model/patron.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class Loan(Base, LoanAndHoldMixin):
__tablename__ = "loans"
id = Column(Integer, primary_key=True)

patron_id = Column(Integer, ForeignKey("patrons.id"), index=True)
patron_id = Column(Integer, ForeignKey("patrons.id"), index=True, nullable=False)
patron: Mapped[Patron] = relationship("Patron", back_populates="loans")

# A Loan is always associated with a LicensePool.
Expand Down Expand Up @@ -565,7 +565,7 @@ class Hold(Base, LoanAndHoldMixin):

__tablename__ = "holds"
id = Column(Integer, primary_key=True)
patron_id = Column(Integer, ForeignKey("patrons.id"), index=True)
patron_id = Column(Integer, ForeignKey("patrons.id"), index=True, nullable=False)
license_pool_id = Column(Integer, ForeignKey("licensepools.id"), index=True)
license_pool: Mapped[LicensePool] = relationship(
"LicensePool", back_populates="holds"
Expand Down

0 comments on commit 69cd3e4

Please sign in to comment.