diff --git a/tasks.py b/tasks.py index 0578f69acd..f079672199 100644 --- a/tasks.py +++ b/tasks.py @@ -6,6 +6,7 @@ import sys import pathlib import re + try: from invoke import ctask as task except: @@ -380,8 +381,8 @@ def export_records(c, filename='data.json'): print("Data export completed") -@task(help={'filename': 'Input filename'}, post=[rebuild_models, rebuild_thumbnails]) -def import_records(c, filename='data.json'): +@task(help={'filename': 'Input filename', 'clear': 'Clear existing data before import'}, post=[rebuild_models, rebuild_thumbnails]) +def import_records(c, filename='data.json', clear=False): """ Import database records from a file """ @@ -394,6 +395,9 @@ def import_records(c, filename='data.json'): print(f"Error: File '{filename}' does not exist") sys.exit(1) + if clear: + delete_data(c, force=True) + print(f"Importing database records from '{filename}'") # Pre-process the data, to remove any "permissions" specified for a user or group @@ -432,6 +436,8 @@ def delete_data(c, force=False): Warning: This will REALLY delete all records in the database!! """ + print(f"Deleting all data from InvenTree database...") + if force: manage(c, 'flush --noinput') else: