Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary keys not working with GENERATED ALWAYS AS IDENTITY columns #374

Open
lauri865 opened this issue Feb 13, 2024 · 0 comments
Open

Primary keys not working with GENERATED ALWAYS AS IDENTITY columns #374

lauri865 opened this issue Feb 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@lauri865
Copy link
Contributor

lauri865 commented Feb 13, 2024

Describe the bug
I'm using GENERATED ALWAYS AS IDENTITY primary key definitions, which is great, because it makes sure that no-one can accidentally update id columns. It's still possible manually, but needs to be an intentional behavior with OVERRIDING SYSTEM VALUE clause.

However, it doesn't seem to work with supabase-cache-helpers, since it requires primary keys to be part of the update payload to build filters, but doesn't remove them from it.

The resulting payload is:

curl 'https://local.test/rest/v1/companies?id=eq.212&select=name%2Cdescription%2Cid' \
  -X 'PATCH' \
  --data-raw '{"name":"Name","description":"description","id":212}' \

Which reults in the following error:

{
  "code": "428C9",
  "details": "Column \"id\" is an identity column defined as GENERATED ALWAYS.",
  "hint": null,
  "message": "column \"id\" can only be updated to DEFAULT"
}

I think it's a bad practice in general to include primary keys in the update payload by default. Foreign keys, sure, but there's little reasons to make primary keys mutable, and it's just a potential source of unintentional errors / breaking data integrity.

Related code:

let filterBuilder = qb.update(input as any, opts); // todo fix type;

Suggested solution
Remove primary_key values from the update payload by default, and enable it with e.g. opts.stripPrimaryKeysFromData = false or equivalent. It could be a breaking change though for some (even if unintentionally), so for a minor version, stripping primary keys could also be opt-in.

@lauri865 lauri865 added the bug Something isn't working label Feb 13, 2024
@lauri865 lauri865 changed the title Bug: primary keys not working with GENERATED ALWAYS AS IDENTITY columns Primary keys not working with GENERATED ALWAYS AS IDENTITY columns Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant