Repository navigation
feat(ent): add tax code schema - #3885
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a new TaxCode Ent schema with a JSONB-backed Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
docs/database-migration.md (2)
25-25:⚠️ Potential issue | 🟡 MinorPre-existing typo: "found int the package" → "found in the package".
Not introduced by this PR, but since you're already touching this file, a one-word fix while you're here would be nice.
✏️ Proposed fix
-To test your data migrations in hypothetical scenarios, you can use the `tools/migrate` package to write assertions on how data changes after applying the migration. Examples can be found int the package. +To test your data migrations in hypothetical scenarios, you can use the `tools/migrate` package to write assertions on how data changes after applying the migration. Examples can be found in the package.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/database-migration.md` at line 25, Fix the typo in the sentence containing "found int the package": change "int" to "in" so the sentence reads "found in the package"; locate the exact phrase "found int the package" in the docs/database-migration.md content and update it to "found in the package".
3-3:⚠️ Potential issue | 🟡 MinorUpdate schema path reference in documentation.
Line 3 references
internal/ent/schema, but the actual schema directory is atopenmeter/ent/schema. The docs need a quick update to point readers to the correct location.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/database-migration.md` at line 3, The docs reference the wrong ent schema directory; replace the `internal/ent/schema` reference with the actual schema path `openmeter/ent/schema` in the Database Migration docs (docs/database-migration.md) so readers are pointed to the correct `ent` schema location.
🧹 Nitpick comments (1)
openmeter/ent/schema/tax_code.go (1)
11-16:TaxCodeAppMappingsslice doesn't enforce uniqueness perAppType— consider a map representation.As a
[]TaxCodeAppMapping, nothing prevents storing two entries with the sameAppType, which creates ambiguity about which tax code wins at read time. Amap[app.AppType]stringrepresentation would be self-deduplicating and a bit more explicit. If the slice is intentional (e.g., for ordering or future additional fields), consider adding a validation helper or documenting the intended uniqueness invariant so callers don't accidentally create duplicates.♻️ Map-based alternative
-type TaxCodeAppMappings []TaxCodeAppMapping +// TaxCodeAppMappings maps each app type to its tax code string. +type TaxCodeAppMappings map[app.AppType]stringIf you do need to retain the full struct per entry (to support future fields), a validation helper on
TaxCodeAppMappingsis a solid middle ground:// Validate returns an error if any AppType appears more than once. func (m TaxCodeAppMappings) Validate() error { seen := make(map[app.AppType]struct{}, len(m)) for _, entry := range m { if _, ok := seen[entry.AppType]; ok { return fmt.Errorf("duplicate app_type: %s", entry.AppType) } seen[entry.AppType] = struct{}{} } return nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/ent/schema/tax_code.go` around lines 11 - 16, TaxCodeAppMappings currently is a []TaxCodeAppMapping which allows duplicate entries for the same app.AppType and causes ambiguity; either change the type to a map (map[app.AppType]string) to enforce uniqueness, or keep the slice but add a validation helper on TaxCodeAppMappings (e.g., a Validate method) that iterates entries of TaxCodeAppMapping and errors on duplicate AppType values; update any constructors/parsers to populate the map or call Validate before persisting/using the slice.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/ent/schema/tax_code.go`:
- Line 18: Update the top-of-file/type doc comment for TaxCode: change "Tax code
stores information about an entities tax code" to "Tax code stores information
about an entity's tax code" (ensure the comment remains the package/type comment
for TaxCode in tax_code.go so it still follows Go doc conventions).
- Around line 29-42: The new TaxCode schema (see TaxCode.Fields and the
TaxCodeAppMappingsValueScanner/TaxCodeAppMappings types) requires a versioned DB
migration; run the Atlas diff command (e.g. `atlas migrate --env local diff
add_tax_code`) to generate the migration files and then add the generated files
into the project's migration folder (tools/migrate/migrations/) so the schema
change for TaxCode is applied in production.
---
Outside diff comments:
In `@docs/database-migration.md`:
- Line 25: Fix the typo in the sentence containing "found int the package":
change "int" to "in" so the sentence reads "found in the package"; locate the
exact phrase "found int the package" in the docs/database-migration.md content
and update it to "found in the package".
- Line 3: The docs reference the wrong ent schema directory; replace the
`internal/ent/schema` reference with the actual schema path
`openmeter/ent/schema` in the Database Migration docs
(docs/database-migration.md) so readers are pointed to the correct `ent` schema
location.
---
Nitpick comments:
In `@openmeter/ent/schema/tax_code.go`:
- Around line 11-16: TaxCodeAppMappings currently is a []TaxCodeAppMapping which
allows duplicate entries for the same app.AppType and causes ambiguity; either
change the type to a map (map[app.AppType]string) to enforce uniqueness, or keep
the slice but add a validation helper on TaxCodeAppMappings (e.g., a Validate
method) that iterates entries of TaxCodeAppMapping and errors on duplicate
AppType values; update any constructors/parsers to populate the map or call
Validate before persisting/using the slice.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tools/migrate/migrations/20260220092326_tax-code.up.sql (1)
12-12: Worth considering a GIN index onapp_mappingsdown the road.If you'll be querying
app_mappingsby its contents — e.g.,WHERE app_mappings @> '[{"app_type": "stripe"}]'— a GIN index will be a big win for performance. No action needed right now if there are no such queries planned, just something to keep in mind as usage grows.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tools/migrate/migrations/20260220092326_tax-code.up.sql` at line 12, Add a GIN index on the jsonb column app_mappings to speed up containment queries (e.g., WHERE app_mappings @> ...); create a new migration that adds the index (using CREATE INDEX CONCURRENTLY) with a clear name like idx_<table>_app_mappings_gin and choose either the default gin operator class or jsonb_path_ops if you only need containment queries, and include a matching down migration to drop the index.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tools/migrate/migrations/20260220092326_tax-code.up.sql`:
- Line 22: The UNIQUE index "taxcode_namespace_key_deleted_at" on table
"tax_codes" uses ("namespace","key","deleted_at") which does not prevent
duplicate active rows because NULLs are distinct; replace it with a partial
unique index on ("namespace","key") that applies only to active records (WHERE
"deleted_at" IS NULL) so active (deleted_at IS NULL) rows are truly unique for
the (namespace, key) pair and restore the intended constraint.
---
Duplicate comments:
In `@openmeter/ent/schema/tax_code.go`:
- Line 19: Update the file-level comment in openmeter/ent/schema/tax_code.go to
fix the grammar: change "// Tax code stores information about an entities tax
code" to use the possessive form ("an entity's tax code"); locate the comment
above the TaxCode schema/struct declaration (TaxCode) and replace the text
accordingly so the message reads "Tax code stores information about an entity's
tax code".
---
Nitpick comments:
In `@tools/migrate/migrations/20260220092326_tax-code.up.sql`:
- Line 12: Add a GIN index on the jsonb column app_mappings to speed up
containment queries (e.g., WHERE app_mappings @> ...); create a new migration
that adds the index (using CREATE INDEX CONCURRENTLY) with a clear name like
idx_<table>_app_mappings_gin and choose either the default gin operator class or
jsonb_path_ops if you only need containment queries, and include a matching down
migration to drop the index.
d6221fa to
d062113
Compare
8b4de88 to
e6d90d0
Compare
Summary by CodeRabbit
Documentation
New Features