Skip to content

Commit

Permalink
🗃️(api) add geo schemas missing constraints
Browse files Browse the repository at this point in the history
Some constraints linked to recent database schema changes were missing:
no primary keys and foreign keys was defined.
  • Loading branch information
jmaupetit committed Oct 17, 2024
1 parent 9e4d3be commit 8a4813e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ and this project adheres to
- Upgrade fastapi to `0.115.2`
- Upgrade pyinstrument to `5.0.0`

## [0.13.0] - 2024-10-11

### Fixed

- Migrate administrative boundaries tables schema and data
- Add missing City / Department table foreign key constraints

## [0.13.0] - 2024-10-11

### Changed

Expand All @@ -32,6 +32,10 @@ and this project adheres to
- Upgrade python-multipart to `0.0.12`
- Upgrade sentry-sdk to `74.1.2`

### Fixed

- Migrate administrative boundaries tables schema and data

## [0.12.1] - 2024-09-09

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""add missing fk
Revision ID: 6e610f62bcc6
Revises: b69ed697b446
Create Date: 2024-10-16 15:44:28.265424
"""

from typing import Sequence, Union

from alembic import op

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


def upgrade() -> None:
# Create missing PKs
op.create_primary_key("region_pkey", "region", ["id"])
op.create_primary_key("department_pkey", "department", ["id"])
op.create_primary_key("epci_pkey", "epci", ["id"])
op.create_primary_key("city_pkey", "city", ["id"])

# And FKs
op.create_foreign_key(
"city_department_id_fkey", "city", "department", ["department_id"], ["id"]
)
op.create_foreign_key("city_epci_id_fkey", "city", "epci", ["epci_id"], ["id"])
op.create_foreign_key(
"department_region_id_fkey", "department", "region", ["region_id"], ["id"]
)


def downgrade() -> None:
# Delete PKs
op.drop_constraint("region_pkey", "region", type_="primary")
op.drop_constraint("department_pkey", "department", type_="primary")
op.drop_constraint("epci_pkey", "epci", type_="primary")
op.drop_constraint("city_pkey", "city", type_="primary")

# Delete FKs
op.drop_constraint("department_region_id_fkey", "department", type_="foreignkey")
op.drop_constraint("city_epci_id_fkey", "city", type_="foreignkey")
op.drop_constraint("city_department_id_fkey", "city", type_="foreignkey")

0 comments on commit 8a4813e

Please sign in to comment.