timescaledb 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 128f81d085e998eb85b11ae08b9647880e5da2033fe8c845716fb5cb0a231cb8
4
- data.tar.gz: 95c934194cad90f67d4f058491b011935f1da4bf62d40c82bbc85fb293a3189c
3
+ metadata.gz: d1fef5df000abb1cc12f56397a1e18f452bf35c061260cf403809db25954451a
4
+ data.tar.gz: d00d7d94a33b52475a6e5415e7bab669be079f62b165abdb666764a907e34dc6
5
5
  SHA512:
6
- metadata.gz: 589909dd6e1baa40199c0147d8b6e65a4848090d9c7ec9575be64ca841e8e690554ada570136a8b32e60c93f0b155c0cf1a9ba80c601c3923146690e102382ce
7
- data.tar.gz: ca63b74219756fa81ca586ad78b55e597a86f96a354b53a5c20e531925e02bb12aad7ebff000a90082040158e1ddfa6974c97e927c40c2ec65c46c2375656c67
6
+ metadata.gz: 1b814e74e3403c5a0e12ed8d3e115aff9a44e67cf0eff46a94b396e5511c0ce7a316808b1cc563890e27892383e1d0c3358c97abb8f9f49577bc5c8b01fc3fe6
7
+ data.tar.gz: ac250f31153249745e7db4ce3b7d7bbacaa25934dd7915a5a4b2aaf02595b5332344b890d1ee7a759b193f75c554bf101b7e0c492104f539edf7fa094fba133e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- timescaledb (0.2.0)
4
+ timescaledb (0.2.1)
5
5
  activerecord
6
6
  activesupport
7
7
  pg (~> 1.2)
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "timescale"
4
+ require "timescaledb"
5
5
 
6
6
  def uri_from_test
7
7
  require 'dotenv'
data/bin/tsdb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bundler/setup"
3
- require "timescale"
3
+ require "timescaledb"
4
4
  require "pry"
5
5
 
6
6
  ActiveRecord::Base.establish_connection(ARGV[0])
@@ -1,5 +1,5 @@
1
1
  require 'bundler/setup'
2
- require 'timescale'
2
+ require 'timescaledb'
3
3
  require 'pp'
4
4
  require 'pry'
5
5
  # ruby all_in_one.rb postgres://user:pass@host:port/db_name
@@ -1,3 +1,2 @@
1
- require 'timescale'
1
+ require 'timescaledb'
2
2
  require 'scenic'
3
-
@@ -72,26 +72,34 @@ module Timescaledb
72
72
  # GROUP BY bucket
73
73
  # SQL
74
74
  #
75
- def create_continuous_aggregate(name, query, **options)
75
+ def create_continuous_aggregate(table_name, query, **options)
76
76
  execute <<~SQL
77
- CREATE MATERIALIZED VIEW #{name}
77
+ CREATE MATERIALIZED VIEW #{table_name}
78
78
  WITH (timescaledb.continuous) AS
79
79
  #{query.respond_to?(:to_sql) ? query.to_sql : query}
80
80
  WITH #{"NO" unless options[:with_data]} DATA;
81
81
  SQL
82
82
 
83
- if (policy = options[:refresh_policies])
84
- # TODO: assert valid keys
85
- execute <<~SQL
86
- SELECT add_continuous_aggregate_policy('#{name}',
87
- start_offset => #{policy[:start_offset]},
88
- end_offset => #{policy[:end_offset]},
89
- schedule_interval => #{policy[:schedule_interval]});
90
- SQL
91
- end
83
+ create_continuous_aggregate_policy(table_name, options[:refresh_policies] || {})
92
84
  end
93
85
  alias_method :create_continuous_aggregates, :create_continuous_aggregate
94
86
 
87
+ def create_continuous_aggregate_policy(table_name, **options)
88
+ return if options.empty?
89
+
90
+ # TODO: assert valid keys
91
+ execute <<~SQL
92
+ SELECT add_continuous_aggregate_policy('#{table_name}',
93
+ start_offset => #{options[:start_offset]},
94
+ end_offset => #{options[:end_offset]},
95
+ schedule_interval => #{options[:schedule_interval]});
96
+ SQL
97
+ end
98
+
99
+ def remove_continuous_aggregate_policy(table_name)
100
+ execute "SELECT remove_continuous_aggregate_policy('#{table_name}')"
101
+ end
102
+
95
103
  def create_retention_policy(table_name, interval:)
96
104
  execute "SELECT add_retention_policy('#{table_name}', INTERVAL '#{interval}')"
97
105
  end
@@ -10,13 +10,16 @@ module Timescaledb
10
10
 
11
11
  def table(table_name, stream)
12
12
  super(table_name, stream)
13
- if hypertable = Timescaledb::Hypertable.find_by(hypertable_name: table_name)
13
+ if Timescaledb::Hypertable.table_exists? &&
14
+ (hypertable = Timescaledb::Hypertable.find_by(hypertable_name: table_name))
14
15
  timescale_hypertable(hypertable, stream)
15
16
  timescale_retention_policy(hypertable, stream)
16
17
  end
17
18
  end
18
19
 
19
20
  def views(stream)
21
+ return unless Timescaledb::ContinuousAggregates.table_exists?
22
+
20
23
  timescale_continuous_aggregates(stream) # Define these before any Scenic views that might use them
21
24
  super if defined?(super)
22
25
  end
@@ -1,3 +1,3 @@
1
1
  module Timescaledb
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timescaledb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jônatas Davi Paganini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-19 00:00:00.000000000 Z
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg