You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should update the code to create new tables with:
CREATE TABLE goose_db_version (
- id serial NOT NULL,+ id int GENERATED ALWAYS AS IDENTITY,
version_id bigint NOT NULL,
is_applied boolean NOT NULL,
tstamp timestamp NULL DEFAULT now(),
PRIMARY KEY (id)
);
And publish a blog post / update release notes on how users can update existing goose tables.
Note, we're using GENERATED ALWAYS instead of GENERATED BY DEFAULT because these sequence ids should not be manipulated by end-users.
Although I could see an argument for making this GENERATED BY DEFAULT as an escape hatch. But I can't think of a scenario where the id needs to be manually changed, so GENERATED ALWAYS seems like the most sane solution.
EDIT: after a bit of thought, settled on GENERATED BY DEFAULT, as this avoids locking users.
The text was updated successfully, but these errors were encountered:
mfridman
changed the title
Update new postgres table to use identity instead of serial
Update postgres table to use identity instead of serial
Jul 6, 2023
In Postgres versions 10 and above, the recommendation is to use identity instead of serial,
https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_serial
We should update the code to create new tables with:
And publish a blog post / update release notes on how users can update existing goose tables.
Note, we're using
GENERATED ALWAYS
instead ofGENERATED BY DEFAULT
because these sequence ids should not be manipulated by end-users.Although I could see an argument for making this
GENERATED BY DEFAULT
as an escape hatch. But I can't think of a scenario where the id needs to be manually changed, soGENERATED ALWAYS
seems like the most sane solution.EDIT: after a bit of thought, settled on
GENERATED BY DEFAULT
, as this avoids locking users.The text was updated successfully, but these errors were encountered: