fix(taxcode): dedupe tax_codes by app mapping#4448
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds a DB migration (20260527120000) that deduplicates tax_codes sharing identical app_mappings by selecting deterministic winners, repointing FK/JSONB references and rewriting invoice-line snapshots, soft-deleting losers, plus an end-to-end test and a documented no-op down migration. ChangesTax Code Deduplication Migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tools/migrate/dedupe_tax_codes_by_app_mapping_test.go (1)
296-334: 🏗️ Heavy liftGreat start—consider asserting all FK targets touched by the migration
The test currently verifies a subset of repointed columns, while the migration updates many FK-bearing tables. Expanding this to all updated targets would prevent silent regressions if one
UPDATEgets dropped or edited later.As per coding guidelines: "
**/*_test.go: Make sure the tests are comprehensive and cover the changes."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/migrate/dedupe_tax_codes_by_app_mapping_test.go` around lines 296 - 334, The test only asserts a subset of foreign-key repoints; update the test in dedupe_tax_codes_by_app_mapping_test.go to assert every FK target the migration modifies using the same pattern as the existing checks (use db.QueryRow(...).Scan(...) and require.Equal(t, group1Winner, ...)). Locate the assertion block using the variables wfcRowID, prcRowID, subItemID, flatFeeID, orgDTCID and add equivalent queries/assertions for each additional table/column the migration updates so all FK-bearing tables are covered by the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@tools/migrate/migrations/20260527120000_dedupe_tax_codes_by_app_mapping.up.sql`:
- Around line 41-46: The new `_tax_code_dedup_map` can contain the same loser_id
mapped to multiple distinct winner_id values due to multiple TaxCodeAppMappings;
add a post-population check that detects any loser_id with more than one
distinct winner_id (e.g., GROUP BY loser_id HAVING COUNT(DISTINCT winner_id) >
1) and immediately abort the migration with a clear RAISE EXCEPTION message if
any rows are found; perform this check before any UPDATE ... FROM
_tax_code_dedup_map and before creating any FK/indexes so the migration fails
fast and deterministically when the mapping isn’t one-to-one.
---
Nitpick comments:
In `@tools/migrate/dedupe_tax_codes_by_app_mapping_test.go`:
- Around line 296-334: The test only asserts a subset of foreign-key repoints;
update the test in dedupe_tax_codes_by_app_mapping_test.go to assert every FK
target the migration modifies using the same pattern as the existing checks (use
db.QueryRow(...).Scan(...) and require.Equal(t, group1Winner, ...)). Locate the
assertion block using the variables wfcRowID, prcRowID, subItemID, flatFeeID,
orgDTCID and add equivalent queries/assertions for each additional table/column
the migration updates so all FK-bearing tables are covered by the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b083803b-9651-4dd3-8da1-bdf425ee6afb
⛔ Files ignored due to path filters (1)
tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (3)
tools/migrate/dedupe_tax_codes_by_app_mapping_test.gotools/migrate/migrations/20260527120000_dedupe_tax_codes_by_app_mapping.down.sqltools/migrate/migrations/20260527120000_dedupe_tax_codes_by_app_mapping.up.sql
|
Actionable comments posted: 0 |
9da8058 to
dcfaf7d
Compare
|
Actionable comments posted: 0 |
Summary by CodeRabbit