Skip to content
Merged
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
23 changes: 12 additions & 11 deletions src/api/endpoints/annotate/migrate/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any
from uuid import UUID

from sqlalchemy import insert, select, delete
from sqlalchemy import select, delete
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.ext.asyncio import AsyncSession

from src.db.models.impl.annotation.agency.anon.sqlalchemy import AnnotationAgencyAnon
Expand Down Expand Up @@ -45,8 +46,8 @@ async def migrate_agency_annotations(self, session: AsyncSession) -> None:
self.user_id
).where(
AnnotationAgencyAnon.session_id == self.session_id
)
)
).distinct()
).on_conflict_do_nothing(index_elements=["agency_id", "url_id", "user_id"])
await session.execute(statement)
# Delete all anonymous agency annotations.
statement = delete(AnnotationAgencyAnon).where(
Expand All @@ -65,8 +66,8 @@ async def migrate_location_annotations(self, session: AsyncSession) -> None:
self.user_id
).where(
AnnotationLocationAnon.session_id == self.session_id
)
)
).distinct()
).on_conflict_do_nothing(index_elements=["location_id", "url_id", "user_id"])
await session.execute(statement)
# Delete all anonymous location annotations.
statement = delete(AnnotationLocationAnon).where(
Expand All @@ -84,8 +85,8 @@ async def migrate_record_type_annotations(self, session: AsyncSession) -> None:
self.user_id
).where(
AnnotationRecordTypeAnon.session_id == self.session_id
)
)
).distinct()
).on_conflict_do_nothing(index_elements=["url_id", "user_id"])
await session.execute(statement)
# Delete all anonymous record type annotations.
statement = delete(AnnotationRecordTypeAnon).where(
Expand All @@ -103,8 +104,8 @@ async def migrate_url_type_annotations(self, session: AsyncSession) -> None:
self.user_id
).where(
AnnotationURLTypeAnon.session_id == self.session_id
)
)
).distinct()
).on_conflict_do_nothing(index_elements=["url_id", "user_id"])
await session.execute(statement)
# Delete all anonymous url type annotations.
statement = delete(AnnotationURLTypeAnon).where(
Expand All @@ -121,8 +122,8 @@ async def migrate_name_annotations(self, session: AsyncSession) -> None:
self.user_id
).where(
AnnotationNameAnonEndorsement.session_id == self.session_id
)
)
).distinct()
).on_conflict_do_nothing(index_elements=["suggestion_id", "user_id"])
await session.execute(statement)
# Delete all anonymous name annotations.
statement = delete(AnnotationNameAnonEndorsement).where(
Expand Down