sea-query icon indicating copy to clipboard operation
sea-query copied to clipboard

Stop using deprecated serial column type

Open kikijiki opened this issue 2 years ago • 1 comments

Motivation

The generated PostgreSQL tables use serial/bigserial which appears to be obsolete for a long time.

  • https://stackoverflow.com/questions/55300370/postgresql-serial-vs-identity
  • https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_serial

Proposed Solutions

Use integer/bigint with the identity modifier as suggested?

Additional Information

Code ref: https://github.com/SeaQL/sea-query/blob/8ce9930b075aaa204a1b2adf08b234240e66fb57/src/backend/postgres/table.rs#L225

kikijiki avatar Aug 29 '23 23:08 kikijiki

Just for reference for anyone who is not sure about how to achieve

create table posts (
  id bigint primary key generated always as identity
)

the following can be used

Table::create()
  .table(Post::Table)
  .col(
      big_integer(Post::Id)
          .primary_key()
          .extra("GENERATED ALWAYS AS IDENTITY")

nyrdz avatar Jan 03 '25 09:01 nyrdz