timescaledb 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.tool-versions +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +11 -3
  7. data/Gemfile.scenic +7 -0
  8. data/Gemfile.scenic.lock +121 -0
  9. data/README.md +267 -121
  10. data/Rakefile +16 -1
  11. data/bin/console +2 -2
  12. data/bin/setup +2 -0
  13. data/bin/tsdb +30 -6
  14. data/examples/{Gemfile → all_in_one/Gemfile} +1 -1
  15. data/examples/{Gemfile.lock → all_in_one/Gemfile.lock} +2 -2
  16. data/examples/{all_in_one.rb → all_in_one/all_in_one.rb} +3 -6
  17. data/examples/ranking/.gitattributes +7 -0
  18. data/examples/ranking/.gitignore +29 -0
  19. data/examples/ranking/.ruby-version +1 -0
  20. data/examples/ranking/Gemfile +33 -0
  21. data/examples/ranking/Gemfile.lock +189 -0
  22. data/examples/ranking/README.md +166 -0
  23. data/examples/ranking/Rakefile +6 -0
  24. data/examples/ranking/app/controllers/application_controller.rb +2 -0
  25. data/examples/ranking/app/controllers/concerns/.keep +0 -0
  26. data/examples/ranking/app/jobs/application_job.rb +7 -0
  27. data/examples/ranking/app/models/application_record.rb +3 -0
  28. data/examples/ranking/app/models/concerns/.keep +0 -0
  29. data/examples/ranking/app/models/game.rb +2 -0
  30. data/examples/ranking/app/models/play.rb +7 -0
  31. data/examples/ranking/bin/bundle +114 -0
  32. data/examples/ranking/bin/rails +4 -0
  33. data/examples/ranking/bin/rake +4 -0
  34. data/examples/ranking/bin/setup +33 -0
  35. data/examples/ranking/config/application.rb +39 -0
  36. data/examples/ranking/config/boot.rb +4 -0
  37. data/examples/ranking/config/credentials.yml.enc +1 -0
  38. data/examples/ranking/config/database.yml +86 -0
  39. data/examples/ranking/config/environment.rb +5 -0
  40. data/examples/ranking/config/environments/development.rb +60 -0
  41. data/examples/ranking/config/environments/production.rb +75 -0
  42. data/examples/ranking/config/environments/test.rb +53 -0
  43. data/examples/ranking/config/initializers/cors.rb +16 -0
  44. data/examples/ranking/config/initializers/filter_parameter_logging.rb +8 -0
  45. data/examples/ranking/config/initializers/inflections.rb +16 -0
  46. data/examples/ranking/config/initializers/timescale.rb +3 -0
  47. data/examples/ranking/config/locales/en.yml +33 -0
  48. data/examples/ranking/config/puma.rb +43 -0
  49. data/examples/ranking/config/routes.rb +6 -0
  50. data/examples/ranking/config/storage.yml +34 -0
  51. data/examples/ranking/config.ru +6 -0
  52. data/examples/ranking/db/migrate/20220209120747_create_games.rb +10 -0
  53. data/examples/ranking/db/migrate/20220209120910_create_plays.rb +19 -0
  54. data/examples/ranking/db/migrate/20220209143347_create_score_per_hours.rb +5 -0
  55. data/examples/ranking/db/schema.rb +47 -0
  56. data/examples/ranking/db/seeds.rb +7 -0
  57. data/examples/ranking/db/views/score_per_hours_v01.sql +7 -0
  58. data/examples/ranking/lib/tasks/.keep +0 -0
  59. data/examples/ranking/log/.keep +0 -0
  60. data/examples/ranking/public/robots.txt +1 -0
  61. data/examples/ranking/storage/.keep +0 -0
  62. data/examples/ranking/tmp/.keep +0 -0
  63. data/examples/ranking/tmp/pids/.keep +0 -0
  64. data/examples/ranking/tmp/storage/.keep +0 -0
  65. data/examples/ranking/vendor/.keep +0 -0
  66. data/lib/timescaledb/acts_as_hypertable/core.rb +87 -0
  67. data/lib/timescaledb/acts_as_hypertable.rb +62 -0
  68. data/lib/{timescale → timescaledb}/chunk.rb +9 -1
  69. data/lib/{timescale → timescaledb}/compression_settings.rb +3 -2
  70. data/lib/timescaledb/continuous_aggregates.rb +19 -0
  71. data/lib/timescaledb/dimensions.rb +6 -0
  72. data/lib/{timescale → timescaledb}/hypertable.rb +9 -5
  73. data/lib/timescaledb/job.rb +10 -0
  74. data/lib/{timescale → timescaledb}/job_stats.rb +3 -4
  75. data/lib/{timescale → timescaledb}/migration_helpers.rb +35 -5
  76. data/lib/timescaledb/scenic/adapter.rb +55 -0
  77. data/lib/timescaledb/scenic/extension.rb +72 -0
  78. data/lib/timescaledb/schema_dumper.rb +88 -0
  79. data/lib/timescaledb/stats_report.rb +35 -0
  80. data/lib/timescaledb/version.rb +3 -0
  81. data/lib/timescaledb.rb +64 -0
  82. data/{timescale.gemspec → timescaledb.gemspec} +6 -4
  83. metadata +106 -20
  84. data/lib/timescale/acts_as_hypertable.rb +0 -114
  85. data/lib/timescale/continuous_aggregates.rb +0 -9
  86. data/lib/timescale/job.rb +0 -13
  87. data/lib/timescale/stats_report.rb +0 -28
  88. data/lib/timescale/version.rb +0 -3
  89. data/lib/timescale.rb +0 -52
@@ -1,14 +1,14 @@
1
- require_relative 'lib/timescale/version'
1
+ require_relative 'lib/timescaledb/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "timescaledb"
5
- spec.version = Timescale::VERSION
5
+ spec.version = Timescaledb::VERSION
6
6
  spec.authors = ["Jônatas Davi Paganini"]
7
7
  spec.email = ["jonatasdp@gmail.com"]
8
8
 
9
9
  spec.summary = %q{TimescaleDB helpers for Ruby ecosystem.}
10
10
  spec.description = %q{Functions from timescaledb available in the ActiveRecord models.}
11
- spec.homepage = "https://github.com/jonatas/timescale"
11
+ spec.homepage = "https://github.com/jonatas/timescaledb"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
@@ -27,12 +27,14 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^bin/tsdb}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "pg", "~> 1.2"
30
+ spec.add_dependency "pg", "~> 1.2"
31
31
  spec.add_dependency "activerecord"
32
+ spec.add_dependency "activesupport"
32
33
 
33
34
  spec.add_development_dependency "pry"
34
35
  spec.add_development_dependency "rspec-its"
35
36
  spec.add_development_dependency "rspec", "~> 3.0"
36
37
  spec.add_development_dependency "dotenv"
37
38
  spec.add_development_dependency "rake", "~> 12.0"
39
+ spec.add_development_dependency "database_cleaner-active_record"
38
40
  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.1.2
4
+ version: 0.2.0
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: 2021-10-02 00:00:00.000000000 Z
11
+ date: 2022-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: pry
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '12.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: database_cleaner-active_record
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: Functions from timescaledb available in the ActiveRecord models.
112
140
  email:
113
141
  - jonatasdp@gmail.com
@@ -118,37 +146,95 @@ extra_rdoc_files: []
118
146
  files:
119
147
  - ".gitignore"
120
148
  - ".rspec"
149
+ - ".ruby-version"
150
+ - ".tool-versions"
121
151
  - ".travis.yml"
122
152
  - CODE_OF_CONDUCT.md
123
153
  - Gemfile
124
154
  - Gemfile.lock
155
+ - Gemfile.scenic
156
+ - Gemfile.scenic.lock
125
157
  - LICENSE.txt
126
158
  - README.md
127
159
  - Rakefile
128
160
  - bin/console
129
161
  - bin/setup
130
162
  - bin/tsdb
131
- - examples/Gemfile
132
- - examples/Gemfile.lock
133
- - examples/all_in_one.rb
134
- - lib/timescale.rb
135
- - lib/timescale/acts_as_hypertable.rb
136
- - lib/timescale/chunk.rb
137
- - lib/timescale/compression_settings.rb
138
- - lib/timescale/continuous_aggregates.rb
139
- - lib/timescale/hypertable.rb
140
- - lib/timescale/job.rb
141
- - lib/timescale/job_stats.rb
142
- - lib/timescale/migration_helpers.rb
143
- - lib/timescale/stats_report.rb
144
- - lib/timescale/version.rb
145
- - timescale.gemspec
146
- homepage: https://github.com/jonatas/timescale
163
+ - examples/all_in_one/Gemfile
164
+ - examples/all_in_one/Gemfile.lock
165
+ - examples/all_in_one/all_in_one.rb
166
+ - examples/ranking/.gitattributes
167
+ - examples/ranking/.gitignore
168
+ - examples/ranking/.ruby-version
169
+ - examples/ranking/Gemfile
170
+ - examples/ranking/Gemfile.lock
171
+ - examples/ranking/README.md
172
+ - examples/ranking/Rakefile
173
+ - examples/ranking/app/controllers/application_controller.rb
174
+ - examples/ranking/app/controllers/concerns/.keep
175
+ - examples/ranking/app/jobs/application_job.rb
176
+ - examples/ranking/app/models/application_record.rb
177
+ - examples/ranking/app/models/concerns/.keep
178
+ - examples/ranking/app/models/game.rb
179
+ - examples/ranking/app/models/play.rb
180
+ - examples/ranking/bin/bundle
181
+ - examples/ranking/bin/rails
182
+ - examples/ranking/bin/rake
183
+ - examples/ranking/bin/setup
184
+ - examples/ranking/config.ru
185
+ - examples/ranking/config/application.rb
186
+ - examples/ranking/config/boot.rb
187
+ - examples/ranking/config/credentials.yml.enc
188
+ - examples/ranking/config/database.yml
189
+ - examples/ranking/config/environment.rb
190
+ - examples/ranking/config/environments/development.rb
191
+ - examples/ranking/config/environments/production.rb
192
+ - examples/ranking/config/environments/test.rb
193
+ - examples/ranking/config/initializers/cors.rb
194
+ - examples/ranking/config/initializers/filter_parameter_logging.rb
195
+ - examples/ranking/config/initializers/inflections.rb
196
+ - examples/ranking/config/initializers/timescale.rb
197
+ - examples/ranking/config/locales/en.yml
198
+ - examples/ranking/config/puma.rb
199
+ - examples/ranking/config/routes.rb
200
+ - examples/ranking/config/storage.yml
201
+ - examples/ranking/db/migrate/20220209120747_create_games.rb
202
+ - examples/ranking/db/migrate/20220209120910_create_plays.rb
203
+ - examples/ranking/db/migrate/20220209143347_create_score_per_hours.rb
204
+ - examples/ranking/db/schema.rb
205
+ - examples/ranking/db/seeds.rb
206
+ - examples/ranking/db/views/score_per_hours_v01.sql
207
+ - examples/ranking/lib/tasks/.keep
208
+ - examples/ranking/log/.keep
209
+ - examples/ranking/public/robots.txt
210
+ - examples/ranking/storage/.keep
211
+ - examples/ranking/tmp/.keep
212
+ - examples/ranking/tmp/pids/.keep
213
+ - examples/ranking/tmp/storage/.keep
214
+ - examples/ranking/vendor/.keep
215
+ - lib/timescaledb.rb
216
+ - lib/timescaledb/acts_as_hypertable.rb
217
+ - lib/timescaledb/acts_as_hypertable/core.rb
218
+ - lib/timescaledb/chunk.rb
219
+ - lib/timescaledb/compression_settings.rb
220
+ - lib/timescaledb/continuous_aggregates.rb
221
+ - lib/timescaledb/dimensions.rb
222
+ - lib/timescaledb/hypertable.rb
223
+ - lib/timescaledb/job.rb
224
+ - lib/timescaledb/job_stats.rb
225
+ - lib/timescaledb/migration_helpers.rb
226
+ - lib/timescaledb/scenic/adapter.rb
227
+ - lib/timescaledb/scenic/extension.rb
228
+ - lib/timescaledb/schema_dumper.rb
229
+ - lib/timescaledb/stats_report.rb
230
+ - lib/timescaledb/version.rb
231
+ - timescaledb.gemspec
232
+ homepage: https://github.com/jonatas/timescaledb
147
233
  licenses:
148
234
  - MIT
149
235
  metadata:
150
236
  allowed_push_host: https://rubygems.org
151
- homepage_uri: https://github.com/jonatas/timescale
237
+ homepage_uri: https://github.com/jonatas/timescaledb
152
238
  post_install_message:
153
239
  rdoc_options: []
154
240
  require_paths:
@@ -164,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
250
  - !ruby/object:Gem::Version
165
251
  version: '0'
166
252
  requirements: []
167
- rubygems_version: 3.0.3
253
+ rubygems_version: 3.1.2
168
254
  signing_key:
169
255
  specification_version: 4
170
256
  summary: TimescaleDB helpers for Ruby ecosystem.
@@ -1,114 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Timescale
4
- # If you want your model to hook into its underlying hypertable
5
- # as well as have access to TimescaleDB specific data, methods, and more,
6
- # specify this macro in your model.
7
- #
8
- # @note Your model's table needs to have already been converted to a hypertable
9
- # via the TimescaleDB `create_hypertable` function for this to work.
10
- #
11
- # @see https://docs.timescale.com/api/latest/hypertable/create_hypertable/ for
12
- # how to use the SQL `create_hypertable` function.
13
- # @see Timescale::MigrationHelpers#create_table for how to create a new hypertable
14
- # via a Rails migration utilizing the standard `create_table` method.
15
- #
16
- # @example Enabling the macro on your model
17
- # class Event < ActiveRecord::Base
18
- # acts_as_hypertable
19
- # end
20
- #
21
- # @see Timescale::ActsAsHypertable::ClassMethods#acts_as_hypertable
22
- # for configuration options
23
- module ActsAsHypertable
24
- extend ActiveSupport::Concern
25
-
26
- DEFAULT_OPTIONS = {
27
- time_column: :created_at
28
- }.freeze
29
-
30
- module ClassMethods
31
- # == Configuration options
32
- #
33
- # @param [Hash] options The options to initialize your macro with.
34
- # @option options [Symbol] :time_column The name of the column in your
35
- # model's table containing time values. The name provided should be
36
- # the same name as the `time_column_name` you passed to the
37
- # TimescaleDB `create_hypertable` function.
38
- #
39
- # @example Enabling the macro on your model with options
40
- # class Event < ActiveRecord::Base
41
- # acts_as_hypertable time_column: :timestamp
42
- # end
43
- #
44
- def acts_as_hypertable(options = {})
45
- return if already_declared_as_hypertable?
46
-
47
- extend Timescale::ActsAsHypertable::HypertableClassMethods
48
-
49
- class_attribute :hypertable_options, instance_writer: false
50
-
51
- self.hypertable_options = DEFAULT_OPTIONS.dup
52
- hypertable_options.merge!(options)
53
- normalize_hypertable_options
54
-
55
- define_association_scopes
56
- define_default_scopes
57
- end
58
-
59
- def define_association_scopes
60
- scope :chunks, -> do
61
- Chunk.where(hypertable_name: table_name)
62
- end
63
-
64
- scope :hypertable, -> do
65
- Hypertable.find_by(hypertable_name: table_name)
66
- end
67
-
68
- scope :jobs, -> do
69
- Job.where(hypertable_name: table_name)
70
- end
71
-
72
- scope :job_stats, -> do
73
- JobStats.where(hypertable_name: table_name)
74
- end
75
-
76
- scope :compression_settings, -> do
77
- CompressionSettings.where(hypertable_name: table_name)
78
- end
79
-
80
- scope :continuous_aggregates, -> do
81
- ContinuousAggregates.where(hypertable_name: table_name)
82
- end
83
- end
84
-
85
- def define_default_scopes
86
- scope :last_month, -> { where("#{time_column} > ?", 1.month.ago) }
87
- scope :last_week, -> { where("#{time_column} > ?", 1.week.ago) }
88
- scope :last_hour, -> { where("#{time_column} > ?", 1.hour.ago) }
89
- scope :yesterday, -> { where("#{time_column} = ?", 1.day.ago.to_date) }
90
- scope :today, -> { where("#{time_column} = ?", Date.today) }
91
- end
92
-
93
- private
94
-
95
- def already_declared_as_hypertable?
96
- singleton_class
97
- .included_modules
98
- .include?(Timescale::ActsAsHypertable::HypertableClassMethods)
99
- end
100
- end
101
-
102
- module HypertableClassMethods
103
- def time_column
104
- @hypertable_time_column ||= hypertable_options[:time_column] || :created_at
105
- end
106
-
107
- protected
108
-
109
- def normalize_hypertable_options
110
- hypertable_options[:time_column] = hypertable_options[:time_column].to_sym
111
- end
112
- end
113
- end
114
- end
@@ -1,9 +0,0 @@
1
- module Timescale
2
- class ContinuousAggregates < ActiveRecord::Base
3
- self.table_name = "timescaledb_information.continuous_aggregates"
4
- self.primary_key = 'materialization_hypertable_name'
5
-
6
- has_many :jobs, foreign_key: "hypertable_name",
7
- class_name: "Timescale::Job"
8
- end
9
- end
data/lib/timescale/job.rb DELETED
@@ -1,13 +0,0 @@
1
- module Timescale
2
- class Job < ActiveRecord::Base
3
- self.table_name = "timescaledb_information.jobs"
4
- self.primary_key = "job_id"
5
-
6
- attribute :schedule_interval, :interval
7
- attribute :max_runtime, :interval
8
- attribute :retry_period, :interval
9
-
10
- scope :compression, -> { where(proc_name: "tsbs_compress_chunks") }
11
- scope :scheduled, -> { where(scheduled: true) }
12
- end
13
- end
@@ -1,28 +0,0 @@
1
- require "active_support/core_ext/numeric/conversions"
2
- module Timescale
3
- module StatsReport
4
- module_function
5
- def resume
6
- {
7
- hypertables: {
8
- count: Hypertable.count,
9
- uncompressed: Hypertable.all.to_a.count { |h| h.compression_stats.empty? },
10
- approximate_row_count: Hypertable.all.to_a.map do |hypertable|
11
- { hypertable.hypertable_name => hypertable.approximate_row_count }
12
- end.inject(&:merge!),
13
- chunks: {
14
- total: Chunk.count,
15
- compressed: Chunk.compressed.count,
16
- uncompressed: Chunk.uncompressed.count
17
- },
18
- size: {
19
- before_compressing: Hypertable.all.map{|h|h.before_total_bytes}.inject(:+).to_s(:human_size),
20
- after_compressing: Hypertable.all.map{|h|h.after_total_bytes}.inject(:+).to_s(:human_size)
21
- }
22
- },
23
- continuous_aggregates: { count: ContinuousAggregates.count },
24
- jobs_stats: JobStats.resume
25
- }
26
- end
27
- end
28
- end
@@ -1,3 +0,0 @@
1
- module Timescale
2
- VERSION = '0.1.2'
3
- end
data/lib/timescale.rb DELETED
@@ -1,52 +0,0 @@
1
- require 'active_record'
2
-
3
- require_relative 'timescale/acts_as_hypertable'
4
- require_relative 'timescale/chunk'
5
- require_relative 'timescale/compression_settings'
6
- require_relative 'timescale/continuous_aggregates'
7
- require_relative 'timescale/hypertable'
8
- require_relative 'timescale/job'
9
- require_relative 'timescale/job_stats'
10
- require_relative 'timescale/stats_report'
11
- require_relative 'timescale/migration_helpers'
12
- require_relative 'timescale/version'
13
-
14
- module Timescale
15
- module_function
16
-
17
- def chunks
18
- Chunk.all
19
- end
20
-
21
- def hypertables
22
- Hypertable.all
23
- end
24
-
25
- def continuous_aggregates
26
- ContinuousAggregates.all
27
- end
28
-
29
- def compression_settings
30
- CompressionSettings.all
31
- end
32
-
33
- def jobs
34
- Job.all
35
- end
36
-
37
- def job_stats
38
- JobStats.all
39
- end
40
-
41
- def show_stats
42
- StatsReport.resume
43
- end
44
-
45
- def default_hypertable_options
46
- Timescale::ActsAsHypertable::DEFAULT_OPTIONS
47
- end
48
- end
49
-
50
- ActiveSupport.on_load :active_record do
51
- include Timescale::ActsAsHypertable
52
- end