mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-16 03:41:41 +00:00
Merge pull request #184 from ms32035/master
Postgresql compatibility for agent model
This commit is contained in:
commit
0e7c5c5b95
3 changed files with 18 additions and 3 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,7 @@ 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 = " + rdbms_date_add("created_at", "DAY", keep_events_for.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -265,8 +266,8 @@ class Agent < ActiveRecord::Base
|
|||
|
||||
agents_to_events = {}
|
||||
Agent.connection.select_rows(sql).each do |receiver_agent_id, source_agent_id, event_id|
|
||||
agents_to_events[receiver_agent_id] ||= []
|
||||
agents_to_events[receiver_agent_id] << event_id
|
||||
agents_to_events[receiver_agent_id.to_i] ||= []
|
||||
agents_to_events[receiver_agent_id.to_i] << event_id
|
||||
end
|
||||
|
||||
event_ids = agents_to_events.values.flatten.uniq.compact
|
||||
|
|
|
@ -21,6 +21,7 @@ test:
|
|||
socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %>
|
||||
encoding: <%= ENV['DATABASE_ENCODING'] || "utf8" %>
|
||||
reconnect: <%= ENV['DATABASE_RECONNECT'] || "true" %>
|
||||
port: <%= ENV['DATABASE_PORT'] || "" %>
|
||||
pool: <%= ENV['DATABASE_POOL'] || "5" %>
|
||||
|
||||
production:
|
||||
|
|
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, :mysql2
|
||||
"DATE_ADD(`#{source}`, INTERVAL #{amount} #{unit})"
|
||||
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