mammoth icon indicating copy to clipboard operation
mammoth copied to clipboard

How to declare `IDENTITY` columns?

Open cakoose opened this issue 3 years ago • 2 comments

Postgres recommends using IDENTITY (introduced in v10) instead of SERIAL: https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_serial

How should I declare such a column in my Mammoth table schema? This is what I'm doing now:

id: int8().default('')

cakoose avatar Nov 10 '21 01:11 cakoose

Identity [1] is not supported yet. As a workaround to get the typing right you can set a default or use .notNull().

Unfortunately there is not a workaround for the migration generation. This needs to support identity. I'm planning to find some time again the coming weeks to work on Mammoth. I'll add this to my list.

[1] https://www.postgresql.org/docs/13/sql-createtable.html

martijndeh avatar Nov 15 '21 15:11 martijndeh

.notNull() on its own didn't work because then the field is still required when calling .insertInto. But .default('') works fine for us, since we're not using Mammoth schema generation/migration.

cakoose avatar Nov 15 '21 20:11 cakoose