Skip to content

fix(typescript): exclude generated columns from Insert and Update types#1069

Open
selenaalpha77-sketch wants to merge 1 commit intosupabase:masterfrom
selenaalpha77-sketch:fix/exclude-generated-columns-from-insert-update
Open

fix(typescript): exclude generated columns from Insert and Update types#1069
selenaalpha77-sketch wants to merge 1 commit intosupabase:masterfrom
selenaalpha77-sketch:fix/exclude-generated-columns-from-insert-update

Conversation

@selenaalpha77-sketch
Copy link
Copy Markdown

Fixes #838

Problem

PostgreSQL GENERATED ALWAYS AS (expr) STORED columns cannot be inserted or updated — the database computes them automatically. However, they were incorrectly included in the TypeScript Insert and Update types, which only excluded GENERATED ALWAYS identity columns.

Solution

Add a check for column.is_generated alongside the existing identity_generation === 'ALWAYS' check in both the Insert and Update type blocks. When column.is_generated is true, the column is rendered as columnName?: never (same as identity columns), preventing it from appearing as a writable field.

Changes

  • src/server/templates/typescript.ts: Add || column.is_generated to the exclusion condition in both Insert and Update type generation blocks
  • test/server/typegen.ts: Add a test case that creates a table with a GENERATED ALWAYS AS (...) STORED column and asserts it appears in Row but is excluded (?: never) from Insert and Update

PostgreSQL `GENERATED ALWAYS AS (expr) STORED` columns cannot be inserted
or updated, but were incorrectly included in the TypeScript `Insert` and
`Update` types. This fix adds a check for `column.is_generated` alongside
the existing `identity_generation === 'ALWAYS'` check to exclude these
columns from write types.

Fixes supabase#838
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove generated columns from Insert/Update types

1 participant