Specifically load a plugin's alembic_version from the database (#2170)

* Specifically load a plugin's alembic_version from the database
This commit is contained in:
Kevin Chung
2022-08-23 16:05:51 -04:00
committed by GitHub
parent 09f58705a3
commit 541b3f5570

View File

@@ -8,7 +8,7 @@ from alembic.script import ScriptDirectory
from flask import current_app from flask import current_app
from sqlalchemy import create_engine, pool from sqlalchemy import create_engine, pool
from CTFd.utils import get_config, set_config from CTFd.utils import _get_config, set_config
def current(plugin_name=None): def current(plugin_name=None):
@@ -20,7 +20,11 @@ def current(plugin_name=None):
caller_path = caller_info[0] caller_path = caller_info[0]
plugin_name = os.path.basename(os.path.dirname(caller_path)) plugin_name = os.path.basename(os.path.dirname(caller_path))
return get_config(plugin_name + "_alembic_version") # Specifically bypass the cached config so that we always get the database value
version = _get_config.__wrapped__(plugin_name + "_alembic_version")
if version == KeyError:
version = None
return version
def upgrade(plugin_name=None, revision=None, lower="current"): def upgrade(plugin_name=None, revision=None, lower="current"):
@@ -57,7 +61,7 @@ def upgrade(plugin_name=None, revision=None, lower="current"):
# "current" points to the current plugin version stored in config # "current" points to the current plugin version stored in config
# None represents the absolute base layer (e.g. first installation) # None represents the absolute base layer (e.g. first installation)
if lower == "current": if lower == "current":
lower = get_config(plugin_name + "_alembic_version") lower = current(plugin_name)
# Do we upgrade to head or to a specific revision # Do we upgrade to head or to a specific revision
if revision is None: if revision is None: