Skip to content
Snippets Groups Projects
Commit 05f51298 authored by Eva Bardou's avatar Eva Bardou
Browse files

Add Erwan's suggestions

parent bce57a31
No related branches found
No related tags found
No related merge requests found
Pipeline #79044 passed
......@@ -13,6 +13,7 @@ from peewee import (
ForeignKeyField,
IntegerField,
Model,
OperationalError,
SqliteDatabase,
TextField,
UUIDField,
......@@ -217,25 +218,27 @@ def create_tables():
def create_version_table():
"""
Creates the Version table in the cache DB.
This step must be independent from other tables creation since we only
want to create the table and add the one and only Version entry when the
cache is created from scratch.
"""
db.create_tables([Version])
Version.create(version=SQL_VERSION)
def check_version(cache_path):
provided_db = sqlite3.connect(cache_path)
provided_db.row_factory = sqlite3.Row
cursor = provided_db.cursor()
try:
db_results = cursor.execute(SQL_VERSION_QUERY).fetchall()
except sqlite3.OperationalError:
db_results = []
assert (
len(db_results) == 1 and db_results[0]["version"] == SQL_VERSION
), f"The SQLite database {cache_path} does not have the correct cache version, it should be {SQL_VERSION}"
provided_db.close()
with SqliteDatabase(cache_path) as provided_db:
with provided_db.bind_ctx([Version]):
try:
version = Version.get().version
except OperationalError:
version = None
assert (
version == SQL_VERSION
), f"The SQLite database {cache_path} does not have the correct cache version, it should be {SQL_VERSION}"
def retrieve_parents_cache_path(parent_ids, data_dir="/data", chunk=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment