Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Add last_updated field to PhotoGallery

Revision ID: 0150
Revises: 0149
Create Date: 2026-05-11 04:29:37.805098

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "0150"
down_revision = "0149"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"photo_galleries",
sa.Column("last_updated", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
)


def downgrade() -> None:
op.drop_column("photo_galleries", "last_updated")
1 change: 1 addition & 0 deletions app/backend/src/couchers/models/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class PhotoGallery(Base, kw_only=True):
owner_user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)

created: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), init=False)
last_updated: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), init=False)

owner_user: Mapped[User] = relationship(init=False, foreign_keys=[owner_user_id], back_populates="galleries")
photos: Mapped[list[PhotoGalleryItem]] = relationship(
Expand Down
4 changes: 4 additions & 0 deletions app/backend/src/couchers/servicers/galleries.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def AddPhotoToGallery(
caption=request.caption or None,
)
session.add(item)
gallery.last_updated = func.now()
session.flush()
session.refresh(gallery)

Expand Down Expand Up @@ -124,6 +125,7 @@ def RemovePhotoFromGallery(
context.abort_with_error_code(grpc.StatusCode.NOT_FOUND, "gallery_item_not_found")

session.delete(item)
gallery.last_updated = func.now()
session.flush()
session.refresh(gallery)

Expand Down Expand Up @@ -184,6 +186,7 @@ def MovePhoto(
session.execute(
update(PhotoGalleryItem).where(PhotoGalleryItem.id == request.item_id).values(position=new_position)
)
gallery.last_updated = func.now()

session.flush()
session.refresh(gallery)
Expand Down Expand Up @@ -213,6 +216,7 @@ def UpdatePhotoCaption(
context.abort_with_error_code(grpc.StatusCode.NOT_FOUND, "gallery_item_not_found")

item.caption = request.caption or None
gallery.last_updated = func.now()
session.flush()
session.refresh(gallery)

Expand Down
Loading