puppetlabs/puppet-dashboard — pull request #126 by vholer (2012-10-02 16:41:44+00:00)
Title: Make SQL status query more PostgreSQL-friendly.

Although Puppet Dashboard doesn't support PostgreSQL, there are already some pieces of code which adds support. In PostgreSQL strings are just single-quoted and the basic dashboard status query fails here:

ActionView::TemplateError (PGError: ERROR: column "unchanged" does not exist
LINE 3: SUM(CASE status when "unchanged" then 1 else 0 end) ...
^
: SELECT
COUNT(*) as total,
SUM(CASE status when "unchanged" then 1 else 0 end) as unchanged,
SUM(CASE status when "changed" then 1 else 0 end) as changed,
SUM(CASE status when "pending" then 1 else 0 end) as pending,
SUM(CASE status when "failed" then 1 else 0 end) as failed,
CASE
WHEN time >= '2012-10-02 22:00:00' THEN '2012-10-03 00:00:00 +0200'
WHEN time >= '2012-10-01 22:00:00' THEN '2012-10-02 00:00:00 +0200'
...

Attached patch replaces double with single quotes in this query. Works with MySQL as well.