2024_11_22_0701-e19037032219_parent_child_index.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """parent-child-index
  2. Revision ID: e19037032219
  3. Revises: 01d6889832f7
  4. Create Date: 2024-11-22 07:01:17.550037
  5. """
  6. from alembic import op
  7. import models as models
  8. import sqlalchemy as sa
  9. # revision identifiers, used by Alembic.
  10. revision = 'e19037032219'
  11. down_revision = 'd7999dfa4aae'
  12. branch_labels = None
  13. depends_on = None
  14. def upgrade():
  15. # ### commands auto generated by Alembic - please adjust! ###
  16. op.create_table('child_chunks',
  17. sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  18. sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
  19. sa.Column('dataset_id', models.types.StringUUID(), nullable=False),
  20. sa.Column('document_id', models.types.StringUUID(), nullable=False),
  21. sa.Column('segment_id', models.types.StringUUID(), nullable=False),
  22. sa.Column('position', sa.Integer(), nullable=False),
  23. sa.Column('content', sa.Text(), nullable=False),
  24. sa.Column('word_count', sa.Integer(), nullable=False),
  25. sa.Column('index_node_id', sa.String(length=255), nullable=True),
  26. sa.Column('index_node_hash', sa.String(length=255), nullable=True),
  27. sa.Column('type', sa.String(length=255), server_default=sa.text("'automatic'::character varying"), nullable=False),
  28. sa.Column('created_by', models.types.StringUUID(), nullable=False),
  29. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  30. sa.Column('updated_by', models.types.StringUUID(), nullable=True),
  31. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  32. sa.Column('indexing_at', sa.DateTime(), nullable=True),
  33. sa.Column('completed_at', sa.DateTime(), nullable=True),
  34. sa.Column('error', sa.Text(), nullable=True),
  35. sa.PrimaryKeyConstraint('id', name='child_chunk_pkey')
  36. )
  37. with op.batch_alter_table('child_chunks', schema=None) as batch_op:
  38. batch_op.create_index('child_chunk_dataset_id_idx', ['tenant_id', 'dataset_id', 'document_id', 'segment_id', 'index_node_id'], unique=False)
  39. # ### end Alembic commands ###
  40. def downgrade():
  41. # ### commands auto generated by Alembic - please adjust! ###
  42. with op.batch_alter_table('child_chunks', schema=None) as batch_op:
  43. batch_op.drop_index('child_chunk_dataset_id_idx')
  44. op.drop_table('child_chunks')
  45. # ### end Alembic commands ###