From 46a74c0513e4c9471c569d055555900976dee5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B4natas=20Davi=20Paganini?= Date: Thu, 2 May 2024 10:42:42 -0300 Subject: [PATCH] Improve example --- docs/migrations.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/migrations.md b/docs/migrations.md index ac9c818..72d0c71 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -25,6 +25,18 @@ end This example shows a ticks table grouping ticks as OHLCV histograms for every minute. +First make sure you have the model with the `acts_as_hypertable` method to be +able to extract the query from it. + +```ruby +class Tick < ActiveRecord::Base + self.table_name = 'ticks' + acts_as_hypertable +end +``` + +Then, inside your migration: + ```ruby hypertable_options = { time_column: 'created_at', @@ -39,11 +51,6 @@ create_table :ticks, hypertable: hypertable_options, id: false do |t| t.integer :volume t.timestamps end -Tick = Class.new(ActiveRecord::Base) do - self.table_name = 'ticks' - self.primary_key = 'symbol' - acts_as_hypertable -end query = Tick.select(<<~QUERY) time_bucket('1m', created_at) as time, @@ -79,7 +86,7 @@ function that can be reusing candlesticks from smaller timeframes. `disable_ddl_transaction!` in your migration file. ```ruby - class CreateTicks < ActiveRecord::Migration[6.0] + class CreateCaggsWithData < ActiveRecord::Migration[7.0] disable_ddl_transaction! def change