HPC-8748: Introduce project deleting util method #119
Merged
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.
With this PR, we're starting work on properly cleaning up related data upon deletion - HPC-8748. I was thinking of introducing a generic method wrapper for DB models, which would allow you to specify all tables with weak references to that model (table). I am using term "weak references" for tables which have
objectId
-objectType
columns, which can have pointers to entities in other tables, without actual foreign keys. I have abandoned idea of a generic method for related data cleanup, because DB models would have to have reference outside tables, which goes against the separation of concerns and encapsulation.Thus, I am introducing deletion utility methods. They will give us much more flexibility about setting deletion conditions and cleanup rules for each different table. The downside is that we need to remember to call the util method and not just
model.destroy()
on some tables.To kickstart this idea of cleaning up properly after deletion, I have added utility method to delete a project and clean up afterwards. Along with that, I have added the possibility to delete just the latest version of the project - HPC-8746. We can already see that having utility method, rather than putting the logic into
project.destroy()
has advantages in allowing arbitrary complexity in logic.Regarding project deletion, tables
project
andprojectVersion
have weak references in other tables:projectVersion
:categoryRef
project
:budgetSegmentBreakdownEntity
flowObject
expiredData
(table is still not used, but we should clean it up anyway)authTarget
Table
budgetSegmentBreakdownEntity
has some records whereobjectType
is "projectVersion". However,objectId
values in these cases are actually pointing to project ID, not project version ID! Since this table is actually connected to project version by series of foreign keys, that means that deleting project also deletesbudgetSegmentBreakdownEntity
. That series of foreign keys isproject
->projectVersion
->budgetSegment
->budgetSegmentBreakdown
->budgetSegmentBreakdownEntity