timescaledb 0.1.4 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +6 -3
- data/Gemfile.scenic +7 -0
- data/Gemfile.scenic.lock +121 -0
- data/README.md +35 -18
- data/Rakefile +7 -1
- data/bin/console +3 -3
- data/bin/setup +2 -0
- data/bin/tsdb +7 -7
- data/examples/{Gemfile → all_in_one/Gemfile} +0 -0
- data/examples/{Gemfile.lock → all_in_one/Gemfile.lock} +0 -0
- data/examples/{all_in_one.rb → all_in_one/all_in_one.rb} +1 -1
- data/examples/ranking/.gitattributes +7 -0
- data/examples/ranking/.gitignore +29 -0
- data/examples/ranking/.ruby-version +1 -0
- data/examples/ranking/Gemfile +33 -0
- data/examples/ranking/Gemfile.lock +189 -0
- data/examples/ranking/README.md +166 -0
- data/examples/ranking/Rakefile +6 -0
- data/examples/ranking/app/controllers/application_controller.rb +2 -0
- data/examples/ranking/app/controllers/concerns/.keep +0 -0
- data/examples/ranking/app/jobs/application_job.rb +7 -0
- data/examples/ranking/app/models/application_record.rb +3 -0
- data/examples/ranking/app/models/concerns/.keep +0 -0
- data/examples/ranking/app/models/game.rb +2 -0
- data/examples/ranking/app/models/play.rb +7 -0
- data/examples/ranking/bin/bundle +114 -0
- data/examples/ranking/bin/rails +4 -0
- data/examples/ranking/bin/rake +4 -0
- data/examples/ranking/bin/setup +33 -0
- data/examples/ranking/config/application.rb +39 -0
- data/examples/ranking/config/boot.rb +4 -0
- data/examples/ranking/config/credentials.yml.enc +1 -0
- data/examples/ranking/config/database.yml +86 -0
- data/examples/ranking/config/environment.rb +5 -0
- data/examples/ranking/config/environments/development.rb +60 -0
- data/examples/ranking/config/environments/production.rb +75 -0
- data/examples/ranking/config/environments/test.rb +53 -0
- data/examples/ranking/config/initializers/cors.rb +16 -0
- data/examples/ranking/config/initializers/filter_parameter_logging.rb +8 -0
- data/examples/ranking/config/initializers/inflections.rb +16 -0
- data/examples/ranking/config/initializers/timescale.rb +2 -0
- data/examples/ranking/config/locales/en.yml +33 -0
- data/examples/ranking/config/puma.rb +43 -0
- data/examples/ranking/config/routes.rb +6 -0
- data/examples/ranking/config/storage.yml +34 -0
- data/examples/ranking/config.ru +6 -0
- data/examples/ranking/db/migrate/20220209120747_create_games.rb +10 -0
- data/examples/ranking/db/migrate/20220209120910_create_plays.rb +19 -0
- data/examples/ranking/db/migrate/20220209143347_create_score_per_hours.rb +5 -0
- data/examples/ranking/db/schema.rb +47 -0
- data/examples/ranking/db/seeds.rb +7 -0
- data/examples/ranking/db/views/score_per_hours_v01.sql +7 -0
- data/examples/ranking/lib/tasks/.keep +0 -0
- data/examples/ranking/log/.keep +0 -0
- data/examples/ranking/public/robots.txt +1 -0
- data/examples/ranking/storage/.keep +0 -0
- data/examples/ranking/tmp/.keep +0 -0
- data/examples/ranking/tmp/pids/.keep +0 -0
- data/examples/ranking/tmp/storage/.keep +0 -0
- data/examples/ranking/vendor/.keep +0 -0
- data/lib/{timescale → timescaledb}/acts_as_hypertable/core.rb +1 -1
- data/lib/{timescale → timescaledb}/acts_as_hypertable.rb +6 -6
- data/lib/{timescale → timescaledb}/chunk.rb +1 -1
- data/lib/{timescale → timescaledb}/compression_settings.rb +3 -2
- data/lib/{timescale → timescaledb}/continuous_aggregates.rb +5 -4
- data/lib/timescaledb/dimensions.rb +6 -0
- data/lib/{timescale → timescaledb}/hypertable.rb +5 -5
- data/lib/timescaledb/job.rb +10 -0
- data/lib/{timescale → timescaledb}/job_stats.rb +3 -4
- data/lib/{timescale → timescaledb}/migration_helpers.rb +51 -13
- data/lib/timescaledb/scenic/adapter.rb +55 -0
- data/lib/timescaledb/scenic/extension.rb +72 -0
- data/lib/timescaledb/schema_dumper.rb +91 -0
- data/lib/{timescale → timescaledb}/stats_report.rb +2 -2
- data/lib/timescaledb/version.rb +3 -0
- data/lib/timescaledb.rb +64 -0
- data/{timescale.gemspec → timescaledb.gemspec} +5 -4
- metadata +92 -23
- data/lib/timescale/dimensions.rb +0 -7
- data/lib/timescale/job.rb +0 -13
- data/lib/timescale/schema_dumper.rb +0 -24
- data/lib/timescale/version.rb +0 -3
- data/lib/timescale.rb +0 -50
@@ -0,0 +1,60 @@
|
|
1
|
+
require "active_support/core_ext/integer/time"
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
+
|
6
|
+
# In the development environment your application's code is reloaded any time
|
7
|
+
# it changes. This slows down response time but is perfect for development
|
8
|
+
# since you don't have to restart the web server when you make code changes.
|
9
|
+
config.cache_classes = false
|
10
|
+
|
11
|
+
# Do not eager load code on boot.
|
12
|
+
config.eager_load = false
|
13
|
+
|
14
|
+
# Show full error reports.
|
15
|
+
config.consider_all_requests_local = true
|
16
|
+
|
17
|
+
# Enable server timing
|
18
|
+
config.server_timing = true
|
19
|
+
|
20
|
+
# Enable/disable caching. By default caching is disabled.
|
21
|
+
# Run rails dev:cache to toggle caching.
|
22
|
+
if Rails.root.join("tmp/caching-dev.txt").exist?
|
23
|
+
config.cache_store = :memory_store
|
24
|
+
config.public_file_server.headers = {
|
25
|
+
"Cache-Control" => "public, max-age=#{2.days.to_i}"
|
26
|
+
}
|
27
|
+
else
|
28
|
+
config.action_controller.perform_caching = false
|
29
|
+
|
30
|
+
config.cache_store = :null_store
|
31
|
+
end
|
32
|
+
|
33
|
+
# Store uploaded files on the local file system (see config/storage.yml for options).
|
34
|
+
config.active_storage.service = :local
|
35
|
+
|
36
|
+
# Print deprecation notices to the Rails logger.
|
37
|
+
config.active_support.deprecation = :log
|
38
|
+
|
39
|
+
# Raise exceptions for disallowed deprecations.
|
40
|
+
config.active_support.disallowed_deprecation = :raise
|
41
|
+
|
42
|
+
# Tell Active Support which deprecation messages to disallow.
|
43
|
+
config.active_support.disallowed_deprecation_warnings = []
|
44
|
+
|
45
|
+
# Raise an error on page load if there are pending migrations.
|
46
|
+
config.active_record.migration_error = :page_load
|
47
|
+
|
48
|
+
# Highlight code that triggered database queries in logs.
|
49
|
+
config.active_record.verbose_query_logs = true
|
50
|
+
|
51
|
+
|
52
|
+
# Raises error for missing translations.
|
53
|
+
# config.i18n.raise_on_missing_translations = true
|
54
|
+
|
55
|
+
# Annotate rendered view with file names.
|
56
|
+
# config.action_view.annotate_rendered_view_with_filenames = true
|
57
|
+
|
58
|
+
# Uncomment if you wish to allow Action Cable access from any origin.
|
59
|
+
# config.action_cable.disable_request_forgery_protection = true
|
60
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "active_support/core_ext/integer/time"
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
+
|
6
|
+
# Code is not reloaded between requests.
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Eager load code on boot. This eager loads most of Rails and
|
10
|
+
# your application in memory, allowing both threaded web servers
|
11
|
+
# and those relying on copy on write to perform better.
|
12
|
+
# Rake tasks automatically ignore this option for performance.
|
13
|
+
config.eager_load = true
|
14
|
+
|
15
|
+
# Full error reports are disabled and caching is turned on.
|
16
|
+
config.consider_all_requests_local = false
|
17
|
+
|
18
|
+
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
19
|
+
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
|
20
|
+
# config.require_master_key = true
|
21
|
+
|
22
|
+
# Disable serving static files from the `/public` folder by default since
|
23
|
+
# Apache or NGINX already handles this.
|
24
|
+
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
|
25
|
+
|
26
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
27
|
+
# config.asset_host = "http://assets.example.com"
|
28
|
+
|
29
|
+
# Specifies the header that your server uses for sending files.
|
30
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
|
31
|
+
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
|
32
|
+
|
33
|
+
# Store uploaded files on the local file system (see config/storage.yml for options).
|
34
|
+
config.active_storage.service = :local
|
35
|
+
|
36
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
37
|
+
# config.force_ssl = true
|
38
|
+
|
39
|
+
# Include generic and useful information about system operation, but avoid logging too much
|
40
|
+
# information to avoid inadvertent exposure of personally identifiable information (PII).
|
41
|
+
config.log_level = :info
|
42
|
+
|
43
|
+
# Prepend all log lines with the following tags.
|
44
|
+
config.log_tags = [ :request_id ]
|
45
|
+
|
46
|
+
# Use a different cache store in production.
|
47
|
+
# config.cache_store = :mem_cache_store
|
48
|
+
|
49
|
+
# Use a real queuing backend for Active Job (and separate queues per environment).
|
50
|
+
# config.active_job.queue_adapter = :resque
|
51
|
+
# config.active_job.queue_name_prefix = "ranking_production"
|
52
|
+
|
53
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
54
|
+
# the I18n.default_locale when a translation cannot be found).
|
55
|
+
config.i18n.fallbacks = true
|
56
|
+
|
57
|
+
# Don't log any deprecations.
|
58
|
+
config.active_support.report_deprecations = false
|
59
|
+
|
60
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
61
|
+
config.log_formatter = ::Logger::Formatter.new
|
62
|
+
|
63
|
+
# Use a different logger for distributed setups.
|
64
|
+
# require "syslog/logger"
|
65
|
+
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
|
66
|
+
|
67
|
+
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
68
|
+
logger = ActiveSupport::Logger.new(STDOUT)
|
69
|
+
logger.formatter = config.log_formatter
|
70
|
+
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Do not dump schema after migrations.
|
74
|
+
config.active_record.dump_schema_after_migration = false
|
75
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "active_support/core_ext/integer/time"
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
|
8
|
+
Rails.application.configure do
|
9
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
10
|
+
|
11
|
+
# Turn false under Spring and add config.action_view.cache_template_loading = true.
|
12
|
+
config.cache_classes = true
|
13
|
+
|
14
|
+
# Eager loading loads your whole application. When running a single test locally,
|
15
|
+
# this probably isn't necessary. It's a good idea to do in a continuous integration
|
16
|
+
# system, or in some way before deploying your code.
|
17
|
+
config.eager_load = ENV["CI"].present?
|
18
|
+
|
19
|
+
# Configure public file server for tests with Cache-Control for performance.
|
20
|
+
config.public_file_server.enabled = true
|
21
|
+
config.public_file_server.headers = {
|
22
|
+
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
|
23
|
+
}
|
24
|
+
|
25
|
+
# Show full error reports and disable caching.
|
26
|
+
config.consider_all_requests_local = true
|
27
|
+
config.action_controller.perform_caching = false
|
28
|
+
config.cache_store = :null_store
|
29
|
+
|
30
|
+
# Raise exceptions instead of rendering exception templates.
|
31
|
+
config.action_dispatch.show_exceptions = false
|
32
|
+
|
33
|
+
# Disable request forgery protection in test environment.
|
34
|
+
config.action_controller.allow_forgery_protection = false
|
35
|
+
|
36
|
+
# Store uploaded files on the local file system in a temporary directory.
|
37
|
+
config.active_storage.service = :test
|
38
|
+
|
39
|
+
# Print deprecation notices to the stderr.
|
40
|
+
config.active_support.deprecation = :stderr
|
41
|
+
|
42
|
+
# Raise exceptions for disallowed deprecations.
|
43
|
+
config.active_support.disallowed_deprecation = :raise
|
44
|
+
|
45
|
+
# Tell Active Support which deprecation messages to disallow.
|
46
|
+
config.active_support.disallowed_deprecation_warnings = []
|
47
|
+
|
48
|
+
# Raises error for missing translations.
|
49
|
+
# config.i18n.raise_on_missing_translations = true
|
50
|
+
|
51
|
+
# Annotate rendered view with file names.
|
52
|
+
# config.action_view.annotate_rendered_view_with_filenames = true
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Avoid CORS issues when API is called from the frontend app.
|
4
|
+
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
|
5
|
+
|
6
|
+
# Read more: https://github.com/cyu/rack-cors
|
7
|
+
|
8
|
+
# Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
9
|
+
# allow do
|
10
|
+
# origins "example.com"
|
11
|
+
#
|
12
|
+
# resource "*",
|
13
|
+
# headers: :any,
|
14
|
+
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
|
15
|
+
# end
|
16
|
+
# end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Configure parameters to be filtered from the log file. Use this to limit dissemination of
|
4
|
+
# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
|
5
|
+
# notations and behaviors.
|
6
|
+
Rails.application.config.filter_parameters += [
|
7
|
+
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
|
8
|
+
]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, "\\1en"
|
8
|
+
# inflect.singular /^(ox)en/i, "\\1"
|
9
|
+
# inflect.irregular "person", "people"
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
# These inflection rules are supported but not enabled by default:
|
14
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
15
|
+
# inflect.acronym "RESTful"
|
16
|
+
# end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t "hello"
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t("hello") %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# The following keys must be escaped otherwise they will not be retrieved by
|
20
|
+
# the default I18n backend:
|
21
|
+
#
|
22
|
+
# true, false, on, off, yes, no
|
23
|
+
#
|
24
|
+
# Instead, surround them with single quotes.
|
25
|
+
#
|
26
|
+
# en:
|
27
|
+
# "true": "foo"
|
28
|
+
#
|
29
|
+
# To learn more, please read the Rails Internationalization guide
|
30
|
+
# available at https://guides.rubyonrails.org/i18n.html.
|
31
|
+
|
32
|
+
en:
|
33
|
+
hello: "Hello world"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Puma can serve each request in a thread from an internal thread pool.
|
2
|
+
# The `threads` method setting takes two numbers: a minimum and maximum.
|
3
|
+
# Any libraries that use thread pools should be configured to match
|
4
|
+
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
5
|
+
# and maximum; this matches the default thread size of Active Record.
|
6
|
+
#
|
7
|
+
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
|
8
|
+
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
|
9
|
+
threads min_threads_count, max_threads_count
|
10
|
+
|
11
|
+
# Specifies the `worker_timeout` threshold that Puma will use to wait before
|
12
|
+
# terminating a worker in development environments.
|
13
|
+
#
|
14
|
+
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
|
15
|
+
|
16
|
+
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
17
|
+
#
|
18
|
+
port ENV.fetch("PORT") { 3000 }
|
19
|
+
|
20
|
+
# Specifies the `environment` that Puma will run in.
|
21
|
+
#
|
22
|
+
environment ENV.fetch("RAILS_ENV") { "development" }
|
23
|
+
|
24
|
+
# Specifies the `pidfile` that Puma will use.
|
25
|
+
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
|
26
|
+
|
27
|
+
# Specifies the number of `workers` to boot in clustered mode.
|
28
|
+
# Workers are forked web server processes. If using threads and workers together
|
29
|
+
# the concurrency of the application would be max `threads` * `workers`.
|
30
|
+
# Workers do not work on JRuby or Windows (both of which do not support
|
31
|
+
# processes).
|
32
|
+
#
|
33
|
+
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
34
|
+
|
35
|
+
# Use the `preload_app!` method when specifying a `workers` number.
|
36
|
+
# This directive tells Puma to first boot the application and load code
|
37
|
+
# before forking the application. This takes advantage of Copy On Write
|
38
|
+
# process behavior so workers use less memory.
|
39
|
+
#
|
40
|
+
# preload_app!
|
41
|
+
|
42
|
+
# Allow puma to be restarted by `bin/rails restart` command.
|
43
|
+
plugin :tmp_restart
|
@@ -0,0 +1,34 @@
|
|
1
|
+
test:
|
2
|
+
service: Disk
|
3
|
+
root: <%= Rails.root.join("tmp/storage") %>
|
4
|
+
|
5
|
+
local:
|
6
|
+
service: Disk
|
7
|
+
root: <%= Rails.root.join("storage") %>
|
8
|
+
|
9
|
+
# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
|
10
|
+
# amazon:
|
11
|
+
# service: S3
|
12
|
+
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
|
13
|
+
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
|
14
|
+
# region: us-east-1
|
15
|
+
# bucket: your_own_bucket-<%= Rails.env %>
|
16
|
+
|
17
|
+
# Remember not to checkin your GCS keyfile to a repository
|
18
|
+
# google:
|
19
|
+
# service: GCS
|
20
|
+
# project: your_project
|
21
|
+
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
|
22
|
+
# bucket: your_own_bucket-<%= Rails.env %>
|
23
|
+
|
24
|
+
# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
|
25
|
+
# microsoft:
|
26
|
+
# service: AzureStorage
|
27
|
+
# storage_account_name: your_account_name
|
28
|
+
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
|
29
|
+
# container: your_container_name-<%= Rails.env %>
|
30
|
+
|
31
|
+
# mirror:
|
32
|
+
# service: Mirror
|
33
|
+
# primary: local
|
34
|
+
# mirrors: [ amazon, google, microsoft ]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreatePlays < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
enable_extension("timescaledb") unless extensions.include? "timescaledb"
|
4
|
+
hypertable_options = {
|
5
|
+
time_column: 'created_at',
|
6
|
+
chunk_time_interval: '1 day',
|
7
|
+
compress_segmentby: 'game_id',
|
8
|
+
compress_orderby: 'created_at',
|
9
|
+
compression_interval: '7 days'
|
10
|
+
}
|
11
|
+
create_table :plays, hypertable: hypertable_options, id: false do |t|
|
12
|
+
t.references :game, null: false, foreign_key: false
|
13
|
+
t.integer :score
|
14
|
+
t.decimal :total_time
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema[7.0].define(version: 2022_02_09_143347) do
|
14
|
+
# These are extensions that must be enabled in order to support this database
|
15
|
+
enable_extension "plpgsql"
|
16
|
+
enable_extension "timescaledb"
|
17
|
+
|
18
|
+
create_table "games", force: :cascade do |t|
|
19
|
+
t.string "name"
|
20
|
+
t.string "description"
|
21
|
+
t.datetime "created_at", null: false
|
22
|
+
t.datetime "updated_at", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table "plays", id: false, force: :cascade do |t|
|
26
|
+
t.bigint "game_id", null: false
|
27
|
+
t.integer "score"
|
28
|
+
t.decimal "total_time"
|
29
|
+
t.datetime "created_at", null: false
|
30
|
+
t.datetime "updated_at", null: false
|
31
|
+
t.index ["created_at"], name: "plays_created_at_idx", order: :desc
|
32
|
+
t.index ["game_id"], name: "index_plays_on_game_id"
|
33
|
+
end
|
34
|
+
|
35
|
+
create_hypertable "plays", time_column: "created_at", chunk_time_interval: "1 minute", compress_segmentby: "game_id", compress_orderby: "created_at ASC", compression_interval: "P7D"
|
36
|
+
|
37
|
+
create_continuous_aggregate("score_per_hours", <<-SQL)
|
38
|
+
SELECT plays.game_id,
|
39
|
+
time_bucket('PT1H'::interval, plays.created_at) AS bucket,
|
40
|
+
avg(plays.score) AS avg,
|
41
|
+
max(plays.score) AS max,
|
42
|
+
min(plays.score) AS min
|
43
|
+
FROM plays
|
44
|
+
GROUP BY plays.game_id, (time_bucket('PT1H'::interval, plays.created_at))
|
45
|
+
SQL
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
|
7
|
+
# Character.create(name: "Luke", movie: movies.first)
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module Timescaledb
|
4
4
|
# If you want your model to hook into its underlying hypertable
|
5
5
|
# as well as have access to TimescaleDB specific data, methods, and more,
|
6
6
|
# specify this macro in your model.
|
@@ -10,7 +10,7 @@ module Timescale
|
|
10
10
|
#
|
11
11
|
# @see https://docs.timescale.com/api/latest/hypertable/create_hypertable/ for
|
12
12
|
# how to use the SQL `create_hypertable` function.
|
13
|
-
# @see
|
13
|
+
# @see Timescaledb::MigrationHelpers#create_table for how to create a new hypertable
|
14
14
|
# via a Rails migration utilizing the standard `create_table` method.
|
15
15
|
#
|
16
16
|
# @example Enabling the macro on your model
|
@@ -18,7 +18,7 @@ module Timescale
|
|
18
18
|
# acts_as_hypertable
|
19
19
|
# end
|
20
20
|
#
|
21
|
-
# @see
|
21
|
+
# @see Timescaledb::ActsAsHypertable#acts_as_hypertable
|
22
22
|
# for configuration options
|
23
23
|
module ActsAsHypertable
|
24
24
|
DEFAULT_OPTIONS = {
|
@@ -26,7 +26,7 @@ module Timescale
|
|
26
26
|
}.freeze
|
27
27
|
|
28
28
|
def acts_as_hypertable?
|
29
|
-
included_modules.include?(
|
29
|
+
included_modules.include?(Timescaledb::ActsAsHypertable::Core)
|
30
30
|
end
|
31
31
|
|
32
32
|
# == Configuration options
|
@@ -45,7 +45,7 @@ module Timescale
|
|
45
45
|
def acts_as_hypertable(options = {})
|
46
46
|
return if acts_as_hypertable?
|
47
47
|
|
48
|
-
include
|
48
|
+
include Timescaledb::ActsAsHypertable::Core
|
49
49
|
|
50
50
|
class_attribute :hypertable_options, instance_writer: false
|
51
51
|
|
@@ -59,4 +59,4 @@ module Timescale
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
ActiveRecord::Base.extend
|
62
|
+
ActiveRecord::Base.extend Timescaledb::ActsAsHypertable
|
@@ -1,6 +1,7 @@
|
|
1
|
-
module
|
2
|
-
class
|
1
|
+
module Timescaledb
|
2
|
+
class CompressionSetting < ActiveRecord::Base
|
3
3
|
self.table_name = "timescaledb_information.compression_settings"
|
4
4
|
belongs_to :hypertable, foreign_key: :hypertable_name
|
5
5
|
end
|
6
|
+
CompressionSettings = CompressionSetting
|
6
7
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module
|
2
|
-
class
|
1
|
+
module Timescaledb
|
2
|
+
class ContinuousAggregate < ActiveRecord::Base
|
3
3
|
self.table_name = "timescaledb_information.continuous_aggregates"
|
4
4
|
self.primary_key = 'materialization_hypertable_name'
|
5
5
|
|
6
6
|
has_many :jobs, foreign_key: "hypertable_name",
|
7
|
-
class_name: "
|
7
|
+
class_name: "Timescaledb::Job"
|
8
8
|
|
9
9
|
has_many :chunks, foreign_key: "hypertable_name",
|
10
|
-
class_name: "
|
10
|
+
class_name: "Timescaledb::Chunk"
|
11
11
|
|
12
12
|
scope :resume, -> do
|
13
13
|
{
|
@@ -15,4 +15,5 @@ module Timescale
|
|
15
15
|
}
|
16
16
|
end
|
17
17
|
end
|
18
|
+
ContinuousAggregates = ContinuousAggregate
|
18
19
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Timescaledb
|
2
2
|
class Hypertable < ActiveRecord::Base
|
3
3
|
self.table_name = "timescaledb_information.hypertables"
|
4
4
|
self.primary_key = "hypertable_name"
|
@@ -6,17 +6,17 @@ module Timescale
|
|
6
6
|
has_many :jobs, foreign_key: "hypertable_name"
|
7
7
|
has_many :chunks, foreign_key: "hypertable_name"
|
8
8
|
|
9
|
-
|
9
|
+
has_many :compression_settings,
|
10
10
|
foreign_key: "hypertable_name",
|
11
|
-
class_name: "
|
11
|
+
class_name: "Timescaledb::CompressionSetting"
|
12
12
|
|
13
13
|
has_one :dimensions,
|
14
14
|
foreign_key: "hypertable_name",
|
15
|
-
class_name: "
|
15
|
+
class_name: "Timescaledb::Dimension"
|
16
16
|
|
17
17
|
has_many :continuous_aggregates,
|
18
18
|
foreign_key: "hypertable_name",
|
19
|
-
class_name: "
|
19
|
+
class_name: "Timescaledb::ContinuousAggregate"
|
20
20
|
|
21
21
|
def chunks_detailed_size
|
22
22
|
struct_from "SELECT * from chunks_detailed_size('#{self.hypertable_name}')"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Timescaledb
|
2
|
+
class Job < ActiveRecord::Base
|
3
|
+
self.table_name = "timescaledb_information.jobs"
|
4
|
+
self.primary_key = "job_id"
|
5
|
+
|
6
|
+
scope :compression, -> { where(proc_name: [:tsbs_compress_chunks, :policy_compression]) }
|
7
|
+
scope :refresh_continuous_aggregate, -> { where(proc_name: :policy_refresh_continuous_aggregate) }
|
8
|
+
scope :scheduled, -> { where(scheduled: true) }
|
9
|
+
end
|
10
|
+
end
|