Skip to content

Commit

Permalink
Actually really done
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Nov 27, 2024
1 parent 664db54 commit 9e832bd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
"""Update database nullable constraints
Revision ID: 9dafb82f1fac
Revision ID: e8ba89a7585a
Revises: 272da5f400de
Create Date: 2024-11-27 17:21:28.727991+00:00
Create Date: 2024-11-27 17:44:03.526711+00:00
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "9dafb82f1fac"
revision = "e8ba89a7585a"
down_revision = "272da5f400de"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column(
"customlists",
"auto_update_status",
existing_type=postgresql.ENUM(
"init", "updated", "repopulate", name="auto_update_status"
),
nullable=False,
)
op.alter_column(
"editions", "data_source_id", existing_type=sa.INTEGER(), nullable=False
)
Expand Down Expand Up @@ -125,4 +134,12 @@ def downgrade() -> None:
op.alter_column(
"editions", "data_source_id", existing_type=sa.INTEGER(), nullable=True
)
op.alter_column(
"customlists",
"auto_update_status",
existing_type=postgresql.ENUM(
"init", "updated", "repopulate", name="auto_update_status"
),
nullable=True,
)
# ### end Alembic commands ###
3 changes: 2 additions & 1 deletion src/palace/manager/feed/annotator/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def annotate_work_entry(
# Find staff rating and add a tag for it.
for measurement in identifier.measurements:
if (
measurement.data_source.name == DataSource.LIBRARY_STAFF
measurement.data_source
and measurement.data_source.name == DataSource.LIBRARY_STAFF
and measurement.is_most_recent
and measurement.value is not None
):
Expand Down
4 changes: 3 additions & 1 deletion src/palace/manager/sqlalchemy/model/customlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class CustomList(Base):
auto_update_facets = Column(Unicode, nullable=True) # holds json data
auto_update_last_update = Column(DateTime, nullable=True)
auto_update_status: Mapped[str] = Column(
Enum(INIT, UPDATED, REPOPULATE, name="auto_update_status"), default=INIT
Enum(INIT, UPDATED, REPOPULATE, name="auto_update_status"),
default=INIT,
nullable=False,
)

collections: Mapped[list[Collection]] = relationship(
Expand Down
6 changes: 2 additions & 4 deletions src/palace/manager/sqlalchemy/model/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,8 @@ class Measurement(Base):
)

# A Measurement always comes from some DataSource.
data_source_id: Mapped[int] = Column(
Integer, ForeignKey("datasources.id"), index=True
)
data_source: Mapped[DataSource] = relationship(
data_source_id = Column(Integer, ForeignKey("datasources.id"), index=True)
data_source: Mapped[DataSource | None] = relationship(
"DataSource", back_populates="measurements"
)

Expand Down
2 changes: 1 addition & 1 deletion src/palace/manager/sqlalchemy/model/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Work(Base, LoggerMixin):
target_age = Column(INT4RANGE, index=True)
fiction = Column(Boolean, index=True)

summary_id: Mapped[int | None] = Column(
summary_id = Column(
Integer,
ForeignKey("resources.id", use_alter=True, name="fk_works_summary_id"),
index=True,
Expand Down

0 comments on commit 9e832bd

Please sign in to comment.