Skip to content

fix(coupon): Coupon code column missing NOT NULL constraint in database#5500

Merged
murparreira merged 7 commits into
mainfrom
fix/coupon-code-not-null
May 19, 2026
Merged

fix(coupon): Coupon code column missing NOT NULL constraint in database#5500
murparreira merged 7 commits into
mainfrom
fix/coupon-code-not-null

Conversation

@murparreira
Copy link
Copy Markdown
Contributor

Context

The coupons table allows NULL values for the code column, meaning a coupon can be created via the API without providing a code. This is inconsistent with our public API documentation, which marks code as a required field and every other model with a code column (add_on, billable_metric, plan, billing_entity, tax, pricing_unit, charge, etc.) which all have NOT NULL at the DB level.

Description

Add presence: true to the model and required: true in GraphQL, stops new NULLs from being created.
Included a data migration to assign auto-generated codes to any existing NULL-code coupons and the NOT NULL clause on the code.

Copy link
Copy Markdown
Contributor

@groyoh groyoh left a comment

Choose a reason for hiding this comment

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

Could you please also regression tests to ensure sending nil code will be failing both on the API and GraphQL ?

Comment thread db/migrate/20260512155310_add_not_null_to_coupon_code.rb Outdated
Comment thread db/migrate/20260512155310_add_not_null_to_coupon_code.rb Outdated
Comment thread app/graphql/types/coupons/create_input.rb
Comment thread db/migrate/20260512155310_add_not_null_to_coupon_code.rb Outdated
Comment thread db/migrate/20260512155310_add_not_null_to_coupon_code.rb Outdated
@murparreira murparreira requested a review from groyoh May 13, 2026 14:25
Copy link
Copy Markdown
Contributor

@groyoh groyoh left a comment

Choose a reason for hiding this comment

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

I believe we're still missing a non-regression test on the graphQL/api side.

Comment thread db/migrate/20260512155310_backfill_coupon_codes.rb
@murparreira murparreira merged commit 4266c3d into main May 19, 2026
13 checks passed
@murparreira murparreira deleted the fix/coupon-code-not-null branch May 19, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants