Bläddra i källkod

feat: add encryption_key column to LdapConfig model and create migration script

Manuel 7 månader sedan
förälder
incheckning
b48ec66e22
2 ändrade filer med 52 tillägg och 0 borttagningar
  1. 51 0
      alembic/versions/008_add_ldap_encryption_key.py
  2. 1 0
      database/models/models.py

+ 51 - 0
alembic/versions/008_add_ldap_encryption_key.py

@@ -0,0 +1,51 @@
+"""Add encryption key column to ldap_config
+
+Revision ID: 008_add_ldap_encryption_key
+Revises: 007_add_ldap_config
+Create Date: 2026-04-12 00:30:00.000000
+
+"""
+
+from collections.abc import Sequence
+
+import sqlalchemy as sa
+from sqlalchemy import inspect
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision: str = "008_add_ldap_encryption_key"
+down_revision: str | None = "007_add_ldap_config"
+branch_labels: str | Sequence[str] | None = None
+depends_on: str | Sequence[str] | None = None
+
+
+def upgrade() -> None:
+    conn = op.get_bind()
+    inspector = inspect(conn)
+
+    if inspector.has_table("ldap_config"):
+        columns = [col["name"] for col in inspector.get_columns("ldap_config")]
+        if "encryption_key" not in columns:
+            op.add_column(
+                "ldap_config",
+                sa.Column("encryption_key", sa.String(length=512), nullable=True),
+            )
+        else:
+            print("Skipping creation of 'encryption_key' because it already exists")
+    else:
+        print("Skipping alter of 'ldap_config' because table does not exist")
+
+
+def downgrade() -> None:
+    conn = op.get_bind()
+    inspector = inspect(conn)
+
+    if inspector.has_table("ldap_config"):
+        columns = [col["name"] for col in inspector.get_columns("ldap_config")]
+        if "encryption_key" in columns:
+            op.drop_column("ldap_config", "encryption_key")
+        else:
+            print("Skipping drop of 'encryption_key' because it does not exist")
+    else:
+        print("Skipping drop of 'encryption_key' because table does not exist")

+ 1 - 0
database/models/models.py

@@ -208,6 +208,7 @@ class LdapConfig(Base):
     auth_type = Column(String(20), nullable=False, default="SIMPLE")  # SIMPLE | NTLM
     bind_dn = Column(String(512), nullable=False, default="")
     bind_password = Column(String(512), nullable=False, default="")
+    encryption_key = Column(String(512), nullable=True)
     base_dn = Column(String(512), nullable=False, default="")
     created_at = Column(DateTime, default=datetime.now, nullable=False)
     updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)