[BE] Snippet without repo edge case
Summary
Whilst working on #217808 (closed) I discovered an edge case scenario that could lead to data loss as part of the multi-file snippet epic.
In the scenario where a Snippet does not yet have a repository (failed migration, etc), if a user updates that Snippet using the recently added snippet actions, the original Snippet content
and file_name
are lost.
This is because the current implementation does the following:
- Creates an empty repository for the Snippet (here)
- Creates a file (or files) for the given snippet action params (here)
- Updates the Snippet
content
andfile_name
attributes to be that of the first snippet action file (here)
Although point 3 will be removed in the near future (see this comment), we still need to address the fact that no file is created for the snippet during point 1.
Proposal
When creating the repository in the Snippets::UpdateService
(here) we should also create an initial file with the file_name
and content
from the Snippet.
We can possibly achieve this by modifying the params or snippet actions to include an entry for the original snippet content, but this runs the risk of file name conflicts with any existing actions that the user passes in, so we will probably want to check for that and generate a filename instead (as we've done in elsewhere for the migration to versioned snippets), e.g. snippetfile1.txt
, if that's the case.