timescaledb 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/timescaledb/migration_helpers.rb +27 -8
- data/lib/timescaledb/schema_dumper.rb +33 -11
- data/lib/timescaledb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5cb8809c9bfe578eca1fc5fd3e5d6f93a3ff7eaa9a82f6f343d6258aa591817
|
4
|
+
data.tar.gz: 790728e08291b9df8539e08c37639bf81e8669df4e9321bc494cb27b25a21e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61deae5c4a9884e56595771fbbd5de843bc4b06b395bd119495193c5de5a9eb66087453d749d940223e79bfccd5703def5c829f9737385ebd414460782ef5340
|
7
|
+
data.tar.gz: fbd19b66f8d35af8995c25335bd001b92218acf30032533bd5972dff1bfed76105053c99c680ae705d67b6c87c8149c7426daa49de4913a58cc8d2b62327e442
|
data/Gemfile.lock
CHANGED
@@ -4,7 +4,12 @@ require 'active_record/connection_adapters/postgresql_adapter'
|
|
4
4
|
module Timescaledb
|
5
5
|
# Migration helpers can help you to setup hypertables by default.
|
6
6
|
module MigrationHelpers
|
7
|
-
# create_table
|
7
|
+
# `create_table` accepts a `hypertable` argument with options for creating
|
8
|
+
# a TimescaleDB hypertable.
|
9
|
+
#
|
10
|
+
# See https://docs.timescale.com/api/latest/hypertable/create_hypertable/#optional-arguments
|
11
|
+
# for additional options supported by the plugin.
|
12
|
+
#
|
8
13
|
# @example
|
9
14
|
# options = {
|
10
15
|
# time_column: 'created_at',
|
@@ -27,15 +32,29 @@ module Timescaledb
|
|
27
32
|
# Setup hypertable from options
|
28
33
|
# @see create_table with the hypertable options.
|
29
34
|
def create_hypertable(table_name,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
time_column: 'created_at',
|
36
|
+
chunk_time_interval: '1 week',
|
37
|
+
compress_segmentby: nil,
|
38
|
+
compress_orderby: 'created_at',
|
39
|
+
compression_interval: nil,
|
40
|
+
partition_column: nil,
|
41
|
+
number_partitions: nil,
|
42
|
+
**hypertable_options)
|
36
43
|
|
37
44
|
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
38
|
-
|
45
|
+
|
46
|
+
options = ["chunk_time_interval => INTERVAL '#{chunk_time_interval}'"]
|
47
|
+
options += hypertable_options.map { |k, v| "#{k} => #{quote(v)}" }
|
48
|
+
|
49
|
+
arguments = [
|
50
|
+
quote(table_name),
|
51
|
+
quote(time_column),
|
52
|
+
(quote(partition_column) if partition_column),
|
53
|
+
(number_partitions if partition_column),
|
54
|
+
*options
|
55
|
+
]
|
56
|
+
|
57
|
+
execute "SELECT create_hypertable(#{arguments.compact.join(', ')})"
|
39
58
|
|
40
59
|
if compress_segmentby
|
41
60
|
execute <<~SQL
|
@@ -21,15 +21,15 @@ module Timescaledb
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def timescale_hypertables(stream)
|
24
|
-
stream.puts # Insert a blank line above the hypertable definitions, for readability
|
25
|
-
|
26
24
|
sorted_hypertables.each do |hypertable|
|
27
|
-
|
25
|
+
timescale_hypertable(hypertable, stream)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
29
|
def timescale_retention_policies(stream)
|
32
|
-
|
30
|
+
if sorted_hypertables.any? { |hypertable| hypertable.jobs.exists?(proc_name: "policy_retention") }
|
31
|
+
stream.puts # Insert a blank line above the retention policies, for readability
|
32
|
+
end
|
33
33
|
|
34
34
|
sorted_hypertables.each do |hypertable|
|
35
35
|
timescale_retention_policy(hypertable, stream)
|
@@ -39,13 +39,18 @@ module Timescaledb
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def timescale_hypertable(hypertable, stream)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
time = hypertable.main_dimension
|
43
|
+
|
44
|
+
options = {
|
45
|
+
time_column: time.column_name,
|
46
|
+
chunk_time_interval: time.time_interval.inspect,
|
47
|
+
**timescale_compression_settings_for(hypertable),
|
48
|
+
**timescale_space_partition_for(hypertable),
|
49
|
+
**timescale_index_options_for(hypertable)
|
50
|
+
}
|
51
|
+
|
52
|
+
options = options.map { |k, v| "#{k}: #{v.to_json}" }.join(", ")
|
53
|
+
stream.puts %Q[ create_hypertable "#{hypertable.hypertable_name}", #{options}]
|
49
54
|
end
|
50
55
|
|
51
56
|
def timescale_retention_policy(hypertable, stream)
|
@@ -70,6 +75,22 @@ module Timescaledb
|
|
70
75
|
compression_settings
|
71
76
|
end
|
72
77
|
|
78
|
+
def timescale_space_partition_for(hypertable)
|
79
|
+
return {} unless hypertable.dimensions.length > 1
|
80
|
+
|
81
|
+
space = hypertable.dimensions.last
|
82
|
+
{partition_column: space.column_name, number_partitions: space.num_partitions}
|
83
|
+
end
|
84
|
+
|
85
|
+
def timescale_index_options_for(hypertable)
|
86
|
+
time = hypertable.main_dimension
|
87
|
+
if @connection.indexes(hypertable.hypertable_name).any? { |i| i.columns == [time.column_name] }
|
88
|
+
{}
|
89
|
+
else
|
90
|
+
{create_default_indexes: false}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
73
94
|
def timescale_continuous_aggregates(stream)
|
74
95
|
Timescaledb::ContinuousAggregates.all.each do |aggregate|
|
75
96
|
opts = if (refresh_policy = aggregate.jobs.refresh_continuous_aggregate.first)
|
@@ -95,6 +116,7 @@ module Timescaledb
|
|
95
116
|
|
96
117
|
"INTERVAL '#{value}'"
|
97
118
|
end
|
119
|
+
|
98
120
|
def sorted_hypertables
|
99
121
|
@sorted_hypertables ||= Timescaledb::Hypertable.order(:hypertable_name).to_a
|
100
122
|
end
|
data/lib/timescaledb/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.5
|
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-12-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|