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

Upsert creating custom functions even when a postgres unique constraint is in place #128

Open
searls opened this issue Nov 9, 2019 · 2 comments

Comments

@searls
Copy link
Contributor

searls commented Nov 9, 2019

I did my best to follow the README on this one, but I'm still missing something. Running on master

From my structure.sql:

CREATE TABLE public.items (
    id bigint NOT NULL,
    jmdict_id bigint
    -- etc…
);

ALTER TABLE ONLY public.items
    ADD CONSTRAINT items_constraint_on_jmdict_id UNIQUE (jmdict_id);

When I call Upsert.batch:

      Upsert.batch(Item.connection.raw_connection, :items) do |upsert|
          upsert.row({
            jmdict_id: some_id,
          }, {
            # etc…
          })
      end

And then I run rake db:structure:dump, I'll get:

CREATE FUNCTION public.upsert3_0_0_items_sel_jmdict_id_set_created_at_a_jmdi2123077596
-- etc…
@searls
Copy link
Contributor Author

searls commented Nov 10, 2019

I was curious about this and it definitely looks like the gem will call this method to create the custom functions even if use_pg_native? will return true. Just emptied both methods that were creating PG functions and the gem still worked fine from the look of it.

This is important to me because my scripts don't have permission to create functions in prod so these just keep failing/rescuing out countless times and fill my log quota

@pnomolos
Copy link
Collaborator

@searls I'm out of town for the next week but once I'm back I'll take a look at making sure it doesn't create the function if it's not necessary.

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

No branches or pull requests

2 participants