Python/agent/alembic/versions/d52f1ee0f9c4_.py

106 lines
4.7 KiB
Python

"""empty message
Revision ID: d52f1ee0f9c4
Revises:
Create Date: 2026-08-11 14:59:37.246745
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'd52f1ee0f9c4'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('captcharecord',
sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('code', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('is_valid', sa.Boolean(), nullable=False),
sa.Column('is_verified', sa.Boolean(), nullable=False),
sa.Column('expired_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('email', 'code', 'expired_at')
)
with op.batch_alter_table('captcharecord', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_captcharecord_is_valid'), ['is_valid'], unique=False)
batch_op.create_index(batch_op.f('ix_captcharecord_is_verified'), ['is_verified'], unique=False)
op.create_table('conversationrecord',
sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('user_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('usage', sa.JSON(), nullable=False),
sa.Column('is_deleted', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('conversationrecord', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_conversationrecord_is_deleted'), ['is_deleted'], unique=False)
batch_op.create_index(batch_op.f('ix_conversationrecord_user_id'), ['user_id'], unique=False)
op.create_table('messagerecord',
sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('conversation_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('type', sa.Enum('USER_PROMPT', 'THINKING', 'TOOL_CALL', 'RESULT_OUTPUT', name='messagetype'), nullable=False),
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('messagerecord', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_messagerecord_conversation_id'), ['conversation_id'], unique=False)
op.create_table('runrecord',
sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('conversation_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('new_messages', sa.JSON(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('runrecord', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_runrecord_conversation_id'), ['conversation_id'], unique=False)
op.create_table('userrecord',
sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('userrecord', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_userrecord_email'), ['email'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('userrecord', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_userrecord_email'))
op.drop_table('userrecord')
with op.batch_alter_table('runrecord', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_runrecord_conversation_id'))
op.drop_table('runrecord')
with op.batch_alter_table('messagerecord', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_messagerecord_conversation_id'))
op.drop_table('messagerecord')
with op.batch_alter_table('conversationrecord', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_conversationrecord_user_id'))
batch_op.drop_index(batch_op.f('ix_conversationrecord_is_deleted'))
op.drop_table('conversationrecord')
with op.batch_alter_table('captcharecord', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_captcharecord_is_verified'))
batch_op.drop_index(batch_op.f('ix_captcharecord_is_valid'))
op.drop_table('captcharecord')
# ### end Alembic commands ###