GitAuto: Unable to overwrite saved searches #766
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.
Resolves #765
Why did this issue occur?
The bug occurred because saved searches with the same name weren't designed to overwrite an existing entry. Without proper conflict handling in the database, attempting to save a modified search under an already used name triggered an error ("Invalid saved search name").
What and how are we changing? Why this approach?
• We updated the SQL schema used for saved searches by adding a UNIQUE constraint on the combination of source and name.
• We altered the SQL insert command from a standard INSERT into an INSERT OR REPLACE command.
This approach guarantees that when a saved search with an existing name is saved again, the old entry is replaced by the new one instead of throwing an error. The UNIQUE constraint ensures data consistency and simplifies the logic for overwriting searches.
What actions are required from users?
No direct action is required by users. However, users should note that saving a search using an existing name will now overwrite the saved configuration, which may differ from previous behavior.
How does it work? (Technical details)
• The table definition in saved_search.sq now includes a UNIQUE constraint on (source, name), ensuring that duplicates are avoided at the database level.
• The insertion method has been revised to use "INSERT OR REPLACE INTO" so that if there is an existing entry with the same (source, name), it gets replaced by the new data (both query and filters_json).
• This change allows the app to safely update saved search entries without requiring additional UI prompts or conflict resolution on the front end.
Is it backwards compatible?
Yes, the change is backwards compatible. Existing saved searches continue to work as before. The new UNIQUE constraint and INSERT OR REPLACE command only affect cases where a user tries to overwrite an existing search, ensuring a smoother user experience without breaking existing functionality.
Any other considerations?
• Thorough testing has been performed to ensure that the changes resolve the issue without introducing unexpected side effects.
• This solution avoids additional complexity on the client side by handling the overwriting logic directly in the database layer.
• Future improvements might include providing an optional confirmation dialog before replacing a saved search, if user experience feedback suggests the need for it.