20260427_0002_add_tool_credentials.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """add tool credentials
  2. Revision ID: 20260427_0002
  3. Revises: 20260422_0001
  4. Create Date: 2026-04-27 00:00:00
  5. """
  6. from collections.abc import Sequence
  7. from alembic import op
  8. import sqlalchemy as sa
  9. revision: str = "20260427_0002"
  10. down_revision: str | None = "20260422_0001"
  11. branch_labels: Sequence[str] | None = None
  12. depends_on: Sequence[str] | None = None
  13. def upgrade() -> None:
  14. op.create_table(
  15. "tool_credential",
  16. sa.Column("name", sa.String(length=128), nullable=False),
  17. sa.Column("credential_type", sa.String(length=64), nullable=False),
  18. sa.Column("encrypted_payload_text", sa.Text(), nullable=False),
  19. sa.Column("secret_fingerprint", sa.String(length=64), nullable=False),
  20. sa.Column("encryption_algorithm", sa.String(length=64), nullable=False),
  21. sa.Column("metadata_json", sa.JSON(), nullable=True),
  22. sa.Column("id", sa.String(length=36), nullable=False),
  23. sa.Column("tenant_id", sa.String(length=36), nullable=False),
  24. sa.Column("created_by", sa.String(length=36), nullable=True),
  25. sa.Column("updated_by", sa.String(length=36), nullable=True),
  26. sa.Column("created_time", sa.DateTime(), nullable=False),
  27. sa.Column("updated_time", sa.DateTime(), nullable=False),
  28. sa.Column("deleted_time", sa.DateTime(), nullable=True),
  29. sa.Column("version", sa.Integer(), nullable=False),
  30. sa.PrimaryKeyConstraint("id"),
  31. )
  32. op.create_index("ix_tool_credential_tenant_id", "tool_credential", ["tenant_id"])
  33. op.create_index(
  34. "ix_tool_credential_secret_fingerprint",
  35. "tool_credential",
  36. ["secret_fingerprint"],
  37. )
  38. def downgrade() -> None:
  39. op.drop_index("ix_tool_credential_secret_fingerprint", table_name="tool_credential")
  40. op.drop_index("ix_tool_credential_tenant_id", table_name="tool_credential")
  41. op.drop_table("tool_credential")