aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-01-30 12:30:44 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-01-30 12:30:44 +0000
commita75a1088aaa150a5521e1acfa3a372520f3c3995 (patch)
tree11ec8c3cbb227305630924f62d2a49bb99399388 /lib/mauve/alert.rb
parent82d493d723c8a3c50b6fdbe3931a49b6b48443b4 (diff)
parent8ed82944ebd764f1986b3155990b895045b584bc (diff)
Merge
Diffstat (limited to 'lib/mauve/alert.rb')
-rw-r--r--lib/mauve/alert.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 37a8f2e..3c9fbdc 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -14,7 +14,6 @@ module Mauve
include DataMapper::Resource
- property :id, Serial
property :alert_id, Integer
property :earliest, EpochTime
belongs_to :alert, :model => "Alert"
@@ -29,6 +28,16 @@ module Mauve
#
def self.create_view!
the_distant_future = (Time.now + 2000.days).to_i # it is the year 2000 - the humans are dead
+
+ case DataMapper.repository(:default).adapter.class.to_s
+ when "DataMapper::Adapters::PostgresAdapter"
+ ifnull = "COALESCE"
+ min = "LEAST"
+ else
+ ifnull = "IFNULL"
+ min = "MIN"
+ end
+
["BEGIN TRANSACTION",
"DROP VIEW IF EXISTS mauve_alert_earliest_dates",
"CREATE VIEW
@@ -37,12 +46,12 @@ module Mauve
SELECT
id AS alert_id,
NULLIF(
- MIN(
- IFNULL(will_clear_at, '#{the_distant_future}'),
- IFNULL(will_raise_at, '#{the_distant_future}'),
- IFNULL(will_unacknowledge_at, '#{the_distant_future}')
+ #{min}(
+ #{ifnull}(will_clear_at, #{the_distant_future}),
+ #{ifnull}(will_raise_at, #{the_distant_future}),
+ #{ifnull}(will_unacknowledge_at, #{the_distant_future})
),
- '#{the_distant_future}'
+ #{the_distant_future}
) AS earliest
FROM mauve_alerts
WHERE
@@ -54,7 +63,6 @@ module Mauve
repository(:default).adapter.execute(statement.gsub(/\s+/, " "))
end
end
-
end
#