-
Notifications
You must be signed in to change notification settings - Fork 132
Description
To achieve full compatibility between the sqlc
code generator library and the two supported SQL database backends SQLite and Postgres, we require all numeric database primary keys to be of type INTEGER PRIMARY KEY
, if they should auto-increment.
The reason is that our SQL definitions target SQLite compatibility first and are then transformed with replace directives to also work for Postgres. There's also a build-time transformation that makes sure sqlc
generates the correct data types for those columns (the comment above that line also explains this requirement in a bit more detail).
If a new table does not use the correct numeric primary key type then the auto-increment feature might not work on SQLite and weird errors will happen.
In addition, any foreign key referencing these primary keys must be defined as BIGINT REFERENCES
for the correct data type to be generated by sqlc
.
So we should create a CI or build time check that makes sure that any numeric database primary key is of exactly the type INTEGER PRIMARY KEY
.
Something like #1616 is a potential approach, but other checks are possible too.
Once an approach has been decided on, it would be beneficial to use the same check in all projects that offer SQLite and Postgres support (namely lnd
and litd
).