Description
Version
1.16.0
What happened?
Adding PRIMARY KEY
as part of ALTER TABLE
statement does not change generated go type of the respective field to not-nullable if it was nullable before, only when PRIMARY KEY
is part of CREATE TABLE
statement.
Here's the modified default example from the playground: https://play.sqlc.dev/p/a0411602ad2e4cf460b379ca8572a0052b2239accc93675ab0869dfa15473933
In db/models.go
, notice that the generated struct Author
still has its ID
as sql.NullInt64
, even though there's an SQL statement that sets this column to primary key.
Once you move PRIMARY KEY
in the CREATE TABLE
statement, the field becomes sql.Int64
: https://play.sqlc.dev/p/5a10cf0586b17e2b1a26bbbf44a8375751466d9411db0f9692789c0e7855c9de
When I first observed this issue I used sqlc version 1.16 with https://github.com/pressly/goose for migrations, the type of my column was UUID
, but I don't think this is relevant since this is reproducible in the playground with completely different setup and column type.
Relevant log output
No response
Database schema
No response
SQL queries
No response
Configuration
No response
Playground URL
https://play.sqlc.dev/p/a0411602ad2e4cf460b379ca8572a0052b2239accc93675ab0869dfa15473933
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go