Skip to content

feat(ent): Add settlement mode for subscription and plan schemas - #4005

Merged
tothandras merged 1 commit into
mainfrom
feat/add-settlement-mode-for-subscription-and-plan-schemas
Mar 25, 2026
Merged

tothandras merged 1 commit into
mainfrom
feat/add-settlement-mode-for-subscription-and-plan-schemas

Conversation

@mark-vass-konghq

@mark-vass-konghq mark-vass-konghq commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Add settlement mode enum for subscription and plan schemas

Summary by CodeRabbit

  • New Features
    • Added settlement mode configuration to plans and subscriptions. Both entities now support specifying settlement behavior, with "Credit Then Invoice" as the default mode.

@mark-vass-konghq mark-vass-konghq self-assigned this Mar 25, 2026
@mark-vass-konghq
mark-vass-konghq requested a review from a team as a code owner March 25, 2026 14:45
@mark-vass-konghq mark-vass-konghq added release-note/feature Release note: Exciting New Features area/billing labels Mar 25, 2026
@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9c42d356-53f9-4c33-b86c-5cbde2d10423

📥 Commits

Reviewing files that changed from the base of the PR and between 630ea87 and d403564.

⛔ Files ignored due to path filters (12)
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan/plan.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription/subscription.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription_create.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (4)
  • openmeter/ent/schema/productcatalog.go
  • openmeter/ent/schema/subscription.go
  • tools/migrate/migrations/20260325154250_add-settlement-mode-for-plan-and-subscription.down.sql
  • tools/migrate/migrations/20260325154250_add-settlement-mode-for-plan-and-subscription.up.sql
✅ Files skipped from review due to trivial changes (2)
  • tools/migrate/migrations/20260325154250_add-settlement-mode-for-plan-and-subscription.down.sql
  • tools/migrate/migrations/20260325154250_add-settlement-mode-for-plan-and-subscription.up.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • openmeter/ent/schema/subscription.go

📝 Walkthrough

Walkthrough

This PR adds a settlement_mode enum field to the Plan and Subscription entity schemas, both defaulting to CreditThenInvoiceSettlementMode. The subscription version is immutable. Corresponding database migrations add and manage the new column in both tables.

Changes

Cohort / File(s) Summary
Entity Schema Updates
openmeter/ent/schema/productcatalog.go, openmeter/ent/schema/subscription.go
Added settlement_mode enum field mapped to productcatalog.SettlementMode with default value CreditThenInvoiceSettlementMode. Subscription field marked immutable.
Database Migrations
tools/migrate/migrations/20260325154250_add-settlement-mode-for-plan-and-subscription.up.sql, tools/migrate/migrations/20260325154250_add-settlement-mode-for-plan-and-subscription.down.sql
Forward migration adds settlement_mode column (character varying, NOT NULL, default 'credit_then_invoice') to plans and subscriptions tables. Down migration drops the columns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • GAlexIHU
  • tothandras
🚥 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 clearly and accurately summarizes the main change: adding a settlement_mode field to both subscription and plan schemas.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-settlement-mode-for-subscription-and-plan-schemas

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.

🧹 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 varying column type allows any string value, but the Ent schema restricts values to the SettlementMode enum (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

📥 Commits

Reviewing files that changed from the base of the PR and between e9db96f and 630ea87.

⛔ Files ignored due to path filters (12)
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan/plan.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/plan_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription/subscription.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/subscription_create.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (4)
  • openmeter/ent/schema/productcatalog.go
  • openmeter/ent/schema/subscription.go
  • tools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.down.sql
  • tools/migrate/migrations/20260325143618_add-settlement-mode-for-plan-and-subscription.up.sql

@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-settlement-mode-for-subscription-and-plan-schemas branch from 630ea87 to 8eb7714 Compare March 25, 2026 15:36
Comment thread openmeter/ent/schema/productcatalog.go Resolved
Comment thread openmeter/ent/schema/subscription.go Resolved
@mark-vass-konghq
mark-vass-konghq force-pushed the feat/add-settlement-mode-for-subscription-and-plan-schemas branch from 8eb7714 to d403564 Compare March 25, 2026 15:48
@tothandras
tothandras merged commit 37d4d5e into main Mar 25, 2026
24 checks passed
@tothandras
tothandras deleted the feat/add-settlement-mode-for-subscription-and-plan-schemas branch March 25, 2026 16:11

This branch was previously deployed

1 inactive deployment
dev — d4035648 Deployed Mar 25, 2026 by mark-vass-konghq via Migration Checks #12866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants