Skip to content

Commit

Permalink
Improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatas committed May 2, 2024
1 parent f9a50be commit 46a74c0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions docs/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 46a74c0

Please sign in to comment.