Skip to content

feat: add IF EXISTS support for alter table#1720

Open
aryanghugare wants to merge 1 commit intokysely-org:masterfrom
aryanghugare:fix/ALTER_TABLE_IF_EXISTS_ISSUE
Open

feat: add IF EXISTS support for alter table#1720
aryanghugare wants to merge 1 commit intokysely-org:masterfrom
aryanghugare:fix/ALTER_TABLE_IF_EXISTS_ISSUE

Conversation

@aryanghugare
Copy link
Copy Markdown

Implementation: ALTER TABLE IF EXISTS support

Added ifExists() method to AlterTableBuilder, following the same pattern as DropTableBuilder.ifExists() and CreateTableBuilder.ifNotExists().

Usage:

db.schema.alterTable('person').ifExists().addColumn('age', 'integer')
// PostgreSQL: alter table if exists "person" add column "age" integer

Files changed:

  1. src/operation-node/alter-table-node.ts — Added ifExists?: boolean to AlterTableNode interface and AlterTableNodeTableProps
  2. src/schema/alter-table-builder.ts — Added ifExists() chainable method on AlterTableBuilder
  3. src/query-compiler/default-query-compiler.ts — Emit "if exists" in visitAlterTable() when flag is set
  4. src/operation-node/operation-node-transformer.ts — Pass through ifExists in transformAlterTable()
  5. test/node/src/schema.test.ts — Added test covering Postgres, MySQL, and SQLite output

Happy to open a PR if this approach looks good!
Tell me about the changes

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 25, 2026

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

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 25, 2026

commit: edbf5f2

@aryanghugare aryanghugare marked this pull request as ready for review February 25, 2026 21:27
@jamesvillarrubia

This comment has been minimized.

@aryanghugare
Copy link
Copy Markdown
Author

Bumping this. This is pretty critical for idempotent alterations.

Thanks for the bump! Happy to make any further changes if needed.

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.

2 participants