Skip to content

Commit

Permalink
🐛(api) make the PointDeCharge.id_pdc_itinerance field unique
Browse files Browse the repository at this point in the history
My bad. Dunno how I could have missed this?
  • Loading branch information
jmaupetit committed Jul 31, 2024
1 parent 0dc62bf commit 2dd3914
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to

- Add relevant data examples for Swagger
- Improve database session management
- `PointDeCharge.id_pdc_itinerance` should be unique

## [0.10.0] - 2024-07-01

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""id_pdc_itinerance should be unique
Revision ID: d1e96368f232
Revises: f5416bc7dd5f
Create Date: 2024-07-31 15:25:26.997834
"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "d1e96368f232"
down_revision: Union[str, None] = "f5416bc7dd5f"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("ix_pointdecharge_id_pdc_itinerance", table_name="pointdecharge")
op.create_index(
op.f("ix_pointdecharge_id_pdc_itinerance"),
"pointdecharge",
["id_pdc_itinerance"],
unique=True,
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("ix_pointdecharge_id_pdc_itinerance"), table_name="pointdecharge"
)
op.create_index(
"ix_pointdecharge_id_pdc_itinerance",
"pointdecharge",
["id_pdc_itinerance"],
unique=False,
)
# ### end Alembic commands ###
4 changes: 3 additions & 1 deletion src/api/qualicharge/schemas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ class PointDeCharge(BaseTimestampedSQLModel, table=True):

id: Optional[UUID] = Field(default_factory=lambda: uuid4().hex, primary_key=True)
id_pdc_itinerance: str = Field(
regex="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$", index=True
regex="(?:(?:^|,)(^[A-Z]{2}[A-Z0-9]{4,33}$|Non concerné))+$",
index=True,
unique=True,
)
id_pdc_local: Optional[str]
puissance_nominale: PositiveFloat
Expand Down

0 comments on commit 2dd3914

Please sign in to comment.