[dev] Potential fix to Grunts not being deleted #370
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.
TLDR
Fixes an error in Covenant's database schema that led to Grunts that could not be deleted anymore. I tested the fix a bit and have not seen any negative impact.
Explanation
Sometimes, I was unable to delete a Grunt from the list via the Action dropdown. The following error was shown in the console:
I found that this was always the case when I used the file explorer in a Grunt. Looking at the database, two constraints caught my eye.
Table "FolderFileNodes":
CONSTRAINT "FK_FolderFileNodes_Folders_ParentId" FOREIGN KEY ("ParentId") REFERENCES "Folders" ("Id") ON DELETE RESTRICT,
Table "Folders":
CONSTRAINT "FK_Folders_Grunts_RootGruntId" FOREIGN KEY ("RootGruntId") REFERENCES "Grunts" ("Id") ON DELETE RESTRICT,
I modified CovenantContext.cs so that the constraints were set to cascade on deletion.
Line 108-124:
I had to create a new covenant.db, since I could not modify the constraints on the existing database tables. After the change, I was able to use the file explorer in my Grunts and then also successfully delete them.