7b45942e39bb_add_api_key_auth_binding.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """add-api-key-auth-binding
  2. Revision ID: 7b45942e39bb
  3. Revises: 47cc7df8c4f3
  4. Create Date: 2024-05-14 07:31:29.702766
  5. """
  6. import sqlalchemy as sa
  7. from alembic import op
  8. import models.types
  9. # revision identifiers, used by Alembic.
  10. revision = '7b45942e39bb'
  11. down_revision = '4e99a8df00ff'
  12. branch_labels = None
  13. depends_on = None
  14. def upgrade():
  15. # ### commands auto generated by Alembic - please adjust! ###
  16. op.create_table('data_source_api_key_auth_bindings',
  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('category', sa.String(length=255), nullable=False),
  20. sa.Column('provider', sa.String(length=255), nullable=False),
  21. sa.Column('credentials', sa.Text(), nullable=True),
  22. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  23. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  24. sa.Column('disabled', sa.Boolean(), server_default=sa.text('false'), nullable=True),
  25. sa.PrimaryKeyConstraint('id', name='data_source_api_key_auth_binding_pkey')
  26. )
  27. with op.batch_alter_table('data_source_api_key_auth_bindings', schema=None) as batch_op:
  28. batch_op.create_index('data_source_api_key_auth_binding_provider_idx', ['provider'], unique=False)
  29. batch_op.create_index('data_source_api_key_auth_binding_tenant_id_idx', ['tenant_id'], unique=False)
  30. with op.batch_alter_table('data_source_bindings', schema=None) as batch_op:
  31. batch_op.drop_index('source_binding_tenant_id_idx')
  32. batch_op.drop_index('source_info_idx')
  33. op.rename_table('data_source_bindings', 'data_source_oauth_bindings')
  34. with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op:
  35. batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False)
  36. batch_op.create_index('source_info_idx', ['source_info'], unique=False, postgresql_using='gin')
  37. # ### end Alembic commands ###
  38. def downgrade():
  39. # ### commands auto generated by Alembic - please adjust! ###
  40. with op.batch_alter_table('data_source_oauth_bindings', schema=None) as batch_op:
  41. batch_op.drop_index('source_info_idx', postgresql_using='gin')
  42. batch_op.drop_index('source_binding_tenant_id_idx')
  43. op.rename_table('data_source_oauth_bindings', 'data_source_bindings')
  44. with op.batch_alter_table('data_source_bindings', schema=None) as batch_op:
  45. batch_op.create_index('source_info_idx', ['source_info'], unique=False)
  46. batch_op.create_index('source_binding_tenant_id_idx', ['tenant_id'], unique=False)
  47. with op.batch_alter_table('data_source_api_key_auth_bindings', schema=None) as batch_op:
  48. batch_op.drop_index('data_source_api_key_auth_binding_tenant_id_idx')
  49. batch_op.drop_index('data_source_api_key_auth_binding_provider_idx')
  50. op.drop_table('data_source_api_key_auth_bindings')
  51. # ### end Alembic commands ###