From 367c1dd31f7f5bd4f2f8d77da223f29d50a28180 Mon Sep 17 00:00:00 2001 From: Marek Knappe Date: Wed, 20 May 2020 14:51:07 +1000 Subject: [PATCH] Fixing issue to be able to have mterics work for recommended docker / postgresql setup --- app/Repositories/Metric/PgSqlRepository.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Repositories/Metric/PgSqlRepository.php b/app/Repositories/Metric/PgSqlRepository.php index e5209ade..c8d135c6 100644 --- a/app/Repositories/Metric/PgSqlRepository.php +++ b/app/Repositories/Metric/PgSqlRepository.php @@ -37,8 +37,8 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac "WHERE {$this->getMetricsTable()}.id = :metricId ". "AND {$this->getMetricPointsTable()}.created_at >= (NOW() - INTERVAL '{$minutes}' MINUTE) ". "AND {$this->getMetricPointsTable()}.created_at <= NOW() ". - "GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:MI') ". - "ORDER BY {$this->getMetricPointsTable()}.created_at", [ + "GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:MI') ". + "ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:MI')", [ 'metricId' => $metric->id, ]); @@ -61,8 +61,8 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac "WHERE {$this->getMetricsTable()}.id = :metricId ". "AND {$this->getMetricPointsTable()}.created_at >= (NOW() - INTERVAL '{$hour}' HOUR) ". "AND {$this->getMetricPointsTable()}.created_at <= NOW() ". - "GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'HH24:00') ". - "ORDER BY {$this->getMetricPointsTable()}.created_at", [ + "GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:00') ". + "ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:00')", [ 'metricId' => $metric->id, ]); @@ -80,13 +80,13 @@ class PgSqlRepository extends AbstractMetricRepository implements MetricInterfac public function getPointsSinceDay(Metric $metric, $day) { $queryType = $this->getQueryType($metric); - $points = DB::select("SELECT DATE({$this->getMetricPointsTable()}.created_at) AS key, {$queryType} ". + $points = DB::select("SELECT to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:00') AS key, {$queryType} ". "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id ". "WHERE {$this->getMetricsTable()}.id = :metricId ". "AND {$this->getMetricPointsTable()}.created_at >= (DATE(NOW()) - INTERVAL '{$day}' DAY) ". "AND {$this->getMetricPointsTable()}.created_at <= DATE(NOW()) ". - "GROUP BY DATE({$this->getMetricPointsTable()}.created_at) ". - "ORDER BY DATE({$this->getMetricPointsTable()}.created_at)", [ + "GROUP BY to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:00')". + "ORDER BY to_char({$this->getMetricPointsTable()}.created_at, 'YYYY-MM-DD HH24:00')", [ 'metricId' => $metric->id, ]);