From 9fc3601df8cecdd87cad098c7ae3789da22720cf Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Mon, 23 Dec 2024 19:53:07 +0100 Subject: [PATCH] fix: Fix parallel execution of alembic with PostgreSQL (#5408) Fix parallel execution of alembic with PostgreSQL --- src/backend/base/langflow/alembic/__init__.py | 0 src/backend/base/langflow/alembic/env.py | 6 ++++-- src/backend/base/pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/backend/base/langflow/alembic/__init__.py diff --git a/src/backend/base/langflow/alembic/__init__.py b/src/backend/base/langflow/alembic/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/backend/base/langflow/alembic/env.py b/src/backend/base/langflow/alembic/env.py index d4e130649..f3e107eee 100644 --- a/src/backend/base/langflow/alembic/env.py +++ b/src/backend/base/langflow/alembic/env.py @@ -1,9 +1,8 @@ from logging.config import fileConfig from alembic import context -from sqlalchemy import engine_from_config, pool +from sqlalchemy import engine_from_config, pool, text -from langflow.services.database.models import * from langflow.services.database.service import SQLModel # this is the Alembic Config object, which provides @@ -69,6 +68,9 @@ def run_migrations_online() -> None: context.configure(connection=connection, target_metadata=target_metadata, render_as_batch=True) with context.begin_transaction(): + if connection.dialect.name == "postgresql": + connection.execute(text("SET LOCAL lock_timeout = '60s';")) + connection.execute(text("SELECT pg_advisory_xact_lock(112233);")) context.run_migrations() diff --git a/src/backend/base/pyproject.toml b/src/backend/base/pyproject.toml index 57bc691e7..e0afec2be 100644 --- a/src/backend/base/pyproject.toml +++ b/src/backend/base/pyproject.toml @@ -24,7 +24,7 @@ ignore_missing_imports = true [tool.ruff] target-version = "py310" -exclude = ["langflow/alembic"] +exclude = ["langflow/alembic/versions"] line-length = 120 [tool.ruff.lint]