Skip to content

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

Merged
vistart merged 5 commits into
release/v1.0.0.dev16from
feature/alter-table-if-exists-modifier
Aug 7, 2026
Merged

vistart merged 5 commits into
release/v1.0.0.dev16from
feature/alter-table-if-exists-modifier

Conversation

@vistart

@vistart vistart commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

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 python-activerecord#115.

Closes #51

Type of change

  • feat: A new feature

Breaking Change

  • No breaking changes

Impact on End-Users:
No backward-incompatible changes are expected for typical end-user applications.

Impact on Backend Developers (Custom Implementations):
No breaking changes.

Related Repositories/Packages

  • python-activerecord: PR #115 — new qualifier fields on ALTER TABLE actions

Testing

  • I have added new tests to cover my changes.
  • All existing tests pass.
  • This change has been tested on PostgreSQL.

Checklist

  • My code follows the project's code style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation (Docstrings).
  • My changes generate no new warnings.
  • I have added a Changelog fragment (changelog.d/51.added.md).
  • I have verified that my changes do not introduce SQL injection vulnerabilities.
  • I have checked for potential performance regressions.

vistart and others added 4 commits August 6, 2026 19:55
…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.
@vistart vistart self-assigned this Aug 7, 2026
@vistart vistart added the feature label Aug 7, 2026
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.24%. Comparing base (5c9fae4) to head (02cb924).

Files with missing lines Patch % Lines
...ord/backend/impl/postgres/mixins/ddl/constraint.py 50.00% 1 Missing ⚠️
.../backend/impl/postgres/protocols/ddl/constraint.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           release/v1.0.0.dev16      #51      +/-   ##
========================================================
+ Coverage                 73.18%   73.24%   +0.05%     
========================================================
  Files                       277      278       +1     
  Lines                     11333    11364      +31     
  Branches                   1837     1841       +4     
========================================================
+ Hits                       8294     8323      +29     
- Misses                     2439     2441       +2     
  Partials                    600      600              
Flag Coverage Δ
postgres-18 73.24% <93.54%> (+0.05%) ⬆️
python-3.14 73.24% <93.54%> (+0.05%) ⬆️
unittests 73.24% <93.54%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vistart
vistart merged commit 5b83d05 into release/v1.0.0.dev16 Aug 7, 2026
17 checks passed
@vistart vistart mentioned this pull request Aug 15, 2026
8 of 12 tasks
vistart added a commit that referenced this pull request Aug 15, 2026
…greSQL (#51)

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

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.

* chore(changelog): rename fragment 50 to new PR #51

* ci: update Python 3.15 beta-2 to rc.1 in test matrix

* test: add feature/basic/ddl mirror with provider get_dialect for postgres

* test: rename basic/ddl mirror basename to avoid pytest import collision with backend dialect test
@vistart
vistart deleted the feature/alter-table-if-exists-modifier branch October 1, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant