Force db.create_all to happen for imports on sqlite. Force ctf_theme to be set to core in imports. (#972)

* Force `db.create_all` to happen for imports on `sqlite` or on failure to create missing tables
* Force `ctf_theme` to be set to `core` in imports in case a theme is missing from the import or the instance
selenium-screenshot-testing
Kevin Chung 2019-04-28 21:20:49 -04:00 committed by GitHub
parent c4e9b7037a
commit 376d644de7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -1,13 +1,14 @@
from CTFd.utils import get_app_config
from CTFd.utils import get_app_config, set_config
from CTFd.utils.migrations import get_current_revision, create_database, drop_database
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
from flask_migrate import upgrade, stamp
from datafreeze.format.fjson import JSONSerializer, JSONEncoder
from sqlalchemy.exc import OperationalError
from alembic.util import CommandError
import dataset
import datafreeze
import datetime
@ -235,5 +236,15 @@ def import_ctf(backup, erase=True):
source = backup.open(f)
uploader.store(fileobj=source, filename=filename)
upgrade(revision='head')
# Alembic sqlite support is lacking so we should just create_all anyway
try:
upgrade(revision='head')
except (CommandError, RuntimeError, SystemExit):
app.db.create_all()
stamp()
# Invalidate all cached data
cache.clear()
# Set default theme in case the current instance or the import does not provide it
set_config('ctf_theme', 'core')