mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
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:
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user