e1901f623fd0_add_annotation_reply.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """add-annotation-reply
  2. Revision ID: e1901f623fd0
  3. Revises: fca025d3b60f
  4. Create Date: 2023-12-12 06:58:41.054544
  5. """
  6. import sqlalchemy as sa
  7. from alembic import op
  8. from sqlalchemy.dialects import postgresql
  9. # revision identifiers, used by Alembic.
  10. revision = 'e1901f623fd0'
  11. down_revision = 'fca025d3b60f'
  12. branch_labels = None
  13. depends_on = None
  14. def upgrade():
  15. # ### commands auto generated by Alembic - please adjust! ###
  16. op.create_table('app_annotation_hit_histories',
  17. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  18. sa.Column('app_id', postgresql.UUID(), nullable=False),
  19. sa.Column('annotation_id', postgresql.UUID(), nullable=False),
  20. sa.Column('source', sa.Text(), nullable=False),
  21. sa.Column('question', sa.Text(), nullable=False),
  22. sa.Column('account_id', postgresql.UUID(), nullable=False),
  23. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  24. sa.PrimaryKeyConstraint('id', name='app_annotation_hit_histories_pkey')
  25. )
  26. with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op:
  27. batch_op.create_index('app_annotation_hit_histories_account_idx', ['account_id'], unique=False)
  28. batch_op.create_index('app_annotation_hit_histories_annotation_idx', ['annotation_id'], unique=False)
  29. batch_op.create_index('app_annotation_hit_histories_app_idx', ['app_id'], unique=False)
  30. with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
  31. batch_op.add_column(sa.Column('annotation_reply', sa.Text(), nullable=True))
  32. with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
  33. batch_op.add_column(sa.Column('type', sa.String(length=40), server_default=sa.text("'dataset'::character varying"), nullable=False))
  34. with op.batch_alter_table('message_annotations', schema=None) as batch_op:
  35. batch_op.add_column(sa.Column('question', sa.Text(), nullable=True))
  36. batch_op.add_column(sa.Column('hit_count', sa.Integer(), server_default=sa.text('0'), nullable=False))
  37. batch_op.alter_column('conversation_id',
  38. existing_type=postgresql.UUID(),
  39. nullable=True)
  40. batch_op.alter_column('message_id',
  41. existing_type=postgresql.UUID(),
  42. nullable=True)
  43. # ### end Alembic commands ###
  44. def downgrade():
  45. # ### commands auto generated by Alembic - please adjust! ###
  46. with op.batch_alter_table('message_annotations', schema=None) as batch_op:
  47. batch_op.alter_column('message_id',
  48. existing_type=postgresql.UUID(),
  49. nullable=False)
  50. batch_op.alter_column('conversation_id',
  51. existing_type=postgresql.UUID(),
  52. nullable=False)
  53. batch_op.drop_column('hit_count')
  54. batch_op.drop_column('question')
  55. with op.batch_alter_table('dataset_collection_bindings', schema=None) as batch_op:
  56. batch_op.drop_column('type')
  57. with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
  58. batch_op.drop_column('annotation_reply')
  59. with op.batch_alter_table('app_annotation_hit_histories', schema=None) as batch_op:
  60. batch_op.drop_index('app_annotation_hit_histories_app_idx')
  61. batch_op.drop_index('app_annotation_hit_histories_annotation_idx')
  62. batch_op.drop_index('app_annotation_hit_histories_account_idx')
  63. op.drop_table('app_annotation_hit_histories')
  64. # ### end Alembic commands ###