mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-31 02:28:09 +08:00
Merge pull request #14564 from jdavcs/dev_alembic_fix1
Don't query the database when running migrations in offline mode
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import logging
|
||||
|
||||
from alembic import op
|
||||
from alembic import (
|
||||
context,
|
||||
op,
|
||||
)
|
||||
from sqlalchemy import inspect
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -12,7 +15,19 @@ def drop_column(table_name, column_name):
|
||||
|
||||
|
||||
def column_exists(table_name, column_name):
|
||||
if is_offline_mode():
|
||||
msg = (
|
||||
"This script is being executed in offline mode and cannot connect to the database. "
|
||||
f"Therefore, `column_exists({table_name}, {column_name})` returns `False` by default."
|
||||
)
|
||||
log.debug(msg)
|
||||
return False
|
||||
bind = op.get_context().bind
|
||||
insp = inspect(bind)
|
||||
columns = insp.get_columns(table_name)
|
||||
return any(c["name"] == column_name for c in columns)
|
||||
|
||||
|
||||
def is_offline_mode():
|
||||
cmd_opts = context.config.cmd_opts
|
||||
return cmd_opts and cmd_opts.sql
|
||||
|
||||
Reference in New Issue
Block a user