mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Postgresql compatibility for agent model
This commit is contained in:
parent
68437b9e0a
commit
b0d64c4735
2 changed files with 16 additions and 1 deletions
|
@ -10,6 +10,7 @@ class Agent < ActiveRecord::Base
|
|||
include AssignableTypes
|
||||
include MarkdownClassAttributes
|
||||
include JSONSerializedField
|
||||
include RDBMSFunctions
|
||||
|
||||
markdown_class_attributes :description, :event_description
|
||||
|
||||
|
@ -127,7 +128,8 @@ class Agent < ActiveRecord::Base
|
|||
if keep_events_for == 0
|
||||
events.update_all :expires_at => nil
|
||||
else
|
||||
events.update_all "expires_at = DATE_ADD(`created_at`, INTERVAL #{keep_events_for.to_i} DAY)"
|
||||
#events.update_all "expires_at = DATE_ADD(`created_at`, INTERVAL #{keep_events_for.to_i} DAY)"
|
||||
events.update_all "expires_at = " + rdbms_date_add("created_at","DAY",keep_events_for.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
13
lib/rdbms_functions.rb
Normal file
13
lib/rdbms_functions.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module RDBMSFunctions
|
||||
def rdbms_date_add(source, unit, amount)
|
||||
adapter_type = connection.adapter_name.downcase.to_sym
|
||||
case adapter_type
|
||||
when :mysql
|
||||
"DATE_ADD(`#{source}`, INTERVAL #{unit} #{AMOUNT})"
|
||||
when :postgresql
|
||||
"(#{source} + INTERVAL '#{amount} #{unit}')"
|
||||
else
|
||||
raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue