Skip to content

Commit

Permalink
(PC-33423)[API] feat: migration remove unicity constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
ogeber-pass committed Jan 6, 2025
1 parent 65175e7 commit fda8427
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/alembic_version_conflict_detection.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
f8588023c126 (pre) (head)
b18478ab2ea8 (post) (head)
4c53718279e7 (post) (head)
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
Drop headline offer unicity constraints on offer and venue
"""

from alembic import op


# pre/post deployment: post
# revision identifiers, used by Alembic.
revision = "4c53718279e7"
down_revision = "b18478ab2ea8"
branch_labels: tuple[str] | None = None
depends_on: list[str] | None = None


def upgrade() -> None:
with op.get_context().autocommit_block():
op.drop_index(
"ix_headline_offer_offerId",
table_name="headline_offer",
postgresql_concurrently=True,
if_exists=True,
)
op.create_index(
op.f("ix_headline_offer_offerId"),
"headline_offer",
["offerId"],
unique=False,
postgresql_concurrently=True,
if_not_exists=True,
)
op.drop_index(
"ix_headline_offer_venueId",
table_name="headline_offer",
postgresql_concurrently=True,
if_exists=True,
)
op.create_index(
op.f("ix_headline_offer_venueId"),
"headline_offer",
["venueId"],
unique=False,
postgresql_concurrently=True,
if_not_exists=True,
)


def downgrade() -> None:
with op.get_context().autocommit_block():
op.drop_index(
op.f("ix_headline_offer_venueId"),
table_name="headline_offer",
postgresql_concurrently=True,
if_exists=True,
)
op.create_index(
"ix_headline_offer_venueId",
"headline_offer",
["venueId"],
unique=True,
postgresql_concurrently=True,
if_not_exists=True,
)
op.drop_index(
op.f("ix_headline_offer_offerId"),
table_name="headline_offer",
postgresql_concurrently=True,
if_exists=True,
)
op.create_index(
"ix_headline_offer_offerId",
"headline_offer",
["offerId"],
unique=True,
postgresql_concurrently=True,
if_not_exists=True,
)
10 changes: 5 additions & 5 deletions api/src/pcapi/core/offers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,10 @@ class HeadlineOffer(PcObject, Base, Model):
__tablename__ = "headline_offer"

offerId: int = sa.Column(
sa.BigInteger, sa.ForeignKey("offer.id", ondelete="CASCADE"), nullable=False, index=True, unique=True
sa.BigInteger, sa.ForeignKey("offer.id", ondelete="CASCADE"), nullable=False, index=True, unique=False
)
offer: sa_orm.Mapped["Offer"] = sa_orm.relationship("Offer", back_populates="headlineOffer")
venueId: int = sa.Column(sa.BigInteger, sa.ForeignKey("venue.id"), nullable=False, index=True, unique=True)
offer: sa_orm.Mapped["Offer"] = sa_orm.relationship("Offer", back_populates="headlineOffers")
venueId: int = sa.Column(sa.BigInteger, sa.ForeignKey("venue.id"), nullable=False, index=True, unique=False)
venue: sa_orm.Mapped["Venue"] = sa_orm.relationship("Venue", back_populates="headlineOffers")

dateCreated: datetime.datetime = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.utcnow)
Expand Down Expand Up @@ -614,8 +614,8 @@ def __table_args__(self):
reactions: list["Reaction"] = sa.orm.relationship(
"Reaction", back_populates="offer", uselist=True, cascade="all, delete-orphan", passive_deletes=True
)
headlineOffer: sa_orm.Mapped["HeadlineOffer"] = sa_orm.relationship(
"HeadlineOffer", back_populates="offer", uselist=False
headlineOffers: sa_orm.Mapped[list["HeadlineOffer"]] = sa_orm.relationship(
"HeadlineOffer", back_populates="offer", uselist=True, cascade="all, delete-orphan", passive_deletes=True
)

sa.Index("idx_offer_trgm_name", name, postgresql_using="gin")
Expand Down

0 comments on commit fda8427

Please sign in to comment.