Skip to content

feat(backend): render ALTER TABLE IF [NOT] EXISTS qualifiers for PostgreSQL - #50

Closed
vistart wants to merge 1 commit into
release/v1.0.0.dev16from
feat/alter-table-if-exists-modifier
Closed

vistart wants to merge 1 commit into
release/v1.0.0.dev16from
feat/alter-table-if-exists-modifier

Conversation

@vistart

@vistart vistart commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

PostgreSQL has supported the vendor IF [NOT] EXISTS qualifiers on ALTER TABLE since 9.6. This PR adds PostgresAlterColumnModifierMixin so the backend emits:

  • ADD COLUMN IF NOT EXISTS
  • DROP COLUMN IF EXISTS
  • DROP CONSTRAINT IF EXISTS

They are opt-in via if_not_exists / if_exists on AddColumn / DropColumn / DropTableConstraint; None (default) renders the plain SQL-standard form.

Also adds the supports_drop_constraint_if_exists capability to PostgresConstraintSupport / PostgresConstraintMixin.

Requires the core python-activerecord PR #114 (new qualifier fields on the ALTER TABLE actions).

…greSQL

Add PostgresAlterColumnModifierMixin so PostgreSQL emits the vendor
qualifiers supported since 9.6: ADD COLUMN IF NOT EXISTS, DROP COLUMN
IF EXISTS, and DROP CONSTRAINT IF EXISTS, opt-in via if_not_exists /
if_exists on AddColumn / DropColumn / DropTableConstraint. Wire the mixin
into PostgresDialect ahead of TableMixin/ConstraintMixin and add the
supports_drop_constraint_if_exists capability to PostgresConstraintSupport
and PostgresConstraintMixin. Add unit tests covering qualifier and plain
forms.
@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

@vistart vistart closed this Aug 6, 2026
@vistart
vistart deleted the feat/alter-table-if-exists-modifier branch August 6, 2026 19:18
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.

1 participant