Restore historic skeleton endpoint#1
Open
afonsobspinto wants to merge 7 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This change adds an API endpoint that restores the latest deleted historic
version of a single skeleton:
UserRole.Annotate.class_instancetable.The existing skeleton deletion route is now wrapped with:
Older delete transactions may still be labeled
neurons.removeor may have no label; both are rejected by default. These older restore cases should remain a manual admin workflowFinding The Latest Deleted Skeleton
The lookup entry point is:
It searches
class_instance__historyfor historic rows where:idmatches the requested skeleton ID.project_idmatches the requested project.skeleton.sys_periodis closed, meaning the row was removed or replaced historically.The candidates are grouped by:
exec_transaction_idupper(sys_period)The newest candidate is selected by ordering
upper(sys_period)descending andtaking one row. This is the definition of "latest" for this endpoint.
After selecting the latest candidate, the same query checks how many deleted skeleton rows exist for that transaction in
class_instance__history. It only returns a row if that count is exactly one and that one skeleton is the requested skeleton.The query also joins
catmaid_transaction_infoon the transaction ID and execution time to retrieve the transaction label.The Restore View Flow
The view is:
The flow is:
Open
transaction.atomic()so all checks and inserts are one databasetransaction.
Take a transaction-scoped PostgreSQL advisory lock:
(The advisory lock blocks restore operations for the same skeleton id)
class_instancealready has the requested skeleton ID.Transactionobject from the candidate transaction ID and time.undelete_neuron()for the selected transaction.The response includes:
{ "skeleton_id": 1, "transaction_id": 123, "execution_time": "...", "source_label": "skeletons.remove", "success": "Restored skeleton 1 from history." }Tests
The added tests live in:
The restore-related coverage includes:
rows, and treenode edge rows are live again.
skeletons.removeandskeletons.restore.