Corrupted project json files after faulty reattaching

@tosyl A member of our team wrote python commands that you can run in the icli and that restore missing workspaces of which the project’s jobs were a member

cryosparcm icli # from shell to interactive cli
####### Below: PYTHON commands inside icli ######

project_uid = "P#"  # INSERT CORRECT PUID HERE

from models.workspace import Workspace
workspace_uids = db.jobs.distinct("workspace_uids", {"project_uid": project_uid, "deleted": {"$ne": True}})
for workspace_uid in workspace_uids:
    if db.workspaces.find_one({"project_uid": project_uid, "uid": workspace_uid}):
        print(f"Workspace {workspace_uid} already exists")
        continue
    Workspace(
        uid=workspace_uid,
        project_uid=project_uid,
        title=f"Recovered Workspace {workspace_uid}",
        workspace_type="base",
    ).save()
    print(f"Recovered workspace {workspace_uid}")
    
max_workspace_uid = db.workspaces.find_one({"project_uid": project_uid}, sort=[("uid_num", -1)])["uid"]
db.counters.find_one_and_update(
    {"namespace": project_uid},
    {"$set": {"workspaces": int(max_workspace_uid[1:])}},
    upsert=True,
)
exit() # back to shell

After adjusting the project_uid and running the commands, you should see workspaces with your jobs inside them. Remember that indentation levels matter in python.
[Edited]: Modified script, prompted by

1 Like