move sqlite3 checks up a level

This commit is contained in:
Nick Sweeting 2022-06-08 18:29:53 -07:00 committed by GitHub
parent 0c7d7deb32
commit d0f129295f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1203,12 +1203,6 @@ def setup_django(out_dir: Path=None, check_db=False, config: ConfigDict=CONFIG,
except django.db.utils.OperationalError: except django.db.utils.OperationalError:
call_command("createcachetable", verbosity=0) call_command("createcachetable", verbosity=0)
with connection.cursor() as cursor:
config['SQLITE_VERSION'] = cursor.execute("SELECT sqlite_version();").fetchone()[0]
config['SQLITE_JOURNAL_MODE'] = cursor.execute('PRAGMA journal_mode;').fetchone()[0]
config['SQLITE_EXTENSIONS'] = ['JSON1'] if ('ENABLE_JSON1',) in cursor.execute('PRAGMA compile_options;').fetchall() else []
# if archivebox gets imported multiple times, we have to close # if archivebox gets imported multiple times, we have to close
# the sqlite3 whenever we init from scratch to avoid multiple threads # the sqlite3 whenever we init from scratch to avoid multiple threads
# sharing the same connection by accident # sharing the same connection by accident
@ -1220,5 +1214,10 @@ def setup_django(out_dir: Path=None, check_db=False, config: ConfigDict=CONFIG,
assert sql_index_path.exists(), ( assert sql_index_path.exists(), (
f'No database file {SQL_INDEX_FILENAME} found in: {config["OUTPUT_DIR"]} (Are you in an ArchiveBox collection directory?)') f'No database file {SQL_INDEX_FILENAME} found in: {config["OUTPUT_DIR"]} (Are you in an ArchiveBox collection directory?)')
with connection.cursor() as cursor:
config['SQLITE_VERSION'] = cursor.execute("SELECT sqlite_version();").fetchone()[0]
config['SQLITE_JOURNAL_MODE'] = cursor.execute('PRAGMA journal_mode;').fetchone()[0]
config['SQLITE_EXTENSIONS'] = ['JSON1'] if ('ENABLE_JSON1',) in cursor.execute('PRAGMA compile_options;').fetchall() else []
except KeyboardInterrupt: except KeyboardInterrupt:
raise SystemExit(2) raise SystemExit(2)