Add org cleanup Rake tasks and shared Orgs::AssociationInspector#1259
Open
aaronskiba wants to merge 3 commits intointegrationfrom
Open
Add org cleanup Rake tasks and shared Orgs::AssociationInspector#1259aaronskiba wants to merge 3 commits intointegrationfrom
aaronskiba wants to merge 3 commits intointegrationfrom
Conversation
Generated by 🚫 Danger |
Remove org deletion from `CleanupUnmanagedOrgsWithUsersService`. Calling `orgs:delete_orphaned_orgs` after running this task can handle org deletion. This removes redundancies between the tasks.
e0c6a97 to
74872f2
Compare
orgs:delete_orphaned_orgs rake task74872f2 to
ea23a35
Compare
Adds several Rake tasks for cleaning up junk org and tracker data: 1. orgs:delete_junk_trackers - Deletes Tracker records with blank codes. - Partly addresses #1260. 2. orgs:cleanup_junk_funders - Finds "junk funders" (orgs with only `plans.funder` associations and a "junk" name) and sets `plan.funder_id = nil` for their plans. - Supports DRY_RUN=true, which outputs counts without mutating data. 3. orgs:delete_orphan_orgs - Deletes orphan orgs (no entries in any has_many, has_one, or HABTM associations). - Handles non-standard associations (`funded_plans` with `funder_id`) and polymorphic associations (`identifiers`). - Supports DRY_RUN=true, which outputs to-be-deleted orgs to `orphan_orgs.csv`. - Outputs deletion results per-org to `deleted_orphan_orgs.csv`. Introduces `Orgs::AssociationInspector` (app/services/orgs/association_inspector.rb) to share orphan org query logic between `delete_junk_trackers` and `cleanup_junk_funders`. Provides: - `orphan_orgs(allow_funded_plans_association: false)` to construct the base orphan orgs query. - Future-proofing via `verify_expected_associations!` guard against DB schema or association changes. **Notes / Recommendations for running tasks:** - Take a full DB dump for audit and rollback purposes before running cleanup tasks. - Recommended execution order: 1. delete_junk_trackers 2. cleanup_unmanaged_orgs_with_users 3. cleanup_junk_funders 4. delete_orphan_orgs (last) - DRY_RUN outputs for the cleanup tasks can be compared against the DB dump to verify expected changes before performing mutations.
ea23a35 to
38ba470
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes proposed in this PR:
Remove org deletion from
CleanupUnmanagedOrgsWithUsersServiceorgs:delete_orphan_orgsto reduce redundancy.New Rake tasks:
orgs:delete_junk_trackerstrackersdb data and address per org Google Analytics handling #1260.orgs:cleanup_junk_fundersplans.funderassociations and a "junk" name) and setsplan.funder_id = nil.DRY_RUN=true, outputs counts without mutating data.orgs:delete_orphan_orgsfunded_plans) and polymorphic (identifiers) associations.DRY_RUN=true, outputsorphan_orgs.csvanddeleted_orphan_orgs.csv.Orgs::AssociationInspectororphan_orgs(allow_funded_plans_association: false)to construct the base query.verify_expected_associations!to guard against DB schema changes.delete_junk_trackersandcleanup_junk_fundersto prevent duplicate logic.Execution notes / recommendations:
delete_junk_trackerscleanup_unmanaged_orgs_with_userscleanup_junk_fundersdelete_orphan_orgs(last)app/services/orgs/cleanup_junk_funders_service.rb) contains the list of known "junk" funder names.