mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-23 15:14:49 +01:00
Fixed bug that caused apache2+wsgi deployment to break (#1030)
* Create a `flask_migrate.stamp()` wrapper in `CTFd.utils.migrations` that always references the migrations folder regardless of how CTFd is run or deployed. * Closes #257 properly
This commit is contained in:
committed by
Kevin Chung
parent
420e4f4dc7
commit
ff0f2c2a0b
@@ -1,11 +1,11 @@
|
||||
from CTFd.utils import get_app_config, set_config
|
||||
from CTFd.utils.migrations import get_current_revision, create_database, drop_database
|
||||
from CTFd.utils.migrations import get_current_revision, create_database, drop_database, stamp_latest_revision
|
||||
from CTFd.utils.uploads import get_uploader
|
||||
from CTFd.models import db
|
||||
from CTFd.cache import cache
|
||||
from datafreeze.format import SERIALIZERS
|
||||
from flask import current_app as app
|
||||
from flask_migrate import upgrade, stamp
|
||||
from flask_migrate import upgrade
|
||||
from datafreeze.format.fjson import JSONSerializer, JSONEncoder
|
||||
from sqlalchemy.exc import OperationalError, ProgrammingError
|
||||
from alembic.util import CommandError
|
||||
@@ -278,7 +278,7 @@ def import_ctf(backup, erase=True):
|
||||
upgrade(revision="head")
|
||||
except (CommandError, RuntimeError, SystemExit):
|
||||
app.db.create_all()
|
||||
stamp()
|
||||
stamp_latest_revision()
|
||||
|
||||
# Invalidate all cached data
|
||||
cache.clear()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from flask import current_app as app
|
||||
from flask_migrate import Migrate
|
||||
from flask_migrate import Migrate, stamp
|
||||
from alembic.migration import MigrationContext
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.engine.url import make_url
|
||||
@@ -8,6 +8,7 @@ from sqlalchemy_utils import (
|
||||
create_database as create_database_util,
|
||||
drop_database as drop_database_util,
|
||||
)
|
||||
import os
|
||||
|
||||
migrations = Migrate()
|
||||
|
||||
@@ -42,3 +43,9 @@ def get_current_revision():
|
||||
context = MigrationContext.configure(conn)
|
||||
current_rev = context.get_current_revision()
|
||||
return current_rev
|
||||
|
||||
|
||||
def stamp_latest_revision():
|
||||
# Get proper migrations directory regardless of cwd
|
||||
directory = os.path.join(os.path.dirname(app.root_path), 'migrations')
|
||||
stamp(directory=directory)
|
||||
|
||||
Reference in New Issue
Block a user