timescaledb-rails 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/timescaledb/rails/extensions/active_record/command_recorder.rb +42 -0
- data/lib/timescaledb/rails/extensions/active_record/{database_tasks.rb → postgresql_database_tasks.rb} +16 -4
- data/lib/timescaledb/rails/extensions/active_record/schema_statements.rb +9 -0
- data/lib/timescaledb/rails/models/hypertable.rb +3 -1
- data/lib/timescaledb/rails/railtie.rb +7 -2
- data/lib/timescaledb/rails/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b682514201eb2e88a829297e9582cfe9513a127432de8acf7a060b769f38ca2
|
4
|
+
data.tar.gz: c30e268a3b9be19d95537230126a1c12c8aa97746afb3227f0e544293527d399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1011081beb9b4a23ff4ceafe7b47278ad7418ace4438e3a67097e8db933802afd15875ba0a28f4141154ba12170bff7e4db28c4d8c5040d716c49f53b6c8d328
|
7
|
+
data.tar.gz: cd429d48862ce9dd82002fe35d3953814e893bd066a6e2143a9d5245036015d21b2b23174165389888225649e963a696a2328e0b5a228bf88efc268c39a5919e
|
data/README.md
CHANGED
@@ -60,6 +60,16 @@ class AddEventCompression < ActiveRecord::Migration[7.0]
|
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
|
+
Disable hypertable compression by doing:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class RemoveEventCompression < ActiveRecord::Migration[7.0]
|
67
|
+
def change
|
68
|
+
remove_hypertable_compression :events
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
63
73
|
## Supported Ruby/Rails versions
|
64
74
|
|
65
75
|
Supported Ruby/Rails versions are listed in [`.github/workflows/ci.yaml`](https://github.com/crunchloop/timescaledb-rails/blob/main/.github/workflows/ci.yaml)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Timescaledb
|
4
|
+
module Rails
|
5
|
+
module ActiveRecord
|
6
|
+
# :nodoc:
|
7
|
+
module CommandRecorder
|
8
|
+
def create_hypertable(*args, &block)
|
9
|
+
record(:create_hypertable, args, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_hypertable_compression(*args, &block)
|
13
|
+
record(:add_hypertable_compression, args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def remove_hypertable_compression(*args, &block)
|
17
|
+
record(:remove_hypertable_compression, args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def invert_create_hypertable(args, &block)
|
21
|
+
if block.nil?
|
22
|
+
raise ::ActiveRecord::IrreversibleMigration, 'create_hypertable is only reversible if given a block (can be empty).' # rubocop:disable Layout/LineLength
|
23
|
+
end
|
24
|
+
|
25
|
+
[:drop_table, args.first, block]
|
26
|
+
end
|
27
|
+
|
28
|
+
def invert_add_hypertable_compression(args, &block)
|
29
|
+
[:remove_hypertable_compression, args, block]
|
30
|
+
end
|
31
|
+
|
32
|
+
def invert_remove_hypertable_compression(args, &block)
|
33
|
+
if args.size < 2
|
34
|
+
raise ::ActiveRecord::IrreversibleMigration, 'remove_hypertable_compression is only reversible if given table name and compress period.' # rubocop:disable Layout/LineLength
|
35
|
+
end
|
36
|
+
|
37
|
+
[:add_hypertable_compression, args, block]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -7,9 +7,13 @@ module Timescaledb
|
|
7
7
|
module Rails
|
8
8
|
module ActiveRecord
|
9
9
|
# :nodoc:
|
10
|
-
module
|
11
|
-
|
12
|
-
|
10
|
+
module PostgreSQLDatabaseTasks
|
11
|
+
# @override
|
12
|
+
def structure_dump(filename, extra_flags) # rubocop:disable Metrics/MethodLength
|
13
|
+
extra_flags = Array(extra_flags)
|
14
|
+
extra_flags << timescale_structure_dump_default_flags if timescale_enabled?
|
15
|
+
|
16
|
+
super(filename, extra_flags)
|
13
17
|
|
14
18
|
return unless timescale_enabled?
|
15
19
|
|
@@ -46,7 +50,7 @@ module Timescaledb
|
|
46
50
|
|
47
51
|
def hypertable_options(hypertable)
|
48
52
|
sql_statements = ["if_not_exists => 'TRUE'"]
|
49
|
-
sql_statements << "chunk_time_interval => INTERVAL '#{hypertable.chunk_time_interval
|
53
|
+
sql_statements << "chunk_time_interval => INTERVAL '#{hypertable.chunk_time_interval}'"
|
50
54
|
|
51
55
|
sql_statements.compact.join(', ')
|
52
56
|
end
|
@@ -68,6 +72,14 @@ module Timescaledb
|
|
68
72
|
sql_statements.join(', ')
|
69
73
|
end
|
70
74
|
|
75
|
+
# Returns `pg_dump` flag to exclude `_timescaledb_internal` schema tables.
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
def timescale_structure_dump_default_flags
|
79
|
+
'--exclude-schema=_timescaledb_internal'
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [Boolean]
|
71
83
|
def timescale_enabled?
|
72
84
|
Timescaledb::Rails::Hypertable.table_exists?
|
73
85
|
end
|
@@ -41,6 +41,15 @@ module Timescaledb
|
|
41
41
|
execute "SELECT add_compression_policy('#{table_name}', INTERVAL '#{compress_after}')"
|
42
42
|
end
|
43
43
|
|
44
|
+
# Disables compression from given table.
|
45
|
+
#
|
46
|
+
# remove_hypertable_compression('events')
|
47
|
+
#
|
48
|
+
def remove_hypertable_compression(table_name, compress_after = nil, segment_by: nil, order_by: nil) # rubocop:disable Lint/UnusedMethodArgument
|
49
|
+
execute "SELECT remove_compression_policy('#{table_name}');"
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [String]
|
44
53
|
def hypertable_options_to_sql(options)
|
45
54
|
sql_statements = options.map do |option, value|
|
46
55
|
case option
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'rails'
|
4
4
|
|
5
|
-
require_relative 'extensions/active_record/
|
5
|
+
require_relative 'extensions/active_record/command_recorder'
|
6
|
+
require_relative 'extensions/active_record/postgresql_database_tasks'
|
6
7
|
require_relative 'extensions/active_record/schema_dumper'
|
7
8
|
require_relative 'extensions/active_record/schema_statements'
|
8
9
|
|
@@ -18,8 +19,12 @@ module Timescaledb
|
|
18
19
|
|
19
20
|
initializer 'timescaledb-rails.add_timescale_support_to_active_record' do
|
20
21
|
ActiveSupport.on_load(:active_record) do
|
22
|
+
::ActiveRecord::Migration::CommandRecorder.prepend(
|
23
|
+
Timescaledb::Rails::ActiveRecord::CommandRecorder
|
24
|
+
)
|
25
|
+
|
21
26
|
::ActiveRecord::Tasks::PostgreSQLDatabaseTasks.prepend(
|
22
|
-
Timescaledb::Rails::ActiveRecord::
|
27
|
+
Timescaledb::Rails::ActiveRecord::PostgreSQLDatabaseTasks
|
23
28
|
)
|
24
29
|
|
25
30
|
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timescaledb-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iván Etchart
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-11-
|
12
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -119,7 +119,8 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- lib/timescaledb-rails.rb
|
121
121
|
- lib/timescaledb/rails.rb
|
122
|
-
- lib/timescaledb/rails/extensions/active_record/
|
122
|
+
- lib/timescaledb/rails/extensions/active_record/command_recorder.rb
|
123
|
+
- lib/timescaledb/rails/extensions/active_record/postgresql_database_tasks.rb
|
123
124
|
- lib/timescaledb/rails/extensions/active_record/schema_dumper.rb
|
124
125
|
- lib/timescaledb/rails/extensions/active_record/schema_statements.rb
|
125
126
|
- lib/timescaledb/rails/models.rb
|