Skip to content

Commit e540ae7

Browse files
authored
Create af891083abbd_baseline_schema.py
1 parent ff2b1fa commit e540ae7

1 file changed

Lines changed: 180 additions & 0 deletions

File tree

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
"""baseline schema
2+
3+
Revision ID: af891083abbd
4+
Revises:
5+
Create Date: 2026-09-29 09:31:33.099978
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = 'af891083abbd'
16+
down_revision: Union[str, Sequence[str], None] = None
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
"""Upgrade schema."""
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.create_table('sandboxes',
25+
sa.Column('id', sa.String(length=40), nullable=False),
26+
sa.Column('runner_id', sa.String(length=32), nullable=False),
27+
sa.Column('user_id', sa.String(length=40), nullable=False),
28+
sa.Column('conversation_id', sa.String(length=40), nullable=False),
29+
sa.Column('spec', sa.JSON(), nullable=False),
30+
sa.Column('status', sa.String(length=16), nullable=False),
31+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
32+
sa.Column('last_used_at', sa.DateTime(timezone=True), nullable=False),
33+
sa.PrimaryKeyConstraint('id')
34+
)
35+
with op.batch_alter_table('sandboxes', schema=None) as batch_op:
36+
batch_op.create_index(batch_op.f('ix_sandboxes_status'), ['status'], unique=False)
37+
batch_op.create_index(batch_op.f('ix_sandboxes_user_id'), ['user_id'], unique=False)
38+
39+
op.create_table('users',
40+
sa.Column('id', sa.String(length=40), nullable=False),
41+
sa.Column('email', sa.String(length=255), nullable=False),
42+
sa.Column('password_hash', sa.String(length=255), nullable=False),
43+
sa.Column('is_active', sa.Boolean(), nullable=False),
44+
sa.Column('is_admin', sa.Boolean(), nullable=False),
45+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
46+
sa.Column('token_version', sa.Integer(), nullable=False),
47+
sa.Column('plan', sa.String(length=32), nullable=False),
48+
sa.Column('phone', sa.String(length=32), nullable=True),
49+
sa.Column('plan_points', sa.Integer(), nullable=False),
50+
sa.Column('pack_points', sa.Integer(), nullable=False),
51+
sa.Column('points_expire_at', sa.DateTime(timezone=True), nullable=True),
52+
sa.PrimaryKeyConstraint('id')
53+
)
54+
with op.batch_alter_table('users', schema=None) as batch_op:
55+
batch_op.create_index(batch_op.f('ix_users_email'), ['email'], unique=True)
56+
57+
op.create_table('conversations',
58+
sa.Column('id', sa.String(length=40), nullable=False),
59+
sa.Column('user_id', sa.String(length=40), nullable=False),
60+
sa.Column('title', sa.String(length=255), nullable=False),
61+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
62+
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
63+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
64+
sa.PrimaryKeyConstraint('id')
65+
)
66+
with op.batch_alter_table('conversations', schema=None) as batch_op:
67+
batch_op.create_index(batch_op.f('ix_conversations_user_id'), ['user_id'], unique=False)
68+
69+
op.create_table('secrets',
70+
sa.Column('id', sa.String(length=40), nullable=False),
71+
sa.Column('user_id', sa.String(length=40), nullable=False),
72+
sa.Column('name', sa.String(length=120), nullable=False),
73+
sa.Column('value_encrypted', sa.Text(), nullable=False),
74+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
75+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
76+
sa.PrimaryKeyConstraint('id')
77+
)
78+
with op.batch_alter_table('secrets', schema=None) as batch_op:
79+
batch_op.create_index(batch_op.f('ix_secrets_user_id'), ['user_id'], unique=False)
80+
81+
op.create_table('usage_events',
82+
sa.Column('id', sa.String(length=40), nullable=False),
83+
sa.Column('user_id', sa.String(length=40), nullable=False),
84+
sa.Column('conversation_id', sa.String(length=40), nullable=False),
85+
sa.Column('run_id', sa.String(length=40), nullable=False),
86+
sa.Column('input_tokens', sa.Integer(), nullable=False),
87+
sa.Column('output_tokens', sa.Integer(), nullable=False),
88+
sa.Column('rounds', sa.Integer(), nullable=False),
89+
sa.Column('model', sa.String(length=120), nullable=False),
90+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
91+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
92+
sa.PrimaryKeyConstraint('id')
93+
)
94+
with op.batch_alter_table('usage_events', schema=None) as batch_op:
95+
batch_op.create_index(batch_op.f('ix_usage_events_conversation_id'), ['conversation_id'], unique=False)
96+
batch_op.create_index(batch_op.f('ix_usage_events_run_id'), ['run_id'], unique=False)
97+
batch_op.create_index(batch_op.f('ix_usage_events_user_id'), ['user_id'], unique=False)
98+
99+
op.create_table('conversation_files',
100+
sa.Column('id', sa.String(length=40), nullable=False),
101+
sa.Column('conversation_id', sa.String(length=40), nullable=False),
102+
sa.Column('user_id', sa.String(length=40), nullable=False),
103+
sa.Column('filename', sa.String(length=255), nullable=False),
104+
sa.Column('stored_name', sa.String(length=255), nullable=False),
105+
sa.Column('size', sa.Integer(), nullable=False),
106+
sa.Column('path', sa.String(length=1024), nullable=False),
107+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
108+
sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ),
109+
sa.PrimaryKeyConstraint('id')
110+
)
111+
with op.batch_alter_table('conversation_files', schema=None) as batch_op:
112+
batch_op.create_index(batch_op.f('ix_conversation_files_conversation_id'), ['conversation_id'], unique=False)
113+
batch_op.create_index(batch_op.f('ix_conversation_files_user_id'), ['user_id'], unique=False)
114+
115+
op.create_table('runs',
116+
sa.Column('id', sa.String(length=40), nullable=False),
117+
sa.Column('conversation_id', sa.String(length=40), nullable=False),
118+
sa.Column('prompt', sa.Text(), nullable=False),
119+
sa.Column('status', sa.String(length=16), nullable=False),
120+
sa.Column('answer', sa.Text(), nullable=False),
121+
sa.Column('events', sa.JSON(), nullable=False),
122+
sa.Column('error', sa.Text(), nullable=False),
123+
sa.Column('harness_run_id', sa.String(length=64), nullable=False),
124+
sa.Column('owner_instance', sa.String(length=64), nullable=True),
125+
sa.Column('exit_code', sa.Integer(), nullable=True),
126+
sa.Column('cancelled', sa.Boolean(), nullable=False),
127+
sa.Column('duration_ms', sa.Integer(), nullable=False),
128+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
129+
sa.Column('finished_at', sa.DateTime(timezone=True), nullable=True),
130+
sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ),
131+
sa.PrimaryKeyConstraint('id')
132+
)
133+
with op.batch_alter_table('runs', schema=None) as batch_op:
134+
batch_op.create_index(batch_op.f('ix_runs_conversation_id'), ['conversation_id'], unique=False)
135+
batch_op.create_index(batch_op.f('ix_runs_owner_instance'), ['owner_instance'], unique=False)
136+
batch_op.create_index(batch_op.f('ix_runs_status'), ['status'], unique=False)
137+
batch_op.create_index('uq_one_running_run_per_conversation', ['conversation_id'], unique=True, sqlite_where=sa.text("status = 'running'"), postgresql_where=sa.text("status = 'running'"))
138+
139+
# ### end Alembic commands ###
140+
141+
142+
def downgrade() -> None:
143+
"""Downgrade schema."""
144+
# ### commands auto generated by Alembic - please adjust! ###
145+
with op.batch_alter_table('runs', schema=None) as batch_op:
146+
batch_op.drop_index('uq_one_running_run_per_conversation', sqlite_where=sa.text("status = 'running'"), postgresql_where=sa.text("status = 'running'"))
147+
batch_op.drop_index(batch_op.f('ix_runs_status'))
148+
batch_op.drop_index(batch_op.f('ix_runs_owner_instance'))
149+
batch_op.drop_index(batch_op.f('ix_runs_conversation_id'))
150+
151+
op.drop_table('runs')
152+
with op.batch_alter_table('conversation_files', schema=None) as batch_op:
153+
batch_op.drop_index(batch_op.f('ix_conversation_files_user_id'))
154+
batch_op.drop_index(batch_op.f('ix_conversation_files_conversation_id'))
155+
156+
op.drop_table('conversation_files')
157+
with op.batch_alter_table('usage_events', schema=None) as batch_op:
158+
batch_op.drop_index(batch_op.f('ix_usage_events_user_id'))
159+
batch_op.drop_index(batch_op.f('ix_usage_events_run_id'))
160+
batch_op.drop_index(batch_op.f('ix_usage_events_conversation_id'))
161+
162+
op.drop_table('usage_events')
163+
with op.batch_alter_table('secrets', schema=None) as batch_op:
164+
batch_op.drop_index(batch_op.f('ix_secrets_user_id'))
165+
166+
op.drop_table('secrets')
167+
with op.batch_alter_table('conversations', schema=None) as batch_op:
168+
batch_op.drop_index(batch_op.f('ix_conversations_user_id'))
169+
170+
op.drop_table('conversations')
171+
with op.batch_alter_table('users', schema=None) as batch_op:
172+
batch_op.drop_index(batch_op.f('ix_users_email'))
173+
174+
op.drop_table('users')
175+
with op.batch_alter_table('sandboxes', schema=None) as batch_op:
176+
batch_op.drop_index(batch_op.f('ix_sandboxes_user_id'))
177+
batch_op.drop_index(batch_op.f('ix_sandboxes_status'))
178+
179+
op.drop_table('sandboxes')
180+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)