mirror of https://github.com/JohnHammond/CTFd.git
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 properlyselenium-screenshot-testing
parent
420e4f4dc7
commit
ff0f2c2a0b
|
@ -3,7 +3,7 @@ import os
|
|||
|
||||
from distutils.version import StrictVersion
|
||||
from flask import Flask, Request
|
||||
from flask_migrate import upgrade, stamp
|
||||
from flask_migrate import upgrade
|
||||
from werkzeug.utils import cached_property
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
from jinja2 import FileSystemLoader
|
||||
|
@ -11,7 +11,7 @@ from jinja2.sandbox import SandboxedEnvironment
|
|||
from six.moves import input
|
||||
|
||||
from CTFd import utils
|
||||
from CTFd.utils.migrations import migrations, create_database
|
||||
from CTFd.utils.migrations import migrations, create_database, stamp_latest_revision
|
||||
from CTFd.utils.sessions import CachingSessionInterface
|
||||
from CTFd.utils.updates import update_check
|
||||
from CTFd.utils.initialization import (
|
||||
|
@ -149,7 +149,7 @@ def create_app(config="CTFd.config.Config"):
|
|||
# Alembic sqlite support is lacking so we should just create_all anyway
|
||||
if url.drivername.startswith("sqlite"):
|
||||
db.create_all()
|
||||
stamp()
|
||||
stamp_latest_revision()
|
||||
else:
|
||||
# This creates tables instead of db.create_all()
|
||||
# Allows migrations to happen properly
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue