Skip to content

Commit

Permalink
Add check_file_id to insert_datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Oct 1, 2024
1 parent 25e39ed commit 81467ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions isimip_publisher/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ def insert_datasets():

session = database.init_database_session(settings.DATABASE)

for dataset in store.datasets:
for file in dataset.files:
database.check_file_id(session, file.path, file.uuid)

for dataset in tqdm(store.datasets, desc='insert_datasets'.ljust(18)):
database.insert_dataset(session, settings.VERSION, settings.RIGHTS, settings.RESTRICTED,
dataset.name, dataset.path, dataset.size, dataset.specifiers)
Expand Down
6 changes: 6 additions & 0 deletions isimip_publisher/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ def retrieve_datasets(session, path, public=None, follow=False, like=True):
return datasets


def check_file_id(session, path, uuid):
file = session.query(File).filter(File.id == uuid).one_or_none()
if file:
raise RuntimeError(f'File {path} has an id which already exists in the database ({uuid})')


def insert_file(session, version, dataset_path, uuid, name, path, size,
checksum, checksum_type, netcdf_header, specifiers):
# get the dataset from the database
Expand Down

0 comments on commit 81467ca

Please sign in to comment.