Skip to content

feat(ent): add tax code schema - #3885

Merged
tothandras merged 8 commits into
mainfrom
feat/tax-codes-v3-ent-schema
Feb 23, 2026
Merged

tothandras merged 8 commits into
mainfrom
feat/tax-codes-v3-ent-schema

Conversation

@borbelyr-kong

@borbelyr-kong borbelyr-kong commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Documentation

    • Fixed a typo and improved formatting in the database migration guide.
  • New Features

    • Added tax code support with app-specific mappings stored as JSON.
    • Introduced persistent tax codes storage and indexes, plus migrations to create and rollback the tax codes table.

@borbelyr-kong borbelyr-kong added the release-note/ignore Ignore this change when generating release notes label Feb 20, 2026
@borbelyr-kong
borbelyr-kong requested a review from a team as a code owner February 20, 2026 09:14
@coderabbitai

coderabbitai Bot commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new TaxCode Ent schema with a JSONB-backed app_mappings field and JSON value scanner, introduces SQL migrations to create/drop the tax_codes table with indexes (including a partial unique index on (namespace,key) where deleted_at IS NULL), and fixes a typo and formatting in the migration docs.

Changes

Cohort / File(s) Summary
Documentation
docs/database-migration.md
Fixed typo ("calue" → "value") and added a blank line before a code block for formatting.
New Ent schema
openmeter/ent/schema/tax_code.go
Added TaxCode schema and types (TaxCodeAppMapping, TaxCodeAppMappings), introduced app_mappings field stored as Postgres jsonb with GoType and JSON string value scanner, and attached entutils.UniqueResourceMixin.
Migrations (up)
tools/migrate/migrations/20260220092326_tax-code.up.sql
Creates tax_codes table with app_mappings jsonb, primary key and indexes: unique taxcode_id, index on namespace, unique (namespace,id), and partial unique index taxcode_namespace_key on (namespace,key) WHERE deleted_at IS NULL.
Migrations (down)
tools/migrate/migrations/20260220092326_tax-code.down.sql
Rollback script dropping tax_codes-related indexes and the tax_codes table.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

release-note/misc

Suggested reviewers

  • gergely-kurucz-konghq
  • chrisgacsal
  • GAlexIHU
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(ent): add tax code schema' accurately describes the main change—introducing a new TaxCode schema module with supporting database migrations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/tax-codes-v3-ent-schema

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Pre-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 | 🟡 Minor

Update schema path reference in documentation.

Line 3 references internal/ent/schema, but the actual schema directory is at openmeter/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: TaxCodeAppMappings slice doesn't enforce uniqueness per AppType — consider a map representation.

As a []TaxCodeAppMapping, nothing prevents storing two entries with the same AppType, which creates ambiguity about which tax code wins at read time. A map[app.AppType]string representation 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]string

If you do need to retain the full struct per entry (to support future fields), a validation helper on TaxCodeAppMappings is 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.

Comment thread openmeter/ent/schema/tax_code.go Resolved
Comment thread openmeter/ent/schema/tax_code.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tools/migrate/migrations/20260220092326_tax-code.up.sql (1)

12-12: Worth considering a GIN index on app_mappings down the road.

If you'll be querying app_mappings by 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.

@borbelyr-kong
borbelyr-kong marked this pull request as draft February 20, 2026 10:44
@borbelyr-kong
borbelyr-kong marked this pull request as ready for review February 20, 2026 11:43
tothandras
tothandras previously approved these changes Feb 23, 2026
Base automatically changed from feat/tax-codes-v3 to main February 23, 2026 10:34
@tothandras
tothandras dismissed their stale review February 23, 2026 10:34

The base branch was changed.

@tothandras
tothandras force-pushed the feat/tax-codes-v3-ent-schema branch from 8b4de88 to e6d90d0 Compare February 23, 2026 11:55
@tothandras
tothandras merged commit cf041a1 into main Feb 23, 2026
25 checks passed
@tothandras
tothandras deleted the feat/tax-codes-v3-ent-schema branch February 23, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants