Repository navigation
Feat/tax codes v3 add fk keys - #3941
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 (1)
📝 WalkthroughWalkthroughThis PR adds a TaxMixin (tax_code_id, tax_behavior) and connects many schemas to a new TaxCode entity via unique Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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)
📝 Coding Plan
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: 4
🧹 Nitpick comments (1)
openmeter/ent/schema/taxcode.go (1)
14-14: Minor: import ordering.The
mixinimport fromentgo.io/ent/schema/mixinis placed after the local imports. Consider grouping it with the otherentgo.ioimports at lines 4-9 for consistency.Suggested import organization
import ( "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" + "entgo.io/ent/schema/mixin" "github.com/openmeterio/openmeter/openmeter/productcatalog" "github.com/openmeterio/openmeter/openmeter/taxcode" "github.com/openmeterio/openmeter/pkg/framework/entutils" - "entgo.io/ent/schema/mixin" )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/ent/schema/taxcode.go` at line 14, The import ordering in taxcode.go is inconsistent: move the "entgo.io/ent/schema/mixin" import so it is grouped with the other entgo.io imports (the existing entgo.io/ent and entgo.io/ent/schema/* imports) to match the project's import grouping conventions; update the import block in taxcode.go so mixin appears alongside the other entgo.io entries to keep imports organized and consistent.
🤖 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/billing.go`:
- Around line 186-187: The create builders for CustomerOverride, InvoiceLine and
DetailedLine need to persist the new TaxMixin fields: update the builder chains
in the functions that construct customer overrides and invoice/detailed lines to
call the generated nillable setters (e.g. SetNillableTaxCodeID(...) and
SetNillableTaxBehavior(...)) using the source object's tax fields (e.g.
src.TaxCodeID, src.TaxBehavior or equivalent), so NULL is only stored when the
source is nil; apply this change to the create chains currently in the customer
override creator and the invoice line / detailed line creators so the new
relationship is actually set on insert.
- Around line 170-173: Add explicit indexes for the new tax_code_id foreign-key
fields so Postgres won't rely on table scans: for each schema that defines
edge.From("tax_code", TaxCode.Type).Ref(...).Field("tax_code_id") (e.g.,
billing_workflow_configs, billing_invoice_lines and the other schemas at the
referenced locations), add an index via index.Fields("tax_code_id") in the ent
schema definition (or ensure a separate migration creates those indexes). Update
the schema methods that declare tax_code_id to include index declaration so FK
checks/queries on TaxCode use the index.
In `@openmeter/ent/schema/productcatalog.go`:
- Around line 176-179: rateCardBulkCreate currently omits the TaxMixin fields so
PlanRateCard rows are created without tax_code_id and tax_behavior; update
rateCardBulkCreate in the plan adapter to read tax fields from the input
rate-card DTO and populate the PlanRateCard creation calls with tax_code_id (or
set the tax_code edge) and tax_behavior so the TaxMixin and tax_code
relationship are persisted for each created PlanRateCard. Ensure you use the
same field/edge names used in the schema (TaxMixin, tax_code, tax_code_id,
tax_behavior, PlanRateCard) when mapping incoming data to the entity creation.
In `@openmeter/ent/schema/subscription.go`:
- Around line 228-231: The Create() method in subscriptionitemrepo.go currently
omits setting the subscription item's tax fields, so tax_code_id and
tax_behavior (defined in the SubscriptionItem schema edge/fields) remain NULL;
update Create() to pull tax info from the rate card/rate data and call
SetTaxCodeID(...) and SetTaxBehavior(...) on the Ent builder (the same builder
where other fields are SetXxx) before Save(), ensuring you handle nullable
values (only call setters when data exists) and use the same identifiers
SetTaxCodeID and SetTaxBehavior to wire the schema fields through.
---
Nitpick comments:
In `@openmeter/ent/schema/taxcode.go`:
- Line 14: The import ordering in taxcode.go is inconsistent: move the
"entgo.io/ent/schema/mixin" import so it is grouped with the other entgo.io
imports (the existing entgo.io/ent and entgo.io/ent/schema/* imports) to match
the project's import grouping conventions; update the import block in taxcode.go
so mixin appears alongside the other entgo.io entries to keep imports organized
and consistent.
🪄 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: b6a261fb-3c39-415f-aa16-4d246a845425
⛔ Files ignored due to path filters (60)
openmeter/ent/db/addonratecard.gois excluded by!**/ent/db/**openmeter/ent/db/addonratecard/addonratecard.gois excluded by!**/ent/db/**openmeter/ent/db/addonratecard/where.gois excluded by!**/ent/db/**openmeter/ent/db/addonratecard_create.gois excluded by!**/ent/db/**openmeter/ent/db/addonratecard_query.gois excluded by!**/ent/db/**openmeter/ent/db/addonratecard_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingcustomeroverride.gois excluded by!**/ent/db/**openmeter/ent/db/billingcustomeroverride/billingcustomeroverride.gois excluded by!**/ent/db/**openmeter/ent/db/billingcustomeroverride/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingcustomeroverride_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingcustomeroverride_query.gois excluded by!**/ent/db/**openmeter/ent/db/billingcustomeroverride_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/billinginvoiceline.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_query.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoiceline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicesplitlinegroup.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicesplitlinegroup/billinginvoicesplitlinegroup.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicesplitlinegroup/where.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicesplitlinegroup_create.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicesplitlinegroup_query.gois excluded by!**/ent/db/**openmeter/ent/db/billinginvoicesplitlinegroup_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/billingstandardinvoicedetailedline.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_query.gois excluded by!**/ent/db/**openmeter/ent/db/billingstandardinvoicedetailedline_update.gois excluded by!**/ent/db/**openmeter/ent/db/billingworkflowconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billingworkflowconfig/billingworkflowconfig.gois excluded by!**/ent/db/**openmeter/ent/db/billingworkflowconfig/where.gois excluded by!**/ent/db/**openmeter/ent/db/billingworkflowconfig_create.gois excluded by!**/ent/db/**openmeter/ent/db/billingworkflowconfig_query.gois excluded by!**/ent/db/**openmeter/ent/db/billingworkflowconfig_update.gois excluded by!**/ent/db/**openmeter/ent/db/client.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/planratecard.gois excluded by!**/ent/db/**openmeter/ent/db/planratecard/planratecard.gois excluded by!**/ent/db/**openmeter/ent/db/planratecard/where.gois excluded by!**/ent/db/**openmeter/ent/db/planratecard_create.gois excluded by!**/ent/db/**openmeter/ent/db/planratecard_query.gois excluded by!**/ent/db/**openmeter/ent/db/planratecard_update.gois excluded by!**/ent/db/**openmeter/ent/db/setorclear.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem/subscriptionitem.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem/where.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_create.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_query.gois excluded by!**/ent/db/**openmeter/ent/db/subscriptionitem_update.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/taxcode.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode/where.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_create.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_query.gois excluded by!**/ent/db/**openmeter/ent/db/taxcode_update.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (9)
openmeter/ent/schema/addon.goopenmeter/ent/schema/billing.goopenmeter/ent/schema/productcatalog.goopenmeter/ent/schema/subscription.goopenmeter/ent/schema/taxcode.gotools/migrate/migrations/20260305143430_tax-code-fks.down.sqltools/migrate/migrations/20260305143430_tax-code-fks.up.sqltools/migrate/migrations/20260311101915_add_tax_behavior.down.sqltools/migrate/migrations/20260311101915_add_tax_behavior.up.sql
| edge.From("tax_code", TaxCode.Type). | ||
| Ref("billing_workflow_configs"). | ||
| Field("tax_code_id"). | ||
| Unique(), |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Schema-side index definitions for tax_code_id:"
rg -n -C2 'index\.Fields\("tax_code_id"\)|index\.Fields\("namespace",\s*"tax_code_id"\)' openmeter/ent/schema || true
echo
echo "SQL index definitions for tax_code_id:"
rg -n -i -C2 'create( unique)? index .*tax_code_id' -g '*.sql' || trueRepository: openmeterio/openmeter
Length of output: 151
🏁 Script executed:
# First, let's look at the actual billing.go file to see the foreign key definitions
wc -l openmeter/ent/schema/billing.goRepository: openmeterio/openmeter
Length of output: 101
🏁 Script executed:
# Check the structure and find all tax_code_id references
rg -n "tax_code_id" openmeter/ent/schema/billing.goRepository: openmeterio/openmeter
Length of output: 209
🏁 Script executed:
# Look for how indexes are typically defined in ent schema files
fd "\.go$" openmeter/ent/schema | head -5 | xargs -I {} rg -l "index\.Fields" {}Repository: openmeterio/openmeter
Length of output: 241
🏁 Script executed:
# Check for any migration files related to tax_code
fd "\.sql$" | rg -i "tax_code|migration" | head -20Repository: openmeterio/openmeter
Length of output: 1372
🏁 Script executed:
# Let's check an example schema file to see how indexes are defined
head -100 openmeter/ent/schema/addon.go | rg -A5 "Indexes"Repository: openmeterio/openmeter
Length of output: 236
🏁 Script executed:
# Now let's look at the specific lines in billing.go where tax_code_id is defined
sed -n '165,180p' openmeter/ent/schema/billing.go
sed -n '270,280p' openmeter/ent/schema/billing.go
sed -n '490,505p' openmeter/ent/schema/billing.go
sed -n '710,725p' openmeter/ent/schema/billing.go
sed -n '960,975p' openmeter/ent/schema/billing.goRepository: openmeterio/openmeter
Length of output: 1941
🏁 Script executed:
# Check the latest migration files for tax_code_id indexes
ls -ltr tools/migrate/migrations/*.sql | tail -10 | awk '{print $NF}' | xargs -I {} sh -c 'echo "=== {} ===" && rg -i "tax_code_id" {}'Repository: openmeterio/openmeter
Length of output: 846
🏁 Script executed:
# Search for when tax_code was added to these entities - check git history or migration files
fd "\.sql$" tools/migrate/migrations | xargs rg -l "tax_code" | sortRepository: openmeterio/openmeter
Length of output: 620
🏁 Script executed:
# Look at one of those migration files to see if indexes were added
cat tools/migrate/migrations/20250107094857_billing-tax-codes.up.sql 2>/dev/null || echo "File not found, let me search more broadly"Repository: openmeterio/openmeter
Length of output: 107
🏁 Script executed:
# Find migration files that mention billing tables and tax_code
fd "\.sql$" tools/migrate/migrations | xargs rg -l "billing" | xargs rg -l "tax_code"Repository: openmeterio/openmeter
Length of output: 506
🏁 Script executed:
# Check if there's an Indexes() method in billing.go schema for these entities
rg -n "func \(.*\) Indexes\(\)" openmeter/ent/schema/billing.goRepository: openmeterio/openmeter
Length of output: 930
🏁 Script executed:
# Check the latest migration that adds tax_code-fks
cat tools/migrate/migrations/20260305143430_tax-code-fks.up.sqlRepository: openmeterio/openmeter
Length of output: 2440
🏁 Script executed:
# Check the specific Indexes() methods for the affected entities
sed -n '158,175p' openmeter/ent/schema/billing.go
sed -n '254,270p' openmeter/ent/schema/billing.go
sed -n '432,450p' openmeter/ent/schema/billing.go
sed -n '682,700p' openmeter/ent/schema/billing.go
sed -n '939,960p' openmeter/ent/schema/billing.goRepository: openmeterio/openmeter
Length of output: 3039
Add indexes for the new tax_code_id foreign keys.
Postgres enforces these foreign keys but won't auto-index them. This means queries and FK checks on tax_codes updates/deletes could hit table scans—especially on billing_invoice_lines, which seems like a high-traffic table. Looking at the migration, the FKs are added without corresponding indexes. Consider adding schema indexes for these new columns (in the ent schema via index.Fields()), or verify they're in a separate migration. This matters for the performance-critical paths you're touching here.
Applies to: lines 170-173, 273-276, 494-497, 713-716, 964-967
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@openmeter/ent/schema/billing.go` around lines 170 - 173, Add explicit indexes
for the new tax_code_id foreign-key fields so Postgres won't rely on table
scans: for each schema that defines edge.From("tax_code",
TaxCode.Type).Ref(...).Field("tax_code_id") (e.g., billing_workflow_configs,
billing_invoice_lines and the other schemas at the referenced locations), add an
index via index.Fields("tax_code_id") in the ent schema definition (or ensure a
separate migration creates those indexes). Update the schema methods that
declare tax_code_id to include index declaration so FK checks/queries on TaxCode
use the index.
| TaxMixin{}, | ||
| } |
There was a problem hiding this comment.
Please wire these new tax fields into the current create builders.
Right now the schema can store tax_code_id / tax_behavior, but the existing inserts in openmeter/billing/adapter/customeroverride.go:35-40 and openmeter/billing/adapter/stdinvoicelines.go:84-104,453-472 still never set them. Because these mixin fields are nillable, ent won't fail here — it will just persist NULL on fresh overrides, invoice lines, and detailed lines, so the new relationship stays unused on those paths.
Also applies to: 311-312, 873-874
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@openmeter/ent/schema/billing.go` around lines 186 - 187, The create builders
for CustomerOverride, InvoiceLine and DetailedLine need to persist the new
TaxMixin fields: update the builder chains in the functions that construct
customer overrides and invoice/detailed lines to call the generated nillable
setters (e.g. SetNillableTaxCodeID(...) and SetNillableTaxBehavior(...)) using
the source object's tax fields (e.g. src.TaxCodeID, src.TaxBehavior or
equivalent), so NULL is only stored when the source is nil; apply this change to
the create chains currently in the customer override creator and the invoice
line / detailed line creators so the new relationship is actually set on insert.
| edge.From("tax_code", TaxCode.Type). | ||
| Ref("plan_rate_cards"). | ||
| Field("tax_code_id"). | ||
| Unique(), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check for tax field usage in plan adapter
rg -n "SetTaxCodeID|SetTaxBehavior|SetNillableTaxCodeID|SetNillableTaxBehavior" --type go openmeter/productcatalog/Repository: openmeterio/openmeter
Length of output: 47
🏁 Script executed:
# Find the adapter file and examine rateCardBulkCreate function
find openmeter/productcatalog -name "*.go" -type f | xargs grep -l "rateCardBulkCreate" 2>/dev/nullRepository: openmeterio/openmeter
Length of output: 159
🏁 Script executed:
# Check what fields PlanRateCard has in the schema
cat -n openmeter/ent/schema/productcatalog.go | sed -n '1,250p'Repository: openmeterio/openmeter
Length of output: 6308
🏁 Script executed:
# Look for TaxCodeID or TaxBehavior fields in PlanRateCard definition
ast-grep --pattern 'func (PlanRateCard) Fields() {
$$$
}'Repository: openmeterio/openmeter
Length of output: 47
🏁 Script executed:
# Find TaxMixin definition
find openmeter -name "*.go" -type f | xargs grep -l "type TaxMixin" 2>/dev/nullRepository: openmeterio/openmeter
Length of output: 96
🏁 Script executed:
# Look at the rateCardBulkCreate function in phase.go
grep -n "rateCardBulkCreate" openmeter/productcatalog/plan/adapter/phase.go -A 50Repository: openmeterio/openmeter
Length of output: 2345
🏁 Script executed:
# Check TaxMixin definition and what fields it adds
cat -n openmeter/ent/schema/taxcode.go | grep -A 20 "type TaxMixin"Repository: openmeterio/openmeter
Length of output: 533
🏁 Script executed:
# Check what asPlanRateCardRow function does and what it returns
grep -n "func asPlanRateCardRow" openmeter/productcatalog/plan/adapter/phase.go -A 30Repository: openmeterio/openmeter
Length of output: 47
🏁 Script executed:
# Check the RateCard schema to see what tax-related fields exist
cat -n openmeter/ent/schema/productcatalog.go | grep -A 50 "type RateCard struct"Repository: openmeterio/openmeter
Length of output: 47
🏁 Script executed:
# Search for RateCard schema definition
rg "type RateCard struct" --type go openmeter/ent/schema/Repository: openmeterio/openmeter
Length of output: 120
🏁 Script executed:
# Find the asPlanRateCardRow function more carefully
rg -n "asPlanRateCardRow" openmeter/productcatalog/plan/adapter/ -A 40Repository: openmeterio/openmeter
Length of output: 4963
🏁 Script executed:
# Check if TaxCodeID and TaxBehavior are being set in the adapter
rg -n "SetTaxCodeID|SetTaxBehavior|tax_code_id|tax_behavior" openmeter/productcatalog/plan/adapter/ --type goRepository: openmeterio/openmeter
Length of output: 47
Tax fields not wired in the plan adapter.
The schema adds TaxMixin (which provides tax_code_id and tax_behavior fields) and the new tax_code relationship, but rateCardBulkCreate in openmeter/productcatalog/plan/adapter/phase.go doesn't set these fields when creating PlanRateCard entities. Since they're nullable, this won't cause failures, but you'll need to wire them through before tax code functionality can actually work with plans.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@openmeter/ent/schema/productcatalog.go` around lines 176 - 179,
rateCardBulkCreate currently omits the TaxMixin fields so PlanRateCard rows are
created without tax_code_id and tax_behavior; update rateCardBulkCreate in the
plan adapter to read tax fields from the input rate-card DTO and populate the
PlanRateCard creation calls with tax_code_id (or set the tax_code edge) and
tax_behavior so the TaxMixin and tax_code relationship are persisted for each
created PlanRateCard. Ensure you use the same field/edge names used in the
schema (TaxMixin, tax_code, tax_code_id, tax_behavior, PlanRateCard) when
mapping incoming data to the entity creation.
| edge.From("tax_code", TaxCode.Type). | ||
| Ref("subscription_items"). | ||
| Field("tax_code_id"). | ||
| Unique(), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if TaxCodeID or TaxBehavior setters are used anywhere in subscription repo
rg -n "SetTaxCodeID|SetTaxBehavior|SetNillableTaxCodeID|SetNillableTaxBehavior" --type go openmeter/subscription/Repository: openmeterio/openmeter
Length of output: 47
🏁 Script executed:
# First, let's check the schema to verify nullable declarations
head -n 250 openmeter/ent/schema/subscription.go | tail -n 30Repository: openmeterio/openmeter
Length of output: 954
🏁 Script executed:
# Now let's look at the subscriptionitemrepo.go Create() method mentioned
sed -n '123,151p' openmeter/subscription/repo/subscriptionitemrepo.goRepository: openmeterio/openmeter
Length of output: 1450
🏁 Script executed:
# Search for any TODOs/FIXMEs related to tax in subscription code
rg -i "TODO|FIXME" --type go openmeter/subscription/ -A 2 | grep -i "tax\|TaxCode\|TaxBehavior" -B 2Repository: openmeterio/openmeter
Length of output: 47
🏁 Script executed:
# Look for tax_code_id and tax_behavior field definitions in schema
rg -n "tax_code_id|tax_behavior|TaxCodeID|TaxBehavior" openmeter/ent/schema/subscription.go -B 2 -A 2Repository: openmeterio/openmeter
Length of output: 194
🏁 Script executed:
# Check if these are new fields by looking at the full SubscriptionItem schema
rg -n "func.*SubscriptionItem.*Fields" openmeter/ent/schema/subscription.go -A 100Repository: openmeterio/openmeter
Length of output: 3409
The tax_code_id and tax_behavior fields aren't wired up yet in the adapter.
The schema edge and field are defined, but looking at subscriptionitemrepo.go's Create() method (lines 123-151), there's no SetTaxCodeID or SetTaxBehavior being called. Since these columns are nullable, new subscription items will just have NULL values for these fields.
Is this intentional for a follow-up, or should we wire through the tax info from the rate card now?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@openmeter/ent/schema/subscription.go` around lines 228 - 231, The Create()
method in subscriptionitemrepo.go currently omits setting the subscription
item's tax fields, so tax_code_id and tax_behavior (defined in the
SubscriptionItem schema edge/fields) remain NULL; update Create() to pull tax
info from the rate card/rate data and call SetTaxCodeID(...) and
SetTaxBehavior(...) on the Ent builder (the same builder where other fields are
SetXxx) before Save(), ensuring you handle nullable values (only call setters
when data exists) and use the same identifiers SetTaxCodeID and SetTaxBehavior
to wire the schema fields through.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/ent/schema/taxcode.go (1)
1-84: Reminder: Regenerate code and migrations.As per coding guidelines, don't forget to:
- Run
make generateto regenerate all Ent code- Run
atlas migrate --env local diff <migration-name>to generate the database migrations for the new FK columns and fieldsBased on learnings: "Regenerate Go code by running
make generateafter editing ent schema files inopenmeter/ent/schema/" and "Useatlas migrate --env local diff <migration-name>to generate database migrations after editing ent schema."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/ent/schema/taxcode.go` around lines 1 - 84, You added/modified Ent schema types (TaxCode, TaxMixin, TaxCodeAppMappingsValueScanner and fields like tax_code_id and tax_behavior) but haven't regenerated code or created DB migrations; run make generate to regenerate Ent code and then run atlas migrate --env local diff <migration-name> to produce migrations for the new/changed FK columns and JSON/enum fields so the code and database schema stay in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/ent/schema/taxcode.go`:
- Around line 1-84: You added/modified Ent schema types (TaxCode, TaxMixin,
TaxCodeAppMappingsValueScanner and fields like tax_code_id and tax_behavior) but
haven't regenerated code or created DB migrations; run make generate to
regenerate Ent code and then run atlas migrate --env local diff <migration-name>
to produce migrations for the new/changed FK columns and JSON/enum fields so the
code and database schema stay in sync.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 355a3ede-4f21-49c2-9df2-9690939e68ca
📒 Files selected for processing (1)
openmeter/ent/schema/taxcode.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/20260313135547_tax-code-fk.up.sql`:
- Around line 2-30: Split each foreign-key addition into two operations to avoid
long locks: add the FK constraint with NOT VALID, then run a separate ALTER
TABLE ... VALIDATE CONSTRAINT for each of the constraints listed (e.g.
addon_rate_cards_tax_codes_addon_rate_cards,
billing_customer_overrides_tax_codes_billing_customer_overrides,
billing_invoice_lines_tax_codes_billing_invoice_lines,
billing_invoice_split_line_groups_tax_codes_billing_invoice_spl,
billing_standard_invoice_detailed_lines_tax_codes_billing_stand,
billing_workflow_configs_tax_codes_billing_workflow_configs,
plan_rate_cards_tax_codes_plan_rate_cards,
subscription_items_tax_codes_subscription_items); keep the column additions
(tax_behavior, tax_code_id) and index creation as-is, only change the ADD
CONSTRAINT clauses to be NOT VALID and add a separate VALIDATE CONSTRAINT step
for each named constraint.
🪄 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: 2f751575-265f-4bc1-9448-a195a0e1906a
⛔ Files ignored due to path filters (2)
openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (3)
openmeter/ent/schema/taxcode.gotools/migrate/migrations/20260313135547_tax-code-fk.down.sqltools/migrate/migrations/20260313135547_tax-code-fk.up.sql
… and rate card schemas
360fb25 to
47540a1
Compare
Summary by CodeRabbit