Skip to content

translators/postgres: respect null: false in change_column#144

Open
c-tonneslan wants to merge 1 commit into
gobuffalo:mainfrom
c-tonneslan:fix-change-column-null-false
Open

translators/postgres: respect null: false in change_column#144
c-tonneslan wants to merge 1 commit into
gobuffalo:mainfrom
c-tonneslan:fix-change-column-null-false

Conversation

@c-tonneslan
Copy link
Copy Markdown

change_column("posts", "destination_id", "integer", {null: false}) emits

ALTER TABLE "posts" ALTER COLUMN "destination_id" TYPE integer, ALTER COLUMN "destination_id" DROP NOT NULL;

instead of SET NOT NULL. The postgres builder only checked whether the null key was present and ignored its value, so {null: false} (which a user reasonably writes when they want a NOT NULL column) was treated the same as {null: true}.

Fix is to treat null: false the same as omitting the option. Added tests for both null: true and null: false.

Closes #62

change_column with {null: false} emitted DROP NOT NULL instead of
SET NOT NULL because the postgres builder only checked whether the
"null" key was present, not its value. Match the behavior the
caller asked for: nil or false means NOT NULL, anything else means
nullable.

Fixes gobuffalo#62

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@c-tonneslan c-tonneslan requested review from a team as code owners May 18, 2026 18:22
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.

change_column with {null: false} executes SQL "DROP NOT NULL"

1 participant