def perform_db_upgrade_7_to_8(conn: ConnectionPlus) -> None: """ Perform the upgrade from version 6 to version 7. Add a new column to store the dataset's parents to the runs table. """ with atomic(conn) as conn: insert_column(conn, 'runs', 'parent_datasets', 'TEXT')
def perform_db_upgrade_4_to_5(conn: ConnectionPlus) -> None: """ Perform the upgrade from version 4 to version 5. Make sure that 'snapshot' column always exists in the 'runs' table. This was not the case before because 'snapshot' was treated as 'metadata', hence the 'snapshot' column was dynamically created once there was a run with snapshot information. """ with atomic(conn) as conn: insert_column(conn, 'runs', 'snapshot', 'TEXT')
def perform_db_upgrade_7_to_8(conn: ConnectionPlus) -> None: """ Perform the upgrade from version 6 to version 7. Add a new column to store the dataset's parents to the runs table. """ with atomic(conn) as conn: pbar = tqdm(range(1), file=sys.stdout) pbar.set_description("Upgrading database; v7 -> v8") # iterate through the pbar for the sake of the side effect; it # prints that the database is being upgraded for _ in pbar: insert_column(conn, 'runs', 'parent_datasets', 'TEXT')
def perform_db_upgrade_4_to_5(conn: ConnectionPlus) -> None: """ Perform the upgrade from version 4 to version 5. Make sure that 'snapshot' column always exists in the 'runs' table. This was not the case before because 'snapshot' was treated as 'metadata', hence the 'snapshot' column was dynamically created once there was a run with snapshot information. """ with atomic(conn) as conn: pbar = tqdm(range(1), file=sys.stdout) pbar.set_description("Upgrading database; v4 -> v5") # iterate through the pbar for the sake of the side effect; it # prints that the database is being upgraded for _ in pbar: insert_column(conn, 'runs', 'snapshot', 'TEXT')
def insert_meta_data(conn: ConnectionPlus, row_id: int, table_name: str, metadata: Dict[str, Any]) -> None: """ Insert new metadata column and add values. Note that None is not a valid metadata value Args: - conn: the connection to the sqlite database - row_id: the row to add the metadata at - table_name: the table to add to, defaults to runs - metadata: the metadata to add """ for tag, val in metadata.items(): if val is None: raise ValueError(f'Tag {tag} has value None. ' ' That is not a valid metadata value!') for key in metadata.keys(): insert_column(conn, table_name, key) update_meta_data(conn, row_id, table_name, metadata)
def add_parameter(conn: ConnectionPlus, formatted_name: str, *parameter: ParamSpec): """ Add parameters to the dataset This will update the layouts and dependencies tables NOTE: two parameters with the same name are not allowed Args: conn: the connection to the sqlite database formatted_name: name of the table parameter: the list of ParamSpecs for parameters to add """ with atomic(conn) as conn: p_names = [] for p in parameter: insert_column(conn, formatted_name, p.name, p.type) p_names.append(p.name) # get old parameters column from run table sql = f""" SELECT parameters FROM runs WHERE result_table_name=? """ with atomic(conn) as conn: c = transaction(conn, sql, formatted_name) old_parameters = one(c, 'parameters') if old_parameters: new_parameters = ",".join([old_parameters] + p_names) else: new_parameters = ",".join(p_names) sql = "UPDATE runs SET parameters=? WHERE result_table_name=?" with atomic(conn) as conn: transaction(conn, sql, new_parameters, formatted_name) # Update the layouts table c = _add_parameters_to_layout_and_deps(conn, formatted_name, *parameter)