Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-31395)[API] feat: add idAtProvider in PriceCategory #13945

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
4 changes: 2 additions & 2 deletions api/alembic_version_conflict_detection.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
869f0d3be788 (pre) (head)
63fa42fd8352 (post) (head)
8523f3e2d7d6 (pre) (head)
404b3075d1a4 (post) (head)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Add idAtProvider in `price_category`
"""

from alembic import op
import sqlalchemy as sa


# pre/post deployment: pre
# revision identifiers, used by Alembic.
revision = "8523f3e2d7d6"
down_revision = "869f0d3be788"
branch_labels: tuple[str] | None = None
depends_on: list[str] | None = None


def upgrade() -> None:
op.add_column("price_category", sa.Column("idAtProvider", sa.Text(), nullable=True))


def downgrade() -> None:
op.drop_column("price_category", "idAtProvider")
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add unique index on (`idAProvider`, `offerId`) in `price_category` table
"""

from alembic import op


# pre/post deployment: post
# revision identifiers, used by Alembic.
revision = "404b3075d1a4"
down_revision = "63fa42fd8352"
branch_labels: tuple[str] | None = None
depends_on: list[str] | None = None


def upgrade() -> None:
with op.get_context().autocommit_block():
op.create_index(
"unique_ix_offer_id_id_at_provider",
"price_category",
["offerId", "idAtProvider"],
unique=True,
postgresql_concurrently=True,
if_not_exists=True,
)


def downgrade() -> None:
with op.get_context().autocommit_block():
op.drop_index(
"unique_ix_offer_id_id_at_provider",
table_name="price_category",
postgresql_concurrently=True,
if_exists=True,
)
5 changes: 5 additions & 0 deletions api/src/pcapi/core/offers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,11 @@ class PriceCategory(PcObject, Base, Model):
"PriceCategoryLabel", back_populates="priceCategory"
)
stocks: sa_orm.Mapped[list["Stock"]] = relationship("Stock", back_populates="priceCategory", cascade="all")
idAtProvider = sa.Column(sa.Text, nullable=True)

# First step : Create a unique index on offerId/idAtProvider
# Next step : (TO DO) Create a unique constraint based on this index
sa.Index("unique_ix_offer_id_id_at_provider", offerId, idAtProvider, unique=True)

@property
def label(self) -> str:
Expand Down
Loading