Skip to content

Add migration: make stripe_charge_id nullable, add manual_payment_id to earlybird purchases#788

Merged
olearycrew merged 1 commit intomainfrom
earlybird-manual-payment-migration
Mar 3, 2026
Merged

Add migration: make stripe_charge_id nullable, add manual_payment_id to earlybird purchases#788
olearycrew merged 1 commit intomainfrom
earlybird-manual-payment-migration

Conversation

@kilo-code-bot
Copy link
Contributor

@kilo-code-bot kilo-code-bot bot commented Mar 3, 2026

Summary

  • Makes the stripe_charge_id column on kiloclaw_earlybird_purchases nullable (was NOT NULL)
  • Adds a new nullable manual_payment_id column (text, UNIQUE) to support non-Stripe payment tracking

Details

This migration allows earlybird purchases to be recorded via manual payment in addition to Stripe. Both stripe_charge_id and manual_payment_id are nullable with unique constraints, so each purchase can be identified by either payment method.

Files changed

  • packages/db/src/schema.ts — updated Drizzle schema definition
  • packages/db/src/migrations/0041_earlybird_manual_payment.sql — migration SQL
  • packages/db/src/migrations/meta/0041_snapshot.json — Drizzle snapshot
  • packages/db/src/migrations/meta/_journal.json — journal entry for migration 0041

Built for Brendan by Kilo for Slack

…column

Allow earlybird purchases to be recorded via manual payment in addition
to Stripe by making stripe_charge_id nullable and adding a new nullable
manual_payment_id column with a unique constraint.
.references(() => kilocode_users.id, { onDelete: 'cascade' })
.unique(),
stripe_charge_id: text().notNull().unique(),
stripe_charge_id: text().unique(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WARNING: stripe_charge_id is now nullable and manual_payment_id is also nullable, but there is no CHECK constraint ensuring at least one of them is non-null. This means a row could be inserted with no payment reference at all, which is a data integrity risk.

Consider adding a check constraint like:

CHECK (stripe_charge_id IS NOT NULL OR manual_payment_id IS NOT NULL)

Also note: PostgreSQL UNIQUE constraints treat NULLs as distinct, so multiple rows with stripe_charge_id = NULL are allowed. The webhook idempotency for Stripe payments is still maintained via the user_id unique constraint, but this is worth being aware of.

@kilo-code-bot
Copy link
Contributor Author

kilo-code-bot bot commented Mar 3, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/db/src/schema.ts 3383 Both stripe_charge_id and manual_payment_id are nullable with no CHECK constraint ensuring at least one is non-null. A purchase row could be inserted with no payment reference.

SUGGESTION

File Line Issue
packages/db/src/schema.ts 3384 manual_payment_id column added but no insertion code in this PR — is there a follow-up PR?
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
packages/db/src/schema.ts 3373 Comment says "Unique on stripe_charge_id provides webhook idempotency" but stripe_charge_id is now nullable. This comment is stale and should be updated to reflect that idempotency is now primarily enforced by the user_id unique constraint.
Files Reviewed (4 files)
  • packages/db/src/schema.ts - 2 issues
  • packages/db/src/migrations/0041_earlybird_manual_payment.sql - 0 issues
  • packages/db/src/migrations/meta/0041_snapshot.json - skipped (generated)
  • packages/db/src/migrations/meta/_journal.json - 0 issues

Fix these issues in Kilo Cloud

@olearycrew olearycrew enabled auto-merge March 3, 2026 22:17
@olearycrew olearycrew merged commit c3bf03b into main Mar 3, 2026
13 checks passed
@olearycrew olearycrew deleted the earlybird-manual-payment-migration branch March 3, 2026 22:17
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