Improve Snapshot lifecycle handling
- Dominant language
- JavaScript
- Stars
- 400
- Forks
- 89
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 149
Description
### Description
We need to improve our general lifecycle handling of snapshots.
We have seen cases where a snapshot gets orphaned (as its Instance/Device is deleted). The snapshot may still be 'in-use' as the target for a device group - however it can no longer be deployed as the Instance/Device no longer exists to retrieve the credentialSecret needed to decrypt the credentials.
Also, once in this state, **the snapshot doesn't appear anywhere in the UI** because there is no relation between the snapshot and Application/Instance/Device in order to retrieve it.
Problems to solve:
1. A snapshot needs to be deployable even if its originating device/instance has been deleted
2. A snapshot needs to be findable in the UI even if its originating device/instance has been deleted
3. Snapshots live forever - once the device/instance is deleted the snapshots remain and don't get tidied up (even when the team is deleted)
4. No visibility on what a device-groups current targetSnapshot is
5. No visibility on what snapshots are currently 'in-use' (ie currently a target snapshot for a device and/or device group)
---
Solutions:
1. Migrate the credentialSecret to live with the snapshot. Allows the originating device/instance to be deleted without losing access to the snapshot
2. Add ApplicationId to snapshot. This will be set based on the originating Instance/Device. Need to consider what happens if a Device is then reassigned to a different Application. Do the snapshots move over as well?
3.
```[tasklist]
### Tasks
- [ ] https://github.com/FlowFuse/flowfuse/issues/3644
- [ ] Add ApplicationId to snapshot model and keep in sync with owning instance/device
- [ ] https://github.com/FlowFuse/flowfuse/issues/3672
- [ ] https://github.com/FlowFuse/flowfuse/issues/4270
```
Contributor guide
Assessment
This issue has not been assessed yet.