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-32747)[API] feat: fix schema typing and set startDatetime and end… #15664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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)
a8d2c442cc67 (post) (head)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Add NOT NULL constraint on "collective_stock.startDatetime" and "collective_stock.endDatetime" (step 3 of 4)
"""

from alembic import op


# pre/post deployment: post
# revision identifiers, used by Alembic.
revision = "4302137d444a"
down_revision = "89d6c28597ef"
branch_labels: tuple[str] | None = None
depends_on: list[str] | None = None


def upgrade() -> None:
op.alter_column("collective_stock", "startDatetime", nullable=False)
op.alter_column("collective_stock", "endDatetime", nullable=False)


def downgrade() -> None:
op.alter_column("collective_stock", "startDatetime", nullable=True)
op.alter_column("collective_stock", "endDatetime", nullable=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Add NOT NULL constraint on "collective_stock.startDatetime" and "collective_stock.endDatetime" (step 2 of 4)
"""

from alembic import op

from pcapi import settings


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


def upgrade() -> None:
with op.get_context().autocommit_block():
op.execute("SET SESSION statement_timeout = '300s'")
op.execute(
'ALTER TABLE "collective_stock" VALIDATE CONSTRAINT "collective_stock_startDatetime_not_null_constraint"'
)
op.execute(
'ALTER TABLE "collective_stock" VALIDATE CONSTRAINT "collective_stock_endDatetime_not_null_constraint"'
)
op.execute(f"SET SESSION statement_timeout={settings.DATABASE_STATEMENT_TIMEOUT}")


def downgrade() -> None:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Add NOT NULL constraint on "collective_stock.startDatetime" and "collective_stock.endDatetime" (step 1 of 4)
"""

from alembic import op


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


def upgrade() -> None:
op.execute(
"""
ALTER TABLE "collective_stock" DROP CONSTRAINT IF EXISTS "collective_stock_startDatetime_not_null_constraint";
ALTER TABLE "collective_stock" ADD CONSTRAINT "collective_stock_startDatetime_not_null_constraint" CHECK ("startDatetime" IS NOT NULL) NOT VALID;
"""
)
op.execute(
"""
ALTER TABLE "collective_stock" DROP CONSTRAINT IF EXISTS "collective_stock_endDatetime_not_null_constraint";
ALTER TABLE "collective_stock" ADD CONSTRAINT "collective_stock_endDatetime_not_null_constraint" CHECK ("endDatetime" IS NOT NULL) NOT VALID;
"""
)


def downgrade() -> None:
op.drop_constraint("collective_stock_startDatetime_not_null_constraint", table_name="collective_stock")
op.drop_constraint("collective_stock_endDatetime_not_null_constraint", table_name="collective_stock")
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Add NOT NULL constraint on "collective_stock.startDatetime" and "collective_stock.endDatetime" (step 4 of 4)
"""

from alembic import op


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


def upgrade() -> None:
op.drop_constraint("collective_stock_startDatetime_not_null_constraint", table_name="collective_stock")
op.drop_constraint("collective_stock_endDatetime_not_null_constraint", table_name="collective_stock")


def downgrade() -> None:
op.execute(
"""ALTER TABLE "collective_stock" ADD CONSTRAINT "collective_stock_startDatetime_not_null_constraint" CHECK ("startDatetime" IS NOT NULL) NOT VALID"""
)
op.execute(
"""ALTER TABLE "collective_stock" ADD CONSTRAINT "collective_stock_endDatetime_not_null_constraint" CHECK ("endDatetime" IS NOT NULL) NOT VALID"""
)
4 changes: 2 additions & 2 deletions api/src/pcapi/core/educational/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ class CollectiveStock(PcObject, Base, Model):

beginningDatetime: datetime = sa.Column(sa.DateTime, index=True, nullable=False)

startDatetime: datetime = sa.Column(sa.DateTime, nullable=True)
endDatetime: datetime = sa.Column(sa.DateTime, nullable=True)
startDatetime: datetime = sa.Column(sa.DateTime, nullable=False)
endDatetime: datetime = sa.Column(sa.DateTime, nullable=False)

collectiveOfferId: int = sa.Column(
sa.BigInteger, sa.ForeignKey("collective_offer.id"), index=True, nullable=False, unique=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class CollectiveBookingCollectiveStockResponseModel(BaseModel):
offer_id: int
event_beginning_datetime: str
event_start_datetime: str
event_end_datetime: str | None
event_end_datetime: str
offer_isbn: str | None
offer_is_educational: bool
number_of_tickets: int
booking_limit_datetime: str | None
booking_limit_datetime: str

class Config:
alias_generator = to_camel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
/* tslint:disable */
/* eslint-disable */
export type CollectiveBookingCollectiveStockResponseModel = {
bookingLimitDatetime?: string | null;
bookingLimitDatetime: string;
eventBeginningDatetime: string;
eventEndDatetime?: string | null;
eventEndDatetime: string;
eventStartDatetime: string;
numberOfTickets: number;
offerId: number;
Expand Down
1 change: 1 addition & 0 deletions pro/src/commons/utils/factories/collectiveApiFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const collectiveBookingCollectiveStockFactory = (
bookingLimitDatetime: new Date().toISOString(),
eventBeginningDatetime: new Date().toISOString(),
eventStartDatetime: new Date().toISOString(),
eventEndDatetime: new Date().toISOString(),
numberOfTickets: 1,
offerId: 1,
offerIsEducational: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ describe('bookings offer cell', () => {
offerIsbn: '97834567654',
offerName: 'La Guitare pour les nuls',
offerIsEducational: false,
bookingLimitDatetime: new Date().toISOString(),
eventBeginningDatetime: new Date().toISOString(),
eventStartDatetime: new Date().toISOString(),
eventEndDatetime: new Date().toISOString(),
numberOfTickets: 1,
},
}),
Expand All @@ -43,8 +45,10 @@ describe('bookings offer cell', () => {
offerId: offerId,
offerName: 'Guitare acoustique',
offerIsEducational: false,
bookingLimitDatetime: new Date().toISOString(),
eventBeginningDatetime: new Date().toISOString(),
eventStartDatetime: new Date().toISOString(),
eventEndDatetime: new Date().toISOString(),
numberOfTickets: 1,
},
}),
Expand All @@ -61,8 +65,10 @@ describe('bookings offer cell', () => {
const props: BookingOfferCellProps = {
booking: collectiveBookingFactory({
stock: {
bookingLimitDatetime: '2020-05-12T11:03:28.564687+04:00',
eventBeginningDatetime: '2020-05-12T11:03:28.564687+04:00',
eventStartDatetime: new Date().toISOString(),
eventEndDatetime: new Date().toISOString(),
offerId: offerId,
offerName: 'La danse des poireaux',
offerIsEducational: false,
Expand All @@ -89,6 +95,7 @@ describe('bookings offer cell', () => {
bookingLimitDatetime: tomorrowFns.toISOString(),
eventBeginningDatetime: new Date().toISOString(),
eventStartDatetime: new Date().toISOString(),
eventEndDatetime: new Date().toISOString(),
numberOfTickets: 1,
offerId: offerId,
offerIsEducational: true,
Expand All @@ -114,6 +121,7 @@ describe('bookings offer cell', () => {
bookingLimitDatetime: eightDaysFns.toISOString(),
eventBeginningDatetime: new Date().toISOString(),
eventStartDatetime: new Date().toISOString(),
eventEndDatetime: new Date().toISOString(),
numberOfTickets: 1,
offerId: offerId,
offerIsEducational: false,
Expand Down
Loading