Repository navigation
feat(ent): Add settlement mode for subscription and plan schemas - #4005
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 (12)
📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
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 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.
🧹 Nitpick comments (2)
openmeter/ent/schema/subscription.go (1)
57-61: Minor: Comment could be more precise.The comment says "The default settlement mode for subscriptions" but since this IS the subscription's settlement mode (and it's immutable), it's not really a "default" — it's the actual value. The Plan schema's comment makes sense as "default for subscriptions using this plan," but here it's just the subscription's settlement mode.
📝 Suggested comment tweak
field.Enum("settlement_mode"). GoType(productcatalog.SettlementMode("")). Default(string(productcatalog.CreditThenInvoiceSettlementMode)). Immutable(). - Comment("The default settlement mode for subscriptions."), + Comment("The settlement mode for this subscription."),🤖 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 57 - 61, Update the Comment on the field.Enum("settlement_mode") (the GoType productcatalog.SettlementMode, Default and Immutable call chain) to state that this is the subscription's settlement mode and is immutable (e.g., "The subscription's settlement mode; immutable once set."), instead of calling it a "default".tools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.up.sql (1)
1-4: Consider adding a CHECK constraint for enum values.The
character varyingcolumn type allows any string value, but the Ent schema restricts values to theSettlementModeenum (invoice_only,credit_then_invoice,credit_only). Adding a CHECK constraint would provide an extra layer of data integrity at the database level.That said, this is totally optional since Ent handles validation on the application side. If you're confident the app layer is the only write path, this is fine as-is.
💡 Optional: Add CHECK constraint
-- modify "plans" table -ALTER TABLE "plans" ADD COLUMN "settlement_mode" character varying NOT NULL DEFAULT 'credit_then_invoice'; +ALTER TABLE "plans" ADD COLUMN "settlement_mode" character varying NOT NULL DEFAULT 'credit_then_invoice' CHECK (settlement_mode IN ('invoice_only', 'credit_then_invoice', 'credit_only')); -- modify "subscriptions" table -ALTER TABLE "subscriptions" ADD COLUMN "settlement_mode" character varying NOT NULL DEFAULT 'credit_then_invoice'; +ALTER TABLE "subscriptions" ADD COLUMN "settlement_mode" character varying NOT NULL DEFAULT 'credit_then_invoice' CHECK (settlement_mode IN ('invoice_only', 'credit_then_invoice', 'credit_only'));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.up.sql` around lines 1 - 4, Add a DB-level CHECK constraint on the new settlement_mode columns to enforce the Ent enum values: in the ALTER TABLE statements for "plans" and "subscriptions" add a CHECK that settlement_mode IN ('invoice_only','credit_then_invoice','credit_only') (or create a shared CHECK constraint name like plans_settlement_mode_check and subscriptions_settlement_mode_check) so the "settlement_mode" columns only accept the three enum values declared in the Ent schema.
🤖 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/subscription.go`:
- Around line 57-61: Update the Comment on the field.Enum("settlement_mode")
(the GoType productcatalog.SettlementMode, Default and Immutable call chain) to
state that this is the subscription's settlement mode and is immutable (e.g.,
"The subscription's settlement mode; immutable once set."), instead of calling
it a "default".
In
`@tools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.up.sql`:
- Around line 1-4: Add a DB-level CHECK constraint on the new settlement_mode
columns to enforce the Ent enum values: in the ALTER TABLE statements for
"plans" and "subscriptions" add a CHECK that settlement_mode IN
('invoice_only','credit_then_invoice','credit_only') (or create a shared CHECK
constraint name like plans_settlement_mode_check and
subscriptions_settlement_mode_check) so the "settlement_mode" columns only
accept the three enum values declared in the Ent schema.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 83a1269f-2488-4248-b847-108d2569d719
⛔ Files ignored due to path filters (12)
openmeter/ent/db/migrate/schema.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**openmeter/ent/db/plan.gois excluded by!**/ent/db/**openmeter/ent/db/plan/plan.gois excluded by!**/ent/db/**openmeter/ent/db/plan/where.gois excluded by!**/ent/db/**openmeter/ent/db/plan_create.gois excluded by!**/ent/db/**openmeter/ent/db/plan_update.gois excluded by!**/ent/db/**openmeter/ent/db/subscription.gois excluded by!**/ent/db/**openmeter/ent/db/subscription/subscription.gois excluded by!**/ent/db/**openmeter/ent/db/subscription/where.gois excluded by!**/ent/db/**openmeter/ent/db/subscription_create.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (4)
openmeter/ent/schema/productcatalog.goopenmeter/ent/schema/subscription.gotools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.down.sqltools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.up.sql
630ea87 to
8eb7714
Compare
8eb7714 to
d403564
Compare
Add settlement mode enum for subscription and plan schemas
Summary by CodeRabbit