|
| 1 | +"""initial schema |
| 2 | +
|
| 3 | +Revision ID: 29f302f66e10 |
| 4 | +Revises: |
| 5 | +Create Date: 2026-09-24 08:35:31.183126 |
| 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 = '29f302f66e10' |
| 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('plan', sa.String(length=32), nullable=False), |
| 47 | + sa.Column('phone', sa.String(length=32), nullable=True), |
| 48 | + sa.Column('plan_points', sa.Integer(), nullable=False), |
| 49 | + sa.Column('pack_points', sa.Integer(), nullable=False), |
| 50 | + sa.Column('points_expire_at', sa.DateTime(timezone=True), nullable=True), |
| 51 | + sa.PrimaryKeyConstraint('id') |
| 52 | + ) |
| 53 | + with op.batch_alter_table('users', schema=None) as batch_op: |
| 54 | + batch_op.create_index(batch_op.f('ix_users_email'), ['email'], unique=True) |
| 55 | + |
| 56 | + op.create_table('conversations', |
| 57 | + sa.Column('id', sa.String(length=40), nullable=False), |
| 58 | + sa.Column('user_id', sa.String(length=40), nullable=False), |
| 59 | + sa.Column('title', sa.String(length=255), nullable=False), |
| 60 | + sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), |
| 61 | + sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False), |
| 62 | + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), |
| 63 | + sa.PrimaryKeyConstraint('id') |
| 64 | + ) |
| 65 | + with op.batch_alter_table('conversations', schema=None) as batch_op: |
| 66 | + batch_op.create_index(batch_op.f('ix_conversations_user_id'), ['user_id'], unique=False) |
| 67 | + |
| 68 | + op.create_table('secrets', |
| 69 | + sa.Column('id', sa.String(length=40), nullable=False), |
| 70 | + sa.Column('user_id', sa.String(length=40), nullable=False), |
| 71 | + sa.Column('name', sa.String(length=120), nullable=False), |
| 72 | + sa.Column('value_encrypted', sa.Text(), nullable=False), |
| 73 | + sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), |
| 74 | + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), |
| 75 | + sa.PrimaryKeyConstraint('id') |
| 76 | + ) |
| 77 | + with op.batch_alter_table('secrets', schema=None) as batch_op: |
| 78 | + batch_op.create_index(batch_op.f('ix_secrets_user_id'), ['user_id'], unique=False) |
| 79 | + |
| 80 | + op.create_table('usage_events', |
| 81 | + sa.Column('id', sa.String(length=40), nullable=False), |
| 82 | + sa.Column('user_id', sa.String(length=40), nullable=False), |
| 83 | + sa.Column('conversation_id', sa.String(length=40), nullable=False), |
| 84 | + sa.Column('run_id', sa.String(length=40), nullable=False), |
| 85 | + sa.Column('input_tokens', sa.Integer(), nullable=False), |
| 86 | + sa.Column('output_tokens', sa.Integer(), nullable=False), |
| 87 | + sa.Column('rounds', sa.Integer(), nullable=False), |
| 88 | + sa.Column('model', sa.String(length=120), nullable=False), |
| 89 | + sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), |
| 90 | + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), |
| 91 | + sa.PrimaryKeyConstraint('id') |
| 92 | + ) |
| 93 | + with op.batch_alter_table('usage_events', schema=None) as batch_op: |
| 94 | + batch_op.create_index(batch_op.f('ix_usage_events_conversation_id'), ['conversation_id'], unique=False) |
| 95 | + batch_op.create_index(batch_op.f('ix_usage_events_run_id'), ['run_id'], unique=False) |
| 96 | + batch_op.create_index(batch_op.f('ix_usage_events_user_id'), ['user_id'], unique=False) |
| 97 | + |
| 98 | + op.create_table('conversation_files', |
| 99 | + sa.Column('id', sa.String(length=40), nullable=False), |
| 100 | + sa.Column('conversation_id', sa.String(length=40), nullable=False), |
| 101 | + sa.Column('user_id', sa.String(length=40), nullable=False), |
| 102 | + sa.Column('filename', sa.String(length=255), nullable=False), |
| 103 | + sa.Column('stored_name', sa.String(length=255), nullable=False), |
| 104 | + sa.Column('size', sa.Integer(), nullable=False), |
| 105 | + sa.Column('path', sa.String(length=1024), nullable=False), |
| 106 | + sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), |
| 107 | + sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ), |
| 108 | + sa.PrimaryKeyConstraint('id') |
| 109 | + ) |
| 110 | + with op.batch_alter_table('conversation_files', schema=None) as batch_op: |
| 111 | + batch_op.create_index(batch_op.f('ix_conversation_files_conversation_id'), ['conversation_id'], unique=False) |
| 112 | + batch_op.create_index(batch_op.f('ix_conversation_files_user_id'), ['user_id'], unique=False) |
| 113 | + |
| 114 | + op.create_table('runs', |
| 115 | + sa.Column('id', sa.String(length=40), nullable=False), |
| 116 | + sa.Column('conversation_id', sa.String(length=40), nullable=False), |
| 117 | + sa.Column('prompt', sa.Text(), nullable=False), |
| 118 | + sa.Column('status', sa.String(length=16), nullable=False), |
| 119 | + sa.Column('answer', sa.Text(), nullable=False), |
| 120 | + sa.Column('events', sa.JSON(), nullable=False), |
| 121 | + sa.Column('error', sa.Text(), nullable=False), |
| 122 | + sa.Column('harness_run_id', sa.String(length=64), nullable=False), |
| 123 | + sa.Column('exit_code', sa.Integer(), nullable=True), |
| 124 | + sa.Column('cancelled', sa.Boolean(), nullable=False), |
| 125 | + sa.Column('duration_ms', sa.Integer(), nullable=False), |
| 126 | + sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), |
| 127 | + sa.Column('finished_at', sa.DateTime(timezone=True), nullable=True), |
| 128 | + sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ), |
| 129 | + sa.PrimaryKeyConstraint('id') |
| 130 | + ) |
| 131 | + with op.batch_alter_table('runs', schema=None) as batch_op: |
| 132 | + batch_op.create_index(batch_op.f('ix_runs_conversation_id'), ['conversation_id'], unique=False) |
| 133 | + batch_op.create_index(batch_op.f('ix_runs_status'), ['status'], unique=False) |
| 134 | + |
| 135 | + # ### end Alembic commands ### |
| 136 | + |
| 137 | + |
| 138 | +def downgrade() -> None: |
| 139 | + """Downgrade schema.""" |
| 140 | + # ### commands auto generated by Alembic - please adjust! ### |
| 141 | + with op.batch_alter_table('runs', schema=None) as batch_op: |
| 142 | + batch_op.drop_index(batch_op.f('ix_runs_status')) |
| 143 | + batch_op.drop_index(batch_op.f('ix_runs_conversation_id')) |
| 144 | + |
| 145 | + op.drop_table('runs') |
| 146 | + with op.batch_alter_table('conversation_files', schema=None) as batch_op: |
| 147 | + batch_op.drop_index(batch_op.f('ix_conversation_files_user_id')) |
| 148 | + batch_op.drop_index(batch_op.f('ix_conversation_files_conversation_id')) |
| 149 | + |
| 150 | + op.drop_table('conversation_files') |
| 151 | + with op.batch_alter_table('usage_events', schema=None) as batch_op: |
| 152 | + batch_op.drop_index(batch_op.f('ix_usage_events_user_id')) |
| 153 | + batch_op.drop_index(batch_op.f('ix_usage_events_run_id')) |
| 154 | + batch_op.drop_index(batch_op.f('ix_usage_events_conversation_id')) |
| 155 | + |
| 156 | + op.drop_table('usage_events') |
| 157 | + with op.batch_alter_table('secrets', schema=None) as batch_op: |
| 158 | + batch_op.drop_index(batch_op.f('ix_secrets_user_id')) |
| 159 | + |
| 160 | + op.drop_table('secrets') |
| 161 | + with op.batch_alter_table('conversations', schema=None) as batch_op: |
| 162 | + batch_op.drop_index(batch_op.f('ix_conversations_user_id')) |
| 163 | + |
| 164 | + op.drop_table('conversations') |
| 165 | + with op.batch_alter_table('users', schema=None) as batch_op: |
| 166 | + batch_op.drop_index(batch_op.f('ix_users_email')) |
| 167 | + |
| 168 | + op.drop_table('users') |
| 169 | + with op.batch_alter_table('sandboxes', schema=None) as batch_op: |
| 170 | + batch_op.drop_index(batch_op.f('ix_sandboxes_user_id')) |
| 171 | + batch_op.drop_index(batch_op.f('ix_sandboxes_status')) |
| 172 | + |
| 173 | + op.drop_table('sandboxes') |
| 174 | + # ### end Alembic commands ### |
0 commit comments