Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPC-8748: Introduce project deleting util method #119

Merged
merged 3 commits into from
Jun 21, 2024
Merged

HPC-8748: Introduce project deleting util method #119

merged 3 commits into from
Jun 21, 2024

Conversation

Pl217
Copy link
Contributor

@Pl217 Pl217 commented Jun 1, 2023

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 and projectVersion 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 where objectType 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 deletes budgetSegmentBreakdownEntity. That series of foreign keys is project->projectVersion->budgetSegment->budgetSegmentBreakdown->budgetSegmentBreakdownEntity

@Pl217 Pl217 added the ready for review All comments have been addressed, and the Pull Request is ready for review label Jun 1, 2023
@Pl217 Pl217 requested a review from a team as a code owner June 1, 2023 15:06
@Delgee Delgee assigned Pl217 and unassigned Delgee Jun 5, 2023
@Delgee Delgee added ready for merge Review and testing is complete. It is ready for merging as soon as CI has finished. and removed ready for review All comments have been addressed, and the Pull Request is ready for review labels Jun 5, 2023
When a project is being deleted, a bunch of
pre-requisites need to be fulfilled. Then,
in case that deletion can successfully go
through, we also need to clean up any references
to the project, especially those which are
not cleaned up automatically by DB's
`ON DELETE CASCADE` foreign key constraints.
@Pl217 Pl217 enabled auto-merge June 21, 2024 08:58
@Pl217 Pl217 merged commit b3d5fd6 into develop Jun 21, 2024
2 checks passed
@Pl217 Pl217 deleted the HPC-8748 branch June 21, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge Review and testing is complete. It is ready for merging as soon as CI has finished.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants