Skip to content

Commit fd991ce

Browse files
committed
modified runtime_migration.py
1 parent 5967b77 commit fd991ce

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

src/backend/base/langflow/services/database/runtime_migrations.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,57 @@ def _drop_legacy_message_context_id(connection: Connection) -> None:
5757
logger.exception("Failed to drop legacy context_id column from message table")
5858
raise
5959

60+
def _ensure_folder_auth_settings_column(connection: Connection) -> None:
61+
"""
62+
Ensure the `folder.auth_settings` column matches the ORM model definition.
63+
64+
- If the Folder model defines `auth_settings` and the column is missing,
65+
it will be added with type JSON and default NULL.
66+
- If the Folder model no longer defines `auth_settings` but it exists
67+
in the table, it will be dropped.
68+
- Safe to run multiple times (idempotent).
69+
"""
70+
71+
# Import your Folder ORM model — adjust path if needed
72+
try:
73+
from langflow.services.database.models.folder.model import Folder # <-- change if your Folder model lives elsewhere
74+
except ImportError:
75+
logger.warning("Folder model could not be imported; skipping folder schema sync")
76+
return
77+
78+
inspector = inspect(connection)
79+
80+
# Skip if folder table doesn't exist
81+
if "folder" not in inspector.get_table_names():
82+
return
83+
84+
# Check current DB columns
85+
existing_columns = {col["name"] for col in inspector.get_columns("folder")}
86+
has_auth_settings_in_db = "auth_settings" in existing_columns
87+
88+
# Check if ORM model expects the column
89+
expected_by_model = any(c.name == "auth_settings" for c in Folder.__table__.columns)
90+
91+
try:
92+
if expected_by_model and not has_auth_settings_in_db:
93+
logger.info("Adding missing auth_settings column to folder table (model expects it)")
94+
connection.execute(
95+
text('ALTER TABLE "folder" ADD COLUMN auth_settings JSON DEFAULT NULL')
96+
)
97+
98+
elif not expected_by_model and has_auth_settings_in_db:
99+
logger.info("Dropping extra auth_settings column from folder table (model no longer defines it)")
100+
connection.execute(
101+
text('ALTER TABLE "folder" DROP COLUMN IF EXISTS auth_settings')
102+
)
103+
104+
except Exception:
105+
logger.exception("Failed to sync auth_settings column in folder table")
106+
raise
60107

61108
_RUNTIME_MIGRATIONS: Final[tuple[RuntimeMigration, ...]] = (
62109
_drop_legacy_message_context_id,
110+
_ensure_folder_auth_settings_column,
63111
)
64112

65113

0 commit comments

Comments
 (0)