File size: 5,289 Bytes
7644eac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""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 ###