GithubHelp home page GithubHelp logo

Comments (5)

hovsater avatar hovsater commented on May 19, 2024 1

@jenseng I'll take a look at this and see if I can submit a PR by the end of the week. 🙂

from hair_trigger.

jenseng avatar jenseng commented on May 19, 2024

Thanks for the bug report @KevinSjoberg 👍

Yeah, the assumption right now in the code is that all parts of the chain apply to the generated trigger(s), so it tries to apply the of to the insert trigger, which is not valid. Seems like to support this we'd need to change this check to something like:

... if options[:of] && !(options[:events] || []).include?("UPDATE")

and also rework this generate_trigger_postgresql logic, since it just blindly puts the OF clause after the events. I'd happily accept a pull request w/ a couple specs around it.

In the meantime, you could do something like this as a workaround:

trigger_sql = <<-SQL
  -- If row is current, do nothing.
  IF (TG_OP = 'UPDATE' AND OLD.current = true) THEN
    RETURN NEW;
  END IF;

  -- Ensure user roles are not marked as current
  UPDATE roles SET current = null WHERE current = true AND user_id = NEW.user_id;

  RETURN NEW;
SQL
trigger.before(:insert).where('NEW.current') { trigger_sql }
trigger.before(:update).of(:current).where('NEW.current') { trigger_sql }

from hair_trigger.

hovsater avatar hovsater commented on May 19, 2024

@jenseng is this still an issue? I'm doing a bit of issue cleanup on my part.

from hair_trigger.

jenseng avatar jenseng commented on May 19, 2024

Hi @KevinSjoberg, I believe so, I haven't done anything with it yet. So I'll leave this issue open in case anyone else wants to take a stab at it.

I like to think I'll get to it eventually, but the reality is I write very little ruby these days and haven't used this gem in a project in years 😢

from hair_trigger.

hovsater avatar hovsater commented on May 19, 2024

@jenseng same here. I'll close it and let it resurface if needed.

from hair_trigger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.