Script to migrate legacy customers to new pricing#11590
Merged
Conversation
3a50e5b to
1cfc01c
Compare
Betree
commented
Mar 30, 2026
98180b6 to
1fab5a0
Compare
Betree
commented
Mar 31, 2026
7209844 to
c3b774b
Compare
c3b774b to
1ac474d
Compare
| .on('Transactions.createdAt', '>=', transactionCutoffDate), | ||
| ) | ||
| .where('Collectives.deletedAt', 'is', null) | ||
| .where('Collectives.id', 'in', legacyHostToMigrate) |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve opencollective/opencollective#8681