Skip to content

fix(WithSchemaTransformer): using table of merge into queries unhandled.#1554

Merged
igalklebanov merged 3 commits intokysely-org:masterfrom
alexander-azizi-martin:alexander-azizi-martin-with-schema-merge-into
Aug 24, 2025
Merged

fix(WithSchemaTransformer): using table of merge into queries unhandled.#1554
igalklebanov merged 3 commits intokysely-org:masterfrom
alexander-azizi-martin:alexander-azizi-martin-with-schema-merge-into

Conversation

@alexander-azizi-martin
Copy link
Copy Markdown
Contributor

The withSchema method is documented to set the default schema for all table references that don't explicitly specify a schema (docs). However, it currently fails to apply the schema to join tables in mergeInto statements.

When using withSchema with mergeInto, the schema is not applied to the table specified in the .using() clause:

await db
 .withSchema(tenant)
 .mergeInto('person as target')
 .using('pet as source', 'source.owner_id', 'target.id')
 .whenMatchedAnd('target.has_pets', '!=', 'Y')
 .thenUpdateSet({ has_pets: 'Y' })
 .whenNotMatchedBySourceAnd('target.has_pets', '=', 'Y')
 .thenUpdateSet({ has_pets: 'N' })
 .executeTakeFirstOrThrow()

In this example, the person table correctly receives the schema prefix, but the pet table in the .using() clause does not.

This PR updates the WithSchemaTransformer class to properly handle join tables in mergeInto statements.

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
kysely Ready Ready Preview Comment Aug 24, 2025 4:43pm

@alexander-azizi-martin alexander-azizi-martin changed the title Fix bug in WithSchemaTransformer plugin fix: bug in WithSchemaTransformer plugin Aug 20, 2025
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Aug 20, 2025

kysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@1554

commit: ea0697e

@igalklebanov igalklebanov force-pushed the alexander-azizi-martin-with-schema-merge-into branch from 589f5ae to 7b75a5f Compare August 24, 2025 15:24
@igalklebanov igalklebanov added bug Something isn't working built-in plugin Related to a built-in plugin postgres Related to PostgreSQL mssql Related to MS SQL Server (MSSQL) labels Aug 24, 2025
Copy link
Copy Markdown
Member

@igalklebanov igalklebanov left a comment

Choose a reason for hiding this comment

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

Hey 👋

Thanks! 🙏

The test case was not reproducing the bug - made sure it does.

@igalklebanov igalklebanov merged commit 8d141ba into kysely-org:master Aug 24, 2025
31 checks passed
@igalklebanov igalklebanov changed the title fix: bug in WithSchemaTransformer plugin fix(WithSchemaTransformer): using table of merge into queries unhandled. Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working built-in plugin Related to a built-in plugin mssql Related to MS SQL Server (MSSQL) postgres Related to PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants