jonatas / timescaledb

The timescaledb gem. Pack of helpers to work with TimescaleDB extension in Ruby.
https://jonatas.github.io/timescaledb/
MIT License
58 stars 17 forks source link

Scenic integration not working #65

Closed Mustapha90 closed 3 months ago

Mustapha90 commented 3 months ago

Hi there!

If I understood correctly how the integration of the timescaledb gem works, I think this migration should work:

class CreateMetrics1mAggs < ActiveRecord::Migration[7.1]
  def change
    create_scenic_continuous_aggregate :metrics_1m_aggs
  end
end

I have this statement in the SQL file generated using Scenic:

SELECT
  metric_type_id,
  time_bucket('1 minute', timestamp) AS bucket,
  AVG(value) AS avg_value,
  MAX(value) AS max_value,
  MIN(value) AS min_value
FROM metrics
GROUP BY metric_type_id, bucket;

For some reason, I get errors:

== 20240515195547 CreateMetrics1mAggs: migrating ==============================
-- create_scenic_continuous_aggregate("metrics_1m_aggs")
bin/rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::SyntaxError: ERROR:  syntax error at or near "{"
LINE 1: CREATE VIEW "metrics_1m_aggs" AS {:materialized=>true, :no_d...

Any idea how to get this working? The documentation about scenic integration doesn't mention any details or specific configuration needed. What am I missing?

jonatas commented 3 months ago

Hey @Mustapha90, you can check the example working here: https://github.com/jonatas/timescaledb/pull/12/files

Mustapha90 commented 3 months ago

@jonatas That's exactly what i was looking for, thank you!

jonatas commented 3 months ago

Awesome! I'm closing the issue now, feel free to reopen if it does not work as you expect.

jonatas commented 3 months ago

I also added a page in the official docs: https://jonatas.github.io/timescaledb/scenic_views/