Skip to content

Commit

Permalink
fix(api): add data missing from first migration
Browse files Browse the repository at this point in the history
  • Loading branch information
vmttn committed Dec 18, 2024
1 parent c741f9b commit 87761d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""cleanup analytics
Revision ID: df6029fc3a1f
Revises: 89e1ece4f56e
Create Date: 2024-12-18 11:24:08.555320
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "df6029fc3a1f"
down_revision = "89e1ece4f56e"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.drop_column("api__list_structures_events", "structure_id")
op.execute("""
UPDATE public.api__list_services_events
SET
code_departement = COALESCE(query_params ->> 'code_departement', query_params ->> 'departement'),
code_commune = COALESCE(query_params ->> 'code_commune', query_params ->> 'code_insee'),
thematiques = COALESCE(STRING_TO_ARRAY(query_params ->> 'thematiques', ','), ARRAY[query_params ->> 'thematique'])
FROM public.api__requests
WHERE public.api__list_services_events.id = public.api__requests.id
""") # noqa: E501
op.execute("""
UPDATE public.api__list_structures_events
SET
code_departement = COALESCE(query_params ->> 'code_departement', query_params ->> 'departement'),
code_commune = COALESCE(query_params ->> 'code_commune', query_params ->> 'code_insee')
FROM public.api__requests
WHERE public.api__list_structures_events.id = public.api__requests.id
""") # noqa: E501
op.execute("""
UPDATE public.api__search_services_events
SET
code_commune = COALESCE(query_params ->> 'code_commune', query_params ->> 'code_insee')
FROM public.api__requests
WHERE public.api__search_services_events.id = public.api__requests.id
""") # noqa: E501


def downgrade() -> None:
op.add_column(
"api__list_structures_events",
sa.Column("structure_id", sa.VARCHAR(), autoincrement=False, nullable=True),
)
1 change: 0 additions & 1 deletion api/src/data_inclusion/api/analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ListStructuresEvent(db.Base):
created_at: Mapped[db.timestamp]
user: Mapped[str]
sources: Mapped[list[str] | None]
structure_id: Mapped[str | None]
typologie: Mapped[str | None]
label_national: Mapped[str | None]
code_departement: Mapped[str | None]
Expand Down

0 comments on commit 87761d4

Please sign in to comment.