Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Query/Schema/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,21 @@ public function alterColumnType(string $table, string $column, string $type, str
return new Statement($sql, [], executor: $this->executor);
}

/**
* Alter a column's nullability.
*
* Postgres carries NOT NULL through an ALTER COLUMN ... TYPE, so a column
* that changes between required and optional has to be altered separately.
*/
public function alterColumnNullable(string $table, string $column, bool $nullable): Statement
{
$sql = 'ALTER TABLE ' . $this->quote($table)
. ' ALTER COLUMN ' . $this->quoteLiteral($column)
. ($nullable ? ' DROP NOT NULL' : ' SET NOT NULL');

return new Statement($sql, [], executor: $this->executor);
}

/**
* Reject expressions that could chain additional statements or comments.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Query/Schema/PostgreSQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,24 @@ public function testAlterColumnTypeWithUsing(): void
$this->assertSame([], $result->bindings);
}

public function testAlterColumnNullableDrops(): void
{
$schema = new Schema();
$result = $schema->alterColumnNullable('users', 'location', true);

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

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

}

public function testAlterColumnNullableSets(): void
{
$schema = new Schema();
$result = $schema->alterColumnNullable('users', 'location', false);

$this->assertSame('ALTER TABLE "users" ALTER COLUMN "location" SET NOT NULL', $result->query);
$this->assertSame([], $result->bindings);
}

public function testAlterColumnTypeRejectsInjectionInType(): void
{
$this->expectException(ValidationException::class);
Expand Down
Loading