forked from microsoft/semanticworkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate any remaining debugs (microsoft#209)
That have been missed between the manual migration and this one
- Loading branch information
1 parent
fa59fd7
commit 6827e45
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
workbench-service/migrations/versions/2024_11_05_015124_245baf258e11_double_check_debugs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""double-check debugs | ||
Revision ID: 245baf258e11 | ||
Revises: 5149c7fb5a32 | ||
Create Date: 2024-11-05 01:51:24.835708 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
import sqlmodel as sm | ||
from alembic import op | ||
from semantic_workbench_service import db | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "245baf258e11" | ||
down_revision: Union[str, None] = "5149c7fb5a32" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
bind = op.get_bind() | ||
max_sequence = bind.execute(sm.select(sm.func.max(db.ConversationMessage.sequence))).scalar() | ||
if max_sequence is not None: | ||
step = 100 | ||
for sequence_start in range(1, max_sequence + 1, step): | ||
sequence_end_exclusive = sequence_start + step | ||
|
||
results = bind.execute( | ||
sm.select(db.ConversationMessage.message_id, db.ConversationMessage.meta_data).where( | ||
db.ConversationMessage.sequence >= sequence_start, | ||
db.ConversationMessage.sequence < sequence_end_exclusive, | ||
) | ||
).fetchall() | ||
|
||
for message_id, meta_data in results: | ||
debug = meta_data.pop("debug", None) | ||
if not debug: | ||
continue | ||
|
||
bind.execute( | ||
sm.insert(db.ConversationMessageDebug).values( | ||
message_id=message_id, | ||
data=debug, | ||
) | ||
) | ||
|
||
bind.execute( | ||
sm.update(db.ConversationMessage) | ||
.where(db.ConversationMessage.message_id == message_id) | ||
.values(meta_data=meta_data) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
pass |