Skip to content

Script to migrate legacy customers to new pricing#11590

Merged
Betree merged 1 commit intomainfrom
feat/migrate-billing-script
Apr 1, 2026
Merged

Script to migrate legacy customers to new pricing#11590
Betree merged 1 commit intomainfrom
feat/migrate-billing-script

Conversation

@Betree
Copy link
Copy Markdown
Member

@Betree Betree commented Mar 25, 2026

@Betree Betree self-assigned this Mar 25, 2026
@Betree Betree force-pushed the feat/migrate-billing-script branch 5 times, most recently from 3a50e5b to 1cfc01c Compare March 30, 2026 16:13
@Betree Betree changed the title WIP Script to migrate legacy customers to new pricing Mar 30, 2026
Comment thread scripts/billing/migrate-to-new-pricing.ts Outdated
Comment thread scripts/billing/migrate-to-new-pricing.ts Outdated
@Betree Betree force-pushed the feat/migrate-billing-script branch 3 times, most recently from 98180b6 to 1fab5a0 Compare March 31, 2026 08:25
Comment thread scripts/billing/migrate-to-new-pricing.ts Outdated
@Betree Betree force-pushed the feat/migrate-billing-script branch 2 times, most recently from 7209844 to c3b774b Compare April 1, 2026 07:38
@Betree Betree force-pushed the feat/migrate-billing-script branch from c3b774b to 1ac474d Compare April 1, 2026 08:00
@Betree Betree marked this pull request as ready for review April 1, 2026 08:07
.on('Transactions.createdAt', '>=', transactionCutoffDate),
)
.where('Collectives.deletedAt', 'is', null)
.where('Collectives.id', 'in', legacyHostToMigrate)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The database query at line 416 will fail if legacyHostToMigrate is empty, as the Kysely version used generates invalid SQL for empty IN clauses.
Severity: HIGH

Suggested Fix

Wrap the .where('Collectives.id', 'in', legacyHostToMigrate) call in a conditional guard to ensure it only runs when the legacyHostToMigrate array is not empty, for example: .$if(legacyHostToMigrate.length > 0, qb => qb.where('Collectives.id', 'in', legacyHostToMigrate)).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: scripts/billing/migrate-to-new-pricing.ts#L416

Potential issue: The database query on line 416 uses a `.where('Collectives.id', 'in',
legacyHostToMigrate)` clause. The version of Kysely in use (`0.28.14`) is known to
generate invalid SQL (`WHERE ... IN ()`) when the provided array is empty, which causes
a runtime database error and crashes the script. The `legacyHostToMigrate` array can
realistically be empty if, for example, the script is run after all migrations are
complete or if all candidate hosts are marked to be skipped. This will cause the
migration script to fail.

Did we get this right? 👍 / 👎 to inform future reviews.

@Betree Betree merged commit d9dd098 into main Apr 1, 2026
19 checks passed
@Betree Betree deleted the feat/migrate-billing-script branch April 1, 2026 08:14
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.

Script to migrate existing customers to new pricing

1 participant