fix: Fix parallel execution of alembic with SQlite (#5404)
Fix parallel execution of alembic with SQlite
This commit is contained in:
parent
2ce33d41a8
commit
870aedf74e
1 changed files with 21 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ from logging.config import fileConfig
|
|||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool, text
|
||||
from sqlalchemy.event import listen
|
||||
|
||||
from langflow.services.database.service import SQLModel
|
||||
|
||||
|
|
@ -51,6 +52,21 @@ def run_migrations_offline() -> None:
|
|||
context.run_migrations()
|
||||
|
||||
|
||||
def _sqlite_do_connect(
|
||||
dbapi_connection,
|
||||
connection_record, # noqa: ARG001
|
||||
):
|
||||
# disable pysqlite's emitting of the BEGIN statement entirely.
|
||||
# also stops it from emitting COMMIT before any DDL.
|
||||
dbapi_connection.isolation_level = None
|
||||
|
||||
|
||||
def _sqlite_do_begin(conn):
|
||||
# emit our own BEGIN
|
||||
conn.exec_driver_sql("PRAGMA busy_timeout = 60000")
|
||||
conn.exec_driver_sql("BEGIN EXCLUSIVE")
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
|
|
@ -64,6 +80,11 @@ def run_migrations_online() -> None:
|
|||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
if connectable.dialect.name == "sqlite":
|
||||
# See https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl
|
||||
listen(connectable, "connect", _sqlite_do_connect)
|
||||
listen(connectable, "begin", _sqlite_do_begin)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata, render_as_batch=True)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue