ai-learning-path-generator / migrations /versions /12d5dfb6fd16_sync_users_table.py
“shubhamdhamal”
Deploy Flask app with Docker
7644eac
"""sync users table
Revision ID: 12d5dfb6fd16
Revises: 39d22a91999a
Create Date: 2025-10-01 21:25:39.871657
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '12d5dfb6fd16'
down_revision = '39d22a91999a'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('chat_messages',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('learning_path_id', sa.String(length=36), nullable=True),
sa.Column('message', sa.Text(), nullable=False),
sa.Column('role', sa.String(length=20), nullable=False),
sa.Column('intent', sa.String(length=50), nullable=True),
sa.Column('entities', sa.JSON(), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('tokens_used', sa.Integer(), nullable=True),
sa.Column('response_time_ms', sa.Integer(), nullable=True),
sa.Column('session_id', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['learning_path_id'], ['user_learning_paths.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('chat_messages', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_chat_messages_session_id'), ['session_id'], unique=False)
batch_op.create_index(batch_op.f('ix_chat_messages_timestamp'), ['timestamp'], unique=False)
op.create_table('conversation_sessions',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('learning_path_id', sa.String(length=36), nullable=True),
sa.Column('started_at', sa.DateTime(), nullable=True),
sa.Column('last_activity_at', sa.DateTime(), nullable=True),
sa.Column('ended_at', sa.DateTime(), nullable=True),
sa.Column('summary', sa.Text(), nullable=True),
sa.Column('message_count', sa.Integer(), nullable=True),
sa.Column('total_tokens_used', sa.Integer(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['learning_path_id'], ['user_learning_paths.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('conversation_sessions', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_conversation_sessions_started_at'), ['started_at'], unique=False)
op.create_table('path_modifications',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('learning_path_id', sa.String(length=36), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('chat_message_id', sa.Integer(), nullable=True),
sa.Column('modification_type', sa.String(length=50), nullable=False),
sa.Column('target_path', sa.String(length=200), nullable=True),
sa.Column('change_description', sa.Text(), nullable=False),
sa.Column('old_value', sa.JSON(), nullable=True),
sa.Column('new_value', sa.JSON(), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('is_reverted', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['chat_message_id'], ['chat_messages.id'], ),
sa.ForeignKeyConstraint(['learning_path_id'], ['user_learning_paths.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('path_modifications', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_path_modifications_timestamp'), ['timestamp'], unique=False)
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('last_seen', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('registration_source', sa.String(length=20), nullable=True))
batch_op.add_column(sa.Column('login_count', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('display_name', sa.String(length=100), nullable=True))
batch_op.add_column(sa.Column('bio', sa.Text(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_column('bio')
batch_op.drop_column('display_name')
batch_op.drop_column('login_count')
batch_op.drop_column('registration_source')
batch_op.drop_column('last_seen')
with op.batch_alter_table('path_modifications', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_path_modifications_timestamp'))
op.drop_table('path_modifications')
with op.batch_alter_table('conversation_sessions', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_conversation_sessions_started_at'))
op.drop_table('conversation_sessions')
with op.batch_alter_table('chat_messages', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_chat_messages_timestamp'))
batch_op.drop_index(batch_op.f('ix_chat_messages_session_id'))
op.drop_table('chat_messages')
# ### end Alembic commands ###