timescaledb-rails 0.1.2 → 0.1.3
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/README.md +10 -0
- data/lib/timescaledb/rails/extensions/active_record/command_recorder.rb +42 -0
- data/lib/timescaledb/rails/extensions/active_record/postgresql_database_tasks.rb +14 -3
- 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 +3 -3
- data/lib/timescaledb/rails/version.rb +1 -1
- metadata +3 -3
- data/lib/timescaledb/rails/extensions/active_record/database_tasks.rb +0 -32
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
|
@@ -9,8 +9,11 @@ module Timescaledb
|
|
9
9
|
# :nodoc:
|
10
10
|
module PostgreSQLDatabaseTasks
|
11
11
|
# @override
|
12
|
-
def structure_dump(filename, extra_flags)
|
13
|
-
|
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)
|
14
17
|
|
15
18
|
return unless timescale_enabled?
|
16
19
|
|
@@ -47,7 +50,7 @@ module Timescaledb
|
|
47
50
|
|
48
51
|
def hypertable_options(hypertable)
|
49
52
|
sql_statements = ["if_not_exists => 'TRUE'"]
|
50
|
-
sql_statements << "chunk_time_interval => INTERVAL '#{hypertable.chunk_time_interval
|
53
|
+
sql_statements << "chunk_time_interval => INTERVAL '#{hypertable.chunk_time_interval}'"
|
51
54
|
|
52
55
|
sql_statements.compact.join(', ')
|
53
56
|
end
|
@@ -69,6 +72,14 @@ module Timescaledb
|
|
69
72
|
sql_statements.join(', ')
|
70
73
|
end
|
71
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]
|
72
83
|
def timescale_enabled?
|
73
84
|
Timescaledb::Rails::Hypertable.table_exists?
|
74
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,7 @@
|
|
2
2
|
|
3
3
|
require 'rails'
|
4
4
|
|
5
|
-
require_relative 'extensions/active_record/
|
5
|
+
require_relative 'extensions/active_record/command_recorder'
|
6
6
|
require_relative 'extensions/active_record/postgresql_database_tasks'
|
7
7
|
require_relative 'extensions/active_record/schema_dumper'
|
8
8
|
require_relative 'extensions/active_record/schema_statements'
|
@@ -19,8 +19,8 @@ module Timescaledb
|
|
19
19
|
|
20
20
|
initializer 'timescaledb-rails.add_timescale_support_to_active_record' do
|
21
21
|
ActiveSupport.on_load(:active_record) do
|
22
|
-
::ActiveRecord::
|
23
|
-
Timescaledb::Rails::ActiveRecord::
|
22
|
+
::ActiveRecord::Migration::CommandRecorder.prepend(
|
23
|
+
Timescaledb::Rails::ActiveRecord::CommandRecorder
|
24
24
|
)
|
25
25
|
|
26
26
|
::ActiveRecord::Tasks::PostgreSQLDatabaseTasks.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,7 @@ 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
123
|
- lib/timescaledb/rails/extensions/active_record/postgresql_database_tasks.rb
|
124
124
|
- lib/timescaledb/rails/extensions/active_record/schema_dumper.rb
|
125
125
|
- lib/timescaledb/rails/extensions/active_record/schema_statements.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Timescaledb
|
4
|
-
module Rails
|
5
|
-
module ActiveRecord
|
6
|
-
# :nodoc:
|
7
|
-
module DatabaseTasks
|
8
|
-
# @override
|
9
|
-
def structure_dump_flags_for(adapter)
|
10
|
-
return (flags = super) if adapter != 'postgresql'
|
11
|
-
|
12
|
-
if flags.nil?
|
13
|
-
timescaledb_structure_dump_default_flags
|
14
|
-
elsif flags.is_a?(Array)
|
15
|
-
flags << timescaledb_structure_dump_default_flags
|
16
|
-
elsif flags.is_a?(String)
|
17
|
-
"#{flags} #{timescaledb_structure_dump_default_flags}"
|
18
|
-
else
|
19
|
-
flags
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns `pg_dump` flag to exclude `_timescaledb_internal` schema tables.
|
24
|
-
#
|
25
|
-
# @return [String]
|
26
|
-
def timescaledb_structure_dump_default_flags
|
27
|
-
'--exclude-schema=_timescaledb_internal'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|