feat(postgres): alter a column's nullability - #22
Conversation
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>
|
| $this->assertSame('ALTER TABLE "users" ALTER COLUMN "location" DROP NOT NULL', $result->query); | ||
| $this->assertSame([], $result->bindings); |
There was a problem hiding this comment.
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!
📊 Coverage
Full per-file breakdown in the job summary. |
What
Adds
PostgreSQL::alterColumnNullable(), emittingALTER COLUMN … SET NOT NULL/DROP NOT NULL.Why
Postgres carries
NOT NULLthrough anALTER COLUMN … TYPE, so a column that moves between required and optional keeps its old constraint. MySQL resets nullability as part ofMODIFY 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: falsereported success and flipped the stored metadata, but the Postgres column keptNOT 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
alterColumnTypecoverage.🤖 Generated with Claude Code