We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Imports may need to go through the application factory process again
If the CTF has plugins that create tables, those tables may not be re-created when importing/resetting. This might be leading to issues where tables don't exist in the database but are referred to by plugins. 
Imports may need to go through the application factory process again
If the CTF has plugins that create tables, those tables may not be re-created when importing/resetting. This might be leading to issues where tables don't exist in the database but are referred to by plugins. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `CTFd/utils/exports/__init__.py`
Content:
```
1 from CTFd.utils import get_app_config
2 from CTFd.utils.migrations import get_current_revision, create_database, drop_database, upgrade, stamp
3 from CTFd.utils.uploads import get_uploader
4 from CTFd.models import db
5 from CTFd.cache import cache
6 from datafreeze.format import SERIALIZERS
7 from flask import current_app as app
8 from datafreeze.format.fjson import JSONSerializer, JSONEncoder
9 import dataset
10 import datafreeze
11 import datetime
12 import json
13 import os
14 import re
15 import six
16 import zipfile
17 import tempfile
18 
19 
20 class CTFdSerializer(JSONSerializer):
21     """
22     Slightly modified datafreeze serializer so that we can properly
23     export the CTFd database into a zip file.
24     """
25 
26     def close(self):
27         for path, result in self.buckets.items():
28             result = self.wrap(result)
29 
30             if self.fileobj is None:
31                 fh = open(path, 'wb')
32             else:
33                 fh = self.fileobj
34 
35             data = json.dumps(result,
36                               cls=JSONEncoder,
37                               indent=self.export.get_int('indent'))
38 
39             callback = self.export.get('callback')
40             if callback:
41                 data = "%s && %s(%s);" % (callback, callback, data)
42 
43             if six.PY3:
44                 fh.write(bytes(data, encoding='utf-8'))
45             else:
46                 fh.write(data)
47             if self.fileobj is None:
48                 fh.close()
49 
50 
51 SERIALIZERS['ctfd'] = CTFdSerializer  # Load the custom serializer
52 
53 
54 def export_ctf():
55     # TODO: For some unknown reason dataset is only able to see alembic_version during tests.
56     # Even using a real sqlite database. This makes this test impossible to pass in sqlite.
57     db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))
58 
59     # Backup database
60     backup = tempfile.NamedTemporaryFile()
61 
62     backup_zip = zipfile.ZipFile(backup, 'w')
63 
64     tables = db.tables
65     for table in tables:
66         result = db[table].all()
67         result_file = six.BytesIO()
68         datafreeze.freeze(result, format='ctfd', fileobj=result_file)
69         result_file.seek(0)
70         backup_zip.writestr('db/{}.json'.format(table), result_file.read())
71 
72     # # Guarantee that alembic_version is saved into the export
73     if 'alembic_version' not in tables:
74         result = {
75             "count": 1,
76             "results": [
77                 {
78                     "version_num": get_current_revision()
79                 }
80             ],
81             "meta": {}
82         }
83         result_file = six.BytesIO()
84         json.dump(result, result_file)
85         result_file.seek(0)
86         backup_zip.writestr('db/alembic_version.json', result_file.read())
87 
88     # Backup uploads
89     uploader = get_uploader()
90     uploader.sync()
91 
92     upload_folder = os.path.join(os.path.normpath(app.root_path), app.config.get('UPLOAD_FOLDER'))
93     for root, dirs, files in os.walk(upload_folder):
94         for file in files:
95             parent_dir = os.path.basename(root)
96             backup_zip.write(os.path.join(root, file), arcname=os.path.join('uploads', parent_dir, file))
97 
98     backup_zip.close()
99     backup.seek(0)
100     return backup
101 
102 
103 def import_ctf(backup, erase=True):
104     if not zipfile.is_zipfile(backup):
105         raise zipfile.BadZipfile
106 
107     if erase:
108         drop_database()
109         create_database()
110         # We explicitly do not want to upgrade or stamp here.
111         # The import will have this information.
112 
113     side_db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))
114     sqlite = get_app_config('SQLALCHEMY_DATABASE_URI').startswith('sqlite')
115     postgres = get_app_config('SQLALCHEMY_DATABASE_URI').startswith('postgres')
116 
117     backup = zipfile.ZipFile(backup)
118 
119     members = backup.namelist()
120     max_content_length = get_app_config('MAX_CONTENT_LENGTH')
121     for f in members:
122         if f.startswith('/') or '..' in f:
123             # Abort on malicious zip files
124             raise zipfile.BadZipfile
125         info = backup.getinfo(f)
126         if max_content_length:
127             if info.file_size > max_content_length:
128                 raise zipfile.LargeZipFile
129 
130     first = [
131         'db/teams.json',
132         'db/users.json',
133         'db/challenges.json',
134         'db/dynamic_challenge.json',
135 
136         'db/flags.json',
137         'db/hints.json',
138         'db/unlocks.json',
139         'db/awards.json',
140         'db/tags.json',
141 
142         'db/submissions.json',
143         'db/solves.json',
144 
145         'db/files.json',
146 
147         'db/notifications.json',
148         'db/pages.json',
149 
150         'db/tracking.json',
151         'db/config.json',
152     ]
153 
154     for item in first:
155         if item in members:
156             members.remove(item)
157 
158     members = first + members
159 
160     alembic_version = json.loads(backup.open('db/alembic_version.json').read())["results"][0]["version_num"]
161     upgrade(revision=alembic_version)
162     members.remove('db/alembic_version.json')
163 
164     for member in members:
165         if member.startswith('db/'):
166             table_name = member[3:-5]
167 
168             try:
169                 # Try to open a file but skip if it doesn't exist.
170                 data = backup.open(member).read()
171             except KeyError:
172                 continue
173 
174             if data:
175                 table = side_db[table_name]
176 
177                 saved = json.loads(data)
178                 for entry in saved['results']:
179                     # This is a hack to get SQLite to properly accept datetime values from dataset
180                     # See Issue #246
181                     if sqlite:
182                         for k, v in entry.items():
183                             if isinstance(v, six.string_types):
184                                 match = re.match(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d", v)
185                                 if match:
186                                     entry[k] = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f')
187                                     continue
188                                 match = re.match(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}", v)
189                                 if match:
190                                     entry[k] = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S')
191                                     continue
192                     table.insert(entry)
193                     db.session.commit()
194                 if postgres:
195                     # TODO: This should be sanitized even though exports are basically SQL dumps
196                     # Databases are so hard
197                     # https://stackoverflow.com/a/37972960
198                     side_db.engine.execute(
199                         "SELECT setval(pg_get_serial_sequence('{table_name}', 'id'), coalesce(max(id)+1,1), false) FROM {table_name}".format(
200                             table_name=table_name
201                         )
202                     )
203 
204     # Extracting files
205     files = [f for f in backup.namelist() if f.startswith('uploads/')]
206     uploader = get_uploader()
207     for f in files:
208         filename = f.split(os.sep, 1)
209 
210         if len(filename) < 2:  # just an empty uploads directory (e.g. uploads/)
211             continue
212 
213         filename = filename[1]  # Get the second entry in the list (the actual filename)
214         source = backup.open(f)
215         uploader.store(fileobj=source, filename=filename)
216 
217     cache.clear()
218
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/CTFd/utils/exports/__init__.py b/CTFd/utils/exports/__init__.py
--- a/CTFd/utils/exports/__init__.py
+++ b/CTFd/utils/exports/__init__.py
@@ -6,6 +6,7 @@
 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 @@
 
     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:

{"golden_diff": "diff --git a/CTFd/utils/exports/__init__.py b/CTFd/utils/exports/__init__.py\n--- a/CTFd/utils/exports/__init__.py\n+++ b/CTFd/utils/exports/__init__.py\n@@ -6,6 +6,7 @@\n from datafreeze.format import SERIALIZERS\n from flask import current_app as app\n from datafreeze.format.fjson import JSONSerializer, JSONEncoder\n+from sqlalchemy.exc import OperationalError\n import dataset\n import datafreeze\n import datetime\n@@ -159,6 +160,16 @@\n \n     alembic_version = json.loads(backup.open('db/alembic_version.json').read())[\"results\"][0][\"version_num\"]\n     upgrade(revision=alembic_version)\n+\n+    # Create tables created by plugins\n+    try:\n+        app.db.create_all()\n+    except OperationalError as e:\n+        if not postgres:\n+            raise e\n+        else:\n+            print(\"Allowing error during app.db.create_all() due to Postgres\")\n+\n     members.remove('db/alembic_version.json')\n \n     for member in members:\n", "issue": "Imports may need to go through the application factory process again\nIf the CTF has plugins that create tables, those tables may not be re-created when importing/resetting. This might be leading to issues where tables don't exist in the database but are referred to by plugins. \nImports may need to go through the application factory process again\nIf the CTF has plugins that create tables, those tables may not be re-created when importing/resetting. This might be leading to issues where tables don't exist in the database but are referred to by plugins. \n", "before_files": [{"content": "from CTFd.utils import get_app_config\nfrom CTFd.utils.migrations import get_current_revision, create_database, drop_database, upgrade, stamp\nfrom CTFd.utils.uploads import get_uploader\nfrom CTFd.models import db\nfrom CTFd.cache import cache\nfrom datafreeze.format import SERIALIZERS\nfrom flask import current_app as app\nfrom datafreeze.format.fjson import JSONSerializer, JSONEncoder\nimport dataset\nimport datafreeze\nimport datetime\nimport json\nimport os\nimport re\nimport six\nimport zipfile\nimport tempfile\n\n\nclass CTFdSerializer(JSONSerializer):\n    \"\"\"\n    Slightly modified datafreeze serializer so that we can properly\n    export the CTFd database into a zip file.\n    \"\"\"\n\n    def close(self):\n        for path, result in self.buckets.items():\n            result = self.wrap(result)\n\n            if self.fileobj is None:\n                fh = open(path, 'wb')\n            else:\n                fh = self.fileobj\n\n            data = json.dumps(result,\n                              cls=JSONEncoder,\n                              indent=self.export.get_int('indent'))\n\n            callback = self.export.get('callback')\n            if callback:\n                data = \"%s && %s(%s);\" % (callback, callback, data)\n\n            if six.PY3:\n                fh.write(bytes(data, encoding='utf-8'))\n            else:\n                fh.write(data)\n            if self.fileobj is None:\n                fh.close()\n\n\nSERIALIZERS['ctfd'] = CTFdSerializer  # Load the custom serializer\n\n\ndef export_ctf():\n    # TODO: For some unknown reason dataset is only able to see alembic_version during tests.\n    # Even using a real sqlite database. This makes this test impossible to pass in sqlite.\n    db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))\n\n    # Backup database\n    backup = tempfile.NamedTemporaryFile()\n\n    backup_zip = zipfile.ZipFile(backup, 'w')\n\n    tables = db.tables\n    for table in tables:\n        result = db[table].all()\n        result_file = six.BytesIO()\n        datafreeze.freeze(result, format='ctfd', fileobj=result_file)\n        result_file.seek(0)\n        backup_zip.writestr('db/{}.json'.format(table), result_file.read())\n\n    # # Guarantee that alembic_version is saved into the export\n    if 'alembic_version' not in tables:\n        result = {\n            \"count\": 1,\n            \"results\": [\n                {\n                    \"version_num\": get_current_revision()\n                }\n            ],\n            \"meta\": {}\n        }\n        result_file = six.BytesIO()\n        json.dump(result, result_file)\n        result_file.seek(0)\n        backup_zip.writestr('db/alembic_version.json', result_file.read())\n\n    # Backup uploads\n    uploader = get_uploader()\n    uploader.sync()\n\n    upload_folder = os.path.join(os.path.normpath(app.root_path), app.config.get('UPLOAD_FOLDER'))\n    for root, dirs, files in os.walk(upload_folder):\n        for file in files:\n            parent_dir = os.path.basename(root)\n            backup_zip.write(os.path.join(root, file), arcname=os.path.join('uploads', parent_dir, file))\n\n    backup_zip.close()\n    backup.seek(0)\n    return backup\n\n\ndef import_ctf(backup, erase=True):\n    if not zipfile.is_zipfile(backup):\n        raise zipfile.BadZipfile\n\n    if erase:\n        drop_database()\n        create_database()\n        # We explicitly do not want to upgrade or stamp here.\n        # The import will have this information.\n\n    side_db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))\n    sqlite = get_app_config('SQLALCHEMY_DATABASE_URI').startswith('sqlite')\n    postgres = get_app_config('SQLALCHEMY_DATABASE_URI').startswith('postgres')\n\n    backup = zipfile.ZipFile(backup)\n\n    members = backup.namelist()\n    max_content_length = get_app_config('MAX_CONTENT_LENGTH')\n    for f in members:\n        if f.startswith('/') or '..' in f:\n            # Abort on malicious zip files\n            raise zipfile.BadZipfile\n        info = backup.getinfo(f)\n        if max_content_length:\n            if info.file_size > max_content_length:\n                raise zipfile.LargeZipFile\n\n    first = [\n        'db/teams.json',\n        'db/users.json',\n        'db/challenges.json',\n        'db/dynamic_challenge.json',\n\n        'db/flags.json',\n        'db/hints.json',\n        'db/unlocks.json',\n        'db/awards.json',\n        'db/tags.json',\n\n        'db/submissions.json',\n        'db/solves.json',\n\n        'db/files.json',\n\n        'db/notifications.json',\n        'db/pages.json',\n\n        'db/tracking.json',\n        'db/config.json',\n    ]\n\n    for item in first:\n        if item in members:\n            members.remove(item)\n\n    members = first + members\n\n    alembic_version = json.loads(backup.open('db/alembic_version.json').read())[\"results\"][0][\"version_num\"]\n    upgrade(revision=alembic_version)\n    members.remove('db/alembic_version.json')\n\n    for member in members:\n        if member.startswith('db/'):\n            table_name = member[3:-5]\n\n            try:\n                # Try to open a file but skip if it doesn't exist.\n                data = backup.open(member).read()\n            except KeyError:\n                continue\n\n            if data:\n                table = side_db[table_name]\n\n                saved = json.loads(data)\n                for entry in saved['results']:\n                    # This is a hack to get SQLite to properly accept datetime values from dataset\n                    # See Issue #246\n                    if sqlite:\n                        for k, v in entry.items():\n                            if isinstance(v, six.string_types):\n                                match = re.match(r\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d\", v)\n                                if match:\n                                    entry[k] = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f')\n                                    continue\n                                match = re.match(r\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\", v)\n                                if match:\n                                    entry[k] = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S')\n                                    continue\n                    table.insert(entry)\n                    db.session.commit()\n                if postgres:\n                    # TODO: This should be sanitized even though exports are basically SQL dumps\n                    # Databases are so hard\n                    # https://stackoverflow.com/a/37972960\n                    side_db.engine.execute(\n                        \"SELECT setval(pg_get_serial_sequence('{table_name}', 'id'), coalesce(max(id)+1,1), false) FROM {table_name}\".format(\n                            table_name=table_name\n                        )\n                    )\n\n    # Extracting files\n    files = [f for f in backup.namelist() if f.startswith('uploads/')]\n    uploader = get_uploader()\n    for f in files:\n        filename = f.split(os.sep, 1)\n\n        if len(filename) < 2:  # just an empty uploads directory (e.g. uploads/)\n            continue\n\n        filename = filename[1]  # Get the second entry in the list (the actual filename)\n        source = backup.open(f)\n        uploader.store(fileobj=source, filename=filename)\n\n    cache.clear()\n", "path": "CTFd/utils/exports/__init__.py"}], "after_files": [{"content": "from CTFd.utils import get_app_config\nfrom CTFd.utils.migrations import get_current_revision, create_database, drop_database, upgrade, stamp\nfrom CTFd.utils.uploads import get_uploader\nfrom CTFd.models import db\nfrom CTFd.cache import cache\nfrom datafreeze.format import SERIALIZERS\nfrom flask import current_app as app\nfrom datafreeze.format.fjson import JSONSerializer, JSONEncoder\nfrom sqlalchemy.exc import OperationalError\nimport dataset\nimport datafreeze\nimport datetime\nimport json\nimport os\nimport re\nimport six\nimport zipfile\nimport tempfile\n\n\nclass CTFdSerializer(JSONSerializer):\n    \"\"\"\n    Slightly modified datafreeze serializer so that we can properly\n    export the CTFd database into a zip file.\n    \"\"\"\n\n    def close(self):\n        for path, result in self.buckets.items():\n            result = self.wrap(result)\n\n            if self.fileobj is None:\n                fh = open(path, 'wb')\n            else:\n                fh = self.fileobj\n\n            data = json.dumps(result,\n                              cls=JSONEncoder,\n                              indent=self.export.get_int('indent'))\n\n            callback = self.export.get('callback')\n            if callback:\n                data = \"%s && %s(%s);\" % (callback, callback, data)\n\n            if six.PY3:\n                fh.write(bytes(data, encoding='utf-8'))\n            else:\n                fh.write(data)\n            if self.fileobj is None:\n                fh.close()\n\n\nSERIALIZERS['ctfd'] = CTFdSerializer  # Load the custom serializer\n\n\ndef export_ctf():\n    # TODO: For some unknown reason dataset is only able to see alembic_version during tests.\n    # Even using a real sqlite database. This makes this test impossible to pass in sqlite.\n    db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))\n\n    # Backup database\n    backup = tempfile.NamedTemporaryFile()\n\n    backup_zip = zipfile.ZipFile(backup, 'w')\n\n    tables = db.tables\n    for table in tables:\n        result = db[table].all()\n        result_file = six.BytesIO()\n        datafreeze.freeze(result, format='ctfd', fileobj=result_file)\n        result_file.seek(0)\n        backup_zip.writestr('db/{}.json'.format(table), result_file.read())\n\n    # # Guarantee that alembic_version is saved into the export\n    if 'alembic_version' not in tables:\n        result = {\n            \"count\": 1,\n            \"results\": [\n                {\n                    \"version_num\": get_current_revision()\n                }\n            ],\n            \"meta\": {}\n        }\n        result_file = six.BytesIO()\n        json.dump(result, result_file)\n        result_file.seek(0)\n        backup_zip.writestr('db/alembic_version.json', result_file.read())\n\n    # Backup uploads\n    uploader = get_uploader()\n    uploader.sync()\n\n    upload_folder = os.path.join(os.path.normpath(app.root_path), app.config.get('UPLOAD_FOLDER'))\n    for root, dirs, files in os.walk(upload_folder):\n        for file in files:\n            parent_dir = os.path.basename(root)\n            backup_zip.write(os.path.join(root, file), arcname=os.path.join('uploads', parent_dir, file))\n\n    backup_zip.close()\n    backup.seek(0)\n    return backup\n\n\ndef import_ctf(backup, erase=True):\n    if not zipfile.is_zipfile(backup):\n        raise zipfile.BadZipfile\n\n    if erase:\n        drop_database()\n        create_database()\n        # We explicitly do not want to upgrade or stamp here.\n        # The import will have this information.\n\n    side_db = dataset.connect(get_app_config('SQLALCHEMY_DATABASE_URI'))\n    sqlite = get_app_config('SQLALCHEMY_DATABASE_URI').startswith('sqlite')\n    postgres = get_app_config('SQLALCHEMY_DATABASE_URI').startswith('postgres')\n\n    backup = zipfile.ZipFile(backup)\n\n    members = backup.namelist()\n    max_content_length = get_app_config('MAX_CONTENT_LENGTH')\n    for f in members:\n        if f.startswith('/') or '..' in f:\n            # Abort on malicious zip files\n            raise zipfile.BadZipfile\n        info = backup.getinfo(f)\n        if max_content_length:\n            if info.file_size > max_content_length:\n                raise zipfile.LargeZipFile\n\n    first = [\n        'db/teams.json',\n        'db/users.json',\n        'db/challenges.json',\n        'db/dynamic_challenge.json',\n\n        'db/flags.json',\n        'db/hints.json',\n        'db/unlocks.json',\n        'db/awards.json',\n        'db/tags.json',\n\n        'db/submissions.json',\n        'db/solves.json',\n\n        'db/files.json',\n\n        'db/notifications.json',\n        'db/pages.json',\n\n        'db/tracking.json',\n        'db/config.json',\n    ]\n\n    for item in first:\n        if item in members:\n            members.remove(item)\n\n    members = first + members\n\n    alembic_version = json.loads(backup.open('db/alembic_version.json').read())[\"results\"][0][\"version_num\"]\n    upgrade(revision=alembic_version)\n\n    # Create tables created by plugins\n    try:\n        app.db.create_all()\n    except OperationalError as e:\n        if not postgres:\n            raise e\n        else:\n            print(\"Allowing error during app.db.create_all() due to Postgres\")\n\n    members.remove('db/alembic_version.json')\n\n    for member in members:\n        if member.startswith('db/'):\n            table_name = member[3:-5]\n\n            try:\n                # Try to open a file but skip if it doesn't exist.\n                data = backup.open(member).read()\n            except KeyError:\n                continue\n\n            if data:\n                table = side_db[table_name]\n\n                saved = json.loads(data)\n                for entry in saved['results']:\n                    # This is a hack to get SQLite to properly accept datetime values from dataset\n                    # See Issue #246\n                    if sqlite:\n                        for k, v in entry.items():\n                            if isinstance(v, six.string_types):\n                                match = re.match(r\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d\", v)\n                                if match:\n                                    entry[k] = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f')\n                                    continue\n                                match = re.match(r\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\", v)\n                                if match:\n                                    entry[k] = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S')\n                                    continue\n                    table.insert(entry)\n                    db.session.commit()\n                if postgres:\n                    # TODO: This should be sanitized even though exports are basically SQL dumps\n                    # Databases are so hard\n                    # https://stackoverflow.com/a/37972960\n                    side_db.engine.execute(\n                        \"SELECT setval(pg_get_serial_sequence('{table_name}', 'id'), coalesce(max(id)+1,1), false) FROM {table_name}\".format(\n                            table_name=table_name\n                        )\n                    )\n\n    # Extracting files\n    files = [f for f in backup.namelist() if f.startswith('uploads/')]\n    uploader = get_uploader()\n    for f in files:\n        filename = f.split(os.sep, 1)\n\n        if len(filename) < 2:  # just an empty uploads directory (e.g. uploads/)\n            continue\n\n        filename = filename[1]  # Get the second entry in the list (the actual filename)\n        source = backup.open(f)\n        uploader.store(fileobj=source, filename=filename)\n\n    cache.clear()\n", "path": "CTFd/utils/exports/__init__.py"}]}