require_relative 'Table.rb' require_relative 'CachingTable.rb' module Timeseries module Hoarder class SeriesTable < Table def initialize(db, name, **opts) @chunk_time = opts[:chunk_time] || '3h' @compress_chunk_time = opts[:compress_chunk_time] || '24h' @name = name @tags = CachingTable.new(db, name + '_tags') super(db, name, 'ts_hoarder') end def table_creation @pg.exec("CREATE TABLE #{@table_id} ( time TIMESTAMPTZ NOT NULL, source_id INTEGER NOT NULL, tags_id INTEGER NOT NULL, value DOUBLE PRECISION NOT NULL)") @pg.exec_params("SELECT create_hypertable('#{@table_schema}.#{@table_name}', 'time', chunk_time_interval => $1::interval)", [@chunk_time]) @pg.exec_params("ALTER TABLE #{@table_id} SET (timescaledb.compress, timescaledb.compress_segmentby = 'source_id, tags_id', timescaledb.compress_chunk_time_interval='#{@compress_chunk_time}')") view_sql = <