Skip to content
Merged
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: 22.10.0
hooks:
- id: black
language_version: python3.12
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
Expand Down
9 changes: 9 additions & 0 deletions app/repositories/implementations/analysis_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ async def create(self, analysis: Analysis) -> Analysis:

return self._to_domain(model)

async def update_stream_safe(self, analysis: Analysis) -> Analysis:
"""Update with proper async handling."""
db_obj = self._to_model(analysis)
merged_obj = await self._session.merge(db_obj)
await self._session.commit()
self._session.expunge(merged_obj)

return analysis

async def get_with_relations(self, analysis_id: UUID) -> Optional[Analysis]:
"""Get analysis with related sources and feedback."""
query = (
Expand Down
2 changes: 1 addition & 1 deletion app/services/analysis_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def _generate_analysis(
log_data = LogProbsData(tokens=analysis_text, probs=log_probs)
current_analysis.log_probs = log_data

updated_analysis = await self._analysis_repo.update(current_analysis)
updated_analysis = await self._analysis_repo.update_stream_safe(current_analysis)

yield {
"type": "analysis_complete",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
depends_on:
misinformation_mitigation_db:
condition: service_healthy
command: [ "/app/docker-entrypoint.sh" ]
command: ["sh","/app/docker-entrypoint.sh" ]

misinformation_mitigation_db:
container_name: misinformation_mitigation_db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Revision ID: 2abb9260c6fd
Revises: b2122b621d0a
Create Date: 2025-04-10 21:03:31.820890

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "2abb9260c6fd"
Expand All @@ -18,48 +18,65 @@


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# Existing migration: add the new column
op.add_column("claims", sa.Column("batch_user_id", sa.Text(), nullable=True))
# ### end Alembic commands ###

# Existing migration: create the new table
op.execute(
"""
CREATE TABLE social_media_clients (
auth0_id VARCHAR PRIMARY KEY REFERENCES users(auth0_id),
platform TEXT NOT NULL
auth0_id VARCHAR PRIMARY KEY REFERENCES users(auth0_id),
platform TEXT NOT NULL
);
"""
"""
)

# The change makes the migration safe by preventing inserts into social_media_clients unless the referenced user already exists in users.

# New: only insert BlueSky client if the matching user already exists
op.execute(
"""
INSERT INTO social_media_clients (auth0_id, platform)
VALUES ('I1eyLfAX26wlOMiY4n5SxWOsWrSNXLWU@clients', 'BlueSky');
"""
SELECT 'I1eyLfAX26wlOMiY4n5SxWOsWrSNXLWU@clients', 'BlueSky'
WHERE EXISTS (
SELECT 1 FROM users
WHERE auth0_id = 'I1eyLfAX26wlOMiY4n5SxWOsWrSNXLWU@clients'
);
"""
)

# New: only insert X client if the matching user already exists
op.execute(
"""
INSERT INTO social_media_clients (auth0_id, platform)
VALUES ('K46Fnu6E21BG0x3KfNknffbKdTbOHlzw@clients', 'X');
"""
SELECT 'K46Fnu6E21BG0x3KfNknffbKdTbOHlzw@clients', 'X'
WHERE EXISTS (
SELECT 1 FROM users
WHERE auth0_id = 'K46Fnu6E21BG0x3KfNknffbKdTbOHlzw@clients'
);
"""
)

# New: only insert Reddit client if the matching user already exists
op.execute(
"""
INSERT INTO social_media_clients (auth0_id, platform)
VALUES ('GbaexhSrWJnbX19M4HYuGH87ROyzwJne@clients', 'Reddit');
"""
SELECT 'GbaexhSrWJnbX19M4HYuGH87ROyzwJne@clients', 'Reddit'
WHERE EXISTS (
SELECT 1 FROM users
WHERE auth0_id = 'GbaexhSrWJnbX19M4HYuGH87ROyzwJne@clients'
);
"""
)


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("claims", "batch_user_id")
# ### end Alembic commands ###

# Existing migration: drop the social_media_clients table
op.execute(
"""
DROP TABLE social_media_clients;
"""
"""
)

# Existing migration: remove the batch_user_id column
op.drop_column("claims", "batch_user_id")
Loading