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

🗃️(api) make location address/coordinates unique together #329

Closed
Closed
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: 2 additions & 0 deletions src/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to
command
- Decrease the number of database queries for dynamic endpoints
- Cache the "get PointDeCharge id from its `id_pdc_itinerance`" database query
- Updated `Localisation` table constraint: `adresse_station` is no longer
unique, but the `adresse_station`/`coordonneesXY` couple should be
- Upgrade pydantic to `2.10.4`
- Upgrade pydantic-settings to `2.7.1`
- Upgrade python-multipart to `0.0.20`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Update localisation uniqueness criterions

Revision ID: 32b3d0e269a2
Revises: c09664a85912
Create Date: 2025-01-09 16:20:52.578289

"""

from typing import Sequence, Union

from alembic import op

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


def upgrade() -> None:
op.drop_constraint(
"localisation_adresse_station_key", "localisation", type_="unique"
)
op.create_unique_constraint(
"localisation_adresse_station_coordonneesXY_key",
"localisation",
["adresse_station", "coordonneesXY"],
)


def downgrade() -> None:
op.drop_constraint(
"localisation_adresse_station_coordonneesXY_key", "localisation", type_="unique"
)
op.create_unique_constraint(
"localisation_adresse_station_key", "localisation", ["adresse_station"]
)
6 changes: 5 additions & 1 deletion src/api/qualicharge/schemas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ def __eq__(self, other) -> bool:
class Localisation(BaseTimestampedSQLModel, table=True):
"""Localisation table."""

__table_args__ = BaseTimestampedSQLModel.__table_args__ + (
UniqueConstraint("adresse_station", "coordonneesXY"),
)

model_config = SQLModelConfig(
validate_assignment=True, arbitrary_types_allowed=True
)

id: UUID = Field(default_factory=uuid4, primary_key=True)
adresse_station: str = Field(unique=True)
adresse_station: str
code_insee_commune: str = Field(regex=r"^([013-9]\d|2[AB1-9])\d{3}$")
coordonneesXY: DataGouvCoordinate = Field(
sa_type=Geometry(
Expand Down
2 changes: 1 addition & 1 deletion src/api/qualicharge/schemas/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def save(self):
self._save_schema(
self.localisation,
Localisation,
constraint="localisation_adresse_station_key",
constraint="localisation_adresse_station_coordonneesXY_key",
)
self._save_schema(
self.station,
Expand Down
Loading