007_add_ldap_config.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """Add ldap_config table
  2. Revision ID: 007_add_ldap_config
  3. Revises: 006_add_user_restrictions
  4. Create Date: 2026-04-12 00:00:00.000000
  5. """
  6. from collections.abc import Sequence
  7. import sqlalchemy as sa
  8. from sqlalchemy import inspect
  9. from alembic import op
  10. # revision identifiers, used by Alembic.
  11. revision: str = "007_add_ldap_config"
  12. down_revision: str | None = "006_add_user_restrictions"
  13. branch_labels: str | Sequence[str] | None = None
  14. depends_on: str | Sequence[str] | None = None
  15. def upgrade() -> None:
  16. """Create ldap_config table."""
  17. conn = op.get_bind()
  18. inspector = inspect(conn)
  19. if not inspector.has_table("ldap_config"):
  20. op.create_table(
  21. "ldap_config",
  22. sa.Column("id", sa.Integer(), nullable=False),
  23. sa.Column("host", sa.String(length=255), nullable=False, server_default=""),
  24. sa.Column("port", sa.Integer(), nullable=False, server_default="389"),
  25. sa.Column("use_ssl", sa.Integer(), nullable=False, server_default="0"),
  26. sa.Column(
  27. "auth_type",
  28. sa.String(length=20),
  29. nullable=False,
  30. server_default="SIMPLE",
  31. ),
  32. sa.Column(
  33. "bind_dn", sa.String(length=512), nullable=False, server_default=""
  34. ),
  35. sa.Column(
  36. "bind_password",
  37. sa.String(length=512),
  38. nullable=False,
  39. server_default="",
  40. ),
  41. sa.Column(
  42. "base_dn", sa.String(length=512), nullable=False, server_default=""
  43. ),
  44. sa.Column("created_at", sa.DateTime(), nullable=False),
  45. sa.Column("updated_at", sa.DateTime(), nullable=True),
  46. sa.PrimaryKeyConstraint("id"),
  47. )
  48. else:
  49. print("Skipping creation of 'ldap_config' because it already exists")
  50. def downgrade() -> None:
  51. """Drop ldap_config table."""
  52. conn = op.get_bind()
  53. inspector = inspect(conn)
  54. if inspector.has_table("ldap_config"):
  55. op.drop_table("ldap_config")
  56. else:
  57. print("Skipping drop of 'ldap_config' because it does not exist")