Skip to content

feat(postgres): alter a column's nullability - #22

Merged
abnegate merged 2 commits into
mainfrom
qlt-nullable
Sep 21, 2026
Merged

abnegate merged 2 commits into
mainfrom
qlt-nullable

Conversation

@abnegate

Copy link
Copy Markdown
Member

What

Adds PostgreSQL::alterColumnNullable(), emitting ALTER COLUMN … SET NOT NULL / DROP NOT NULL.

Why

Postgres carries NOT NULL through an ALTER COLUMN … TYPE, so a column that moves between required and optional keeps its old constraint. MySQL resets nullability as part of MODIFY COLUMN, so only Postgres needs the constraint altered on its own — there is currently no way to express that through the builder.

This surfaced in the query-lib train: updating a spatial attribute to required: false reported success and flipped the stored metadata, but the Postgres column kept NOT NULL, so the next insert of a null value failed with a not-null violation. Only the Postgres lanes were affected.

Tests

Two cases covering the generated SQL in both directions, alongside the existing alterColumnType coverage.

🤖 Generated with Claude Code

Postgres carries NOT NULL through an ALTER COLUMN ... TYPE, so a column
that moves between required and optional keeps its old constraint. MySQL
resets it as part of MODIFY COLUMN, which is why only Postgres needs the
constraint altered on its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The implementation appears safe to merge, though the unresolved non-blocking test-quality finding should still be addressed.

Fix All in Claude CodeFindings

  1. P2 Tests Mirror SQL Construction
Fix with agent prompt
### Issue 1
tests/Query/Schema/PostgreSQLTest.php:728-729
These tests assert only the exact generated SQL and empty bindings, so they can pass without proving that PostgreSQL changes the column constraint. This violates the repository directive to test observable behavior instead of mirroring source output. The tests should execute the statements against PostgreSQL and verify the resulting nullability or insert behavior before this merges.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds PostgreSQL support for independently changing a column’s nullability.

  • Adds PostgreSQL::alterColumnNullable() to emit DROP NOT NULL or SET NOT NULL.
  • Adds SQL-generation tests for both nullable and non-nullable directions.
  • No code changed since the previous review.

Reviews (2) · Last reviewed commit: "chore: retrigger CI"

Comment on lines +728 to +729
$this->assertSame('ALTER TABLE "users" ALTER COLUMN "location" DROP NOT NULL', $result->query);
$this->assertSame([], $result->bindings);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Tests Mirror SQL Construction

These tests assert only the exact generated SQL and empty bindings, so they can pass without proving that PostgreSQL changes the column constraint. This violates the repository directive to test observable behavior instead of mirroring source output. The tests should execute the statements against PostgreSQL and verify the resulting nullability or insert behavior before this merges.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/Query/Schema/PostgreSQLTest.php
Line: 728-729

Comment:
**Tests Mirror SQL Construction**

These tests assert only the exact generated SQL and empty bindings, so they can pass without proving that PostgreSQL changes the column constraint. This violates the repository directive to test observable behavior instead of mirroring source output. The tests should execute the statements against PostgreSQL and verify the resulting nullability or insert behavior before this merges.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@github-actions

Copy link
Copy Markdown

📊 Coverage

Metric Covered Ratio
Lines 91.88% 7563 / 8231
Methods 83.90% 1115 / 1329
Classes 65.16% 144 / 221

Full per-file breakdown in the job summary.

@abnegate
abnegate merged commit 67f89d9 into main Sep 21, 2026
7 checks passed
@abnegate
abnegate deleted the qlt-nullable branch September 21, 2026 05:06
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