opencompletion.com/migrations/versions/190d5ef26e20_add_token_count_to_message.py
Russell Ballestrini f5df195e9b black and also set_language isn't "correct" anymore.
so it doesn't move the student on.

	modified:   app.py
	modified:   migrations/env.py
	modified:   migrations/versions/190d5ef26e20_add_token_count_to_message.py
	modified:   migrations/versions/a9e886c56482_create_room_table.py
	modified:   migrations/versions/d737de68d6fa_add_metadata_field_to_activitystate.py
	modified:   research/activity21.yaml
	modified:   research/guarded_ai.py
2024-08-10 17:00:52 -04:00

43 lines
1.1 KiB
Python

"""Add token_count to Message
Revision ID: 190d5ef26e20
Revises: a9e886c56482
Create Date: 2023-12-07 08:55:50.378439
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import Session
# revision identifiers, used by Alembic.
revision = "190d5ef26e20"
down_revision = "a9e886c56482"
branch_labels = None
depends_on = None
from app import Message
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("message", schema=None) as batch_op:
batch_op.add_column(sa.Column("token_count", sa.Integer(), nullable=True))
# Use this binding to connect to the database
bind = op.get_bind()
session = Session(bind=bind)
# Assuming the content column is not nullable and always has a value
messages = session.query(Message).all()
for message in messages:
message.count_tokens()
session.add(message)
session.commit()
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("message", schema=None) as batch_op:
batch_op.drop_column("token_count")