Comments (5)
@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.
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.
@jenseng is this still an issue? I'm doing a bit of issue cleanup on my part.
from hair_trigger.
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.
@jenseng same here. I'll close it and let it resurface if needed.
from hair_trigger.
Related Issues (20)
- Model methods without Raw SQLs
- ArgumentError: comparison of NilClass with 20221210175746 failed HOT 1
- Lock the table triggers are created for
- NoMethodError: undefined method `schema_format' for ActiveRecord::Base:Class (NoMethodError) HOT 3
- RFC: use rails generator instead of a custom rake task for migrations
- How to execute sequence with prefix HOT 2
- Triggers at the beginning of schema, before tables created HOT 1
- Undefined method `migrations` in Rails v5.2 HOT 2
- hair_trigger creates adapter specific code for MySQL HOT 1
- can't modify frozen String with frozen_string_literal: true HOT 1
- support for postgres trigger guard (when) HOT 1
- Cannot define multiple 'included' blocks for a Concern
- Rails 6.0 - "Nothing to do" when running rake db:generate_trigger_migration HOT 5
- Rails 6.0 Migrations - "ArgumentError: wrong number of arguments (given 2, expected 1)" HOT 1
- Allow multiple triggers on same event HOT 3
- Use Ruby 1.9 hash syntax in auto-generated migrations
- Fix Ruby 2.7 warnings HOT 2
- schema.rb created when schema_format set to :sql HOT 1
- Hairtrigger broken with fx gem >= 0.6.0 HOT 1
- Rails app with multiple databases: Primary schema file getting overwritten by secondary schema file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hair_trigger.