-
Notifications
You must be signed in to change notification settings - Fork 355
feat(Migrator): allow passing transactions to Migrator.
#1480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jlucaso1
wants to merge
7
commits into
kysely-org:next
Choose a base branch
from
jlucaso1:fix/migrator-trx-disabletransactions
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(Migrator): allow passing transactions to Migrator.
#1480
jlucaso1
wants to merge
7
commits into
kysely-org:next
from
jlucaso1:fix/migrator-trx-disabletransactions
+47
−1
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
commit: |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey 👋
Thanks! 🙏
Left some comments.
This is not a fix. This is a whole use case that wasn't considered.
Migrator.
…tions` Previously, initializing Migrator with a `Transaction` instance (`trx`) and `disableTransactions: true` would lead to an error because Migrator would attempt `trx.connection()`. This change ensures that if `db` is already a `Transaction` and `disableTransactions` is true, the Migrator uses the provided `trx` directly, enabling transactional dry-runs.
7283087 to
84fcd27
Compare
Co-authored-by: Igal Klebanov <[email protected]>
Co-authored-by: Igal Klebanov <[email protected]>
Co-authored-by: Igal Klebanov <[email protected]>
Co-authored-by: Igal Klebanov <[email protected]>
Co-authored-by: Igal Klebanov <[email protected]>
Co-authored-by: Igal Klebanov <[email protected]>
|
Any updates on this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
migrations
Related to migrations
mssql
Related to MS SQL Server (MSSQL)
postgres
Related to PostgreSQL
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.
Hey team!
This PR addresses an issue where the
Migratorwould unexpectedly fail if initialized with a KyselyTransactioninstance (trx) whiledisableTransactionswas set totrue. The Migrator was attempting to calltrx.connection(), which isn't a supported operation on aTransactionobject.The Problem:
When
disableTransactionsis true, theMigratorfalls back to usingthis.#props.db.connection().execute(...). Ifthis.#props.dbis aTransactioninstance, this leads to:Error: calling the connection method for a Transaction is not supportedThis prevented a useful pattern: performing a "transactional dry-run" of migrations, where migrations are executed within an outer transaction that is subsequently rolled back.
The Solution:
This change modifies the
Migratorto check if the provideddbinstanceisTransaction. If it is, anddisableTransactionsis alsotrue, theMigratorwill now directly use the providedTransactioninstance (this.#props.db) to run the migration logic (run(this.#props.db)), bypassing the problematic.connection()call.Use Case Example (Transactional Migration Validation):
This fix makes it much easier to validate migrations without permanently altering the database, which is super handy for pre-push hooks or CI checks:
Testing:
I've added a test case to cover this specific scenario, ensuring the
Migratorbehaves as expected when used with aTransactionanddisableTransactions: true.