From bf799fb22040a32bd2c8dcebecb010042782bc83 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Fri, 1 Mar 2019 15:37:02 -0800 Subject: [PATCH] Closes #861 (#889) * Move plugin table creation before insertion and ignore errors during Postgres --- CTFd/utils/exports/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CTFd/utils/exports/__init__.py b/CTFd/utils/exports/__init__.py index d624bca..f7a0f2a 100644 --- a/CTFd/utils/exports/__init__.py +++ b/CTFd/utils/exports/__init__.py @@ -6,6 +6,7 @@ from CTFd.cache import cache from datafreeze.format import SERIALIZERS from flask import current_app as app from datafreeze.format.fjson import JSONSerializer, JSONEncoder +from sqlalchemy.exc import OperationalError import dataset import datafreeze import datetime @@ -159,6 +160,16 @@ def import_ctf(backup, erase=True): alembic_version = json.loads(backup.open('db/alembic_version.json').read())["results"][0]["version_num"] upgrade(revision=alembic_version) + + # Create tables created by plugins + try: + app.db.create_all() + except OperationalError as e: + if not postgres: + raise e + else: + print("Allowing error during app.db.create_all() due to Postgres") + members.remove('db/alembic_version.json') for member in members: