aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-01-30 12:27:05 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-01-30 12:27:05 +0000
commitc34a4b2e54ad091e0e98d195c0a9bf70da47b91f (patch)
tree34a671b277a2d62195754d965c36f7e7fb80d60f /lib/mauve/alert.rb
parent7b3587a985ff36392c06649cd84c81472f1209c5 (diff)
Added possibility of using postgres databases.
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
#