Skip to content

feat: Per-migration transaction configuration#1671

Open
lourd wants to merge 27 commits into
kysely-org:nextfrom
lourd:per-migration-transaction
Open

feat: Per-migration transaction configuration#1671
lourd wants to merge 27 commits into
kysely-org:nextfrom
lourd:per-migration-transaction

Conversation

@lourd

@lourd lourd commented Jan 3, 2026

Copy link
Copy Markdown

Closes #352

Creates the ability for individual migrations to opt out of being executed in a transaction, depending on the adapter's support for transactions, the Migrator configuration, and the options given to the migrate method.

Follows pretty closely to the Knex implementation as suggested by @tgriesser.

If transactions are enabled globally and an individual migration opts out, then all of the migrations before it are run in a transaction, then it is run outside of a transaction, then all the migrations after it are run in a transaction.

The behavior is the same when migrating up and down.

I decided that if a transaction is passed to the Migrator (#1480), it results in an error. And if any of the options disabling transactions are used, either globally or per migrate call (#1517), those take precedence.

Basically this feature only takes effect when transactions aren't disabled and the Migrator has responsibility over transactions.

@vercel

vercel Bot commented Jan 3, 2026

Copy link
Copy Markdown

@lourd is attempting to deploy a commit to the Kysely Team Team on Vercel.

A member of the Team first needs to authorize it.

@lourd lourd changed the title Per-migration transaction configuration feat: Per-migration transaction configuration Jan 3, 2026
@lourd lourd force-pushed the per-migration-transaction branch from a65e02e to 58d73b0 Compare January 3, 2026 23:16
@lourd lourd changed the base branch from master to next January 3, 2026 23:17
@lourd

lourd commented Jan 11, 2026

Copy link
Copy Markdown
Author

Hey @igalklebanov, eager to hear your feedback!

@Philipinho

Copy link
Copy Markdown

Great work @lourd.

@igalklebanov igalklebanov force-pushed the next branch 4 times, most recently from a225c9f to ebcfe24 Compare January 17, 2026 20:28
y-hsgw and others added 19 commits January 18, 2026 09:25
Co-authored-by: Eric So <56284867+ericsodev@users.noreply.github.com>
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
Co-authored-by: igalklebanov <igalklebanov@gmail.com>
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
…fier (kysely-org#1615)

Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
Co-authored-by: igalklebanov <igalklebanov@gmail.com>
@lourd lourd force-pushed the per-migration-transaction branch from 7ba0d09 to 1a9ef42 Compare January 20, 2026 16:06
@lourd

lourd commented Jan 20, 2026

Copy link
Copy Markdown
Author

Hey @igalklebanov, just rebased on next, should be good to go here. Let me know if there's anything I can do to help making reviewing or merging easier

@pkg-pr-new

pkg-pr-new Bot commented Jan 25, 2026

Copy link
Copy Markdown

commit: 1a9ef42

Comment thread src/migration/migrator.ts
* Note: Setting this to `true` has no effect if the dialect doesn't support
* transactional DDL.
*/
readonly transaction?: boolean

@igalklebanov igalklebanov Jan 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If there wasn't such a strong case to keep knex naming and behavior - familiarity and lots of training data, I'd call this something more explicit and perhaps go beyond boolean.

e.g. transactionMode?: 'never' | 'shared' | 'file-scoped', where "never" means no matter what, never runs this file's changes in a transaction, "shared" means reuse or create "global" transaction (the default mode), "file-scoped" which means always commit previous transaction group if available and start a transaction just for this file.

Not for now. Something to consider after this effort.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think that's a great idea, covers more use cases than a boolean can. Happy to make those changes, let me know!

@igalklebanov igalklebanov Feb 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not for this iteration. Let's keep it knexy and minimal as possible.

@igalklebanov igalklebanov force-pushed the next branch 3 times, most recently from f0934fe to a859b43 Compare February 1, 2026 16:34
@igalklebanov igalklebanov added enhancement New feature or request migrations Related to migrations labels Feb 1, 2026
@igalklebanov igalklebanov force-pushed the next branch 3 times, most recently from 63af1a3 to 0cf6dcb Compare April 4, 2026 20:47
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from ca8e49a to 9f037a2 Compare April 12, 2026 08:52
@igalklebanov igalklebanov force-pushed the next branch 6 times, most recently from 53663bf to e74f592 Compare May 23, 2026 15:02
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from ab33123 to d628e64 Compare May 29, 2026 05:25
@shoooe

shoooe commented Jun 6, 2026

Copy link
Copy Markdown

@lourd @igalklebanov Anything I can do to help?

@lourd

lourd commented Jun 6, 2026

Copy link
Copy Markdown
Author

@shoooe, thanks for the offer. Last I talked with @igalklebanov this is slated for 0.30, he wanted to get 0.29 out first. I need to rebase on latest and resolve the merge conflicts.

@shoooe

shoooe commented Jun 8, 2026

Copy link
Copy Markdown

Alright, thanks very much for working on this @lourd @igalklebanov. 🙏

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: non-transactional migrations for concurrent index creation