Module: Timescaledb::SchemaDumper

Defined in:
lib/timescaledb/schema_dumper.rb

Overview

Schema dumper overrides default schema dumper to include:

  • hypertables

  • retention policies

  • continuous aggregates

  • compression settings

It also ignores Timescale related schemas when dumping the schema. It also ignores dumping options as extension is not installed or no hypertables are available.

Constant Summary collapse

IGNORE_SCHEMAS =

Ignores Timescale related schemas when dumping the schema

%w[
  _timescaledb_cache
  _timescaledb_config
  _timescaledb_catalog
  _timescaledb_debug
  _timescaledb_functions
  _timescaledb_internal
  timescaledb_experimental
  timescaledb_information
  toolkit_experimental
]

Instance Method Summary collapse

Instance Method Details

#schemas(stream) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/timescaledb/schema_dumper.rb', line 48

def schemas(stream)
  schema_names = @connection.schema_names - ["public", *IGNORE_SCHEMAS]
  if schema_names.any?
    schema_names.sort.each do |name|
      stream.puts "  create_schema #{name.inspect}"
    end
    stream.puts
  end
end

#tables(stream) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/timescaledb/schema_dumper.rb', line 13

def tables(stream)
  super # This will call #table for each table in the database

  if exports_timescaledb_metadata?
    timescale_hypertables(stream)
    timescale_retention_policies(stream)
    timescale_continuous_aggregates(stream) # Define these before any Scenic views that might use them
  end
end

#timescale_hypertables(stream) ⇒ Object



58
59
60
61
62
# File 'lib/timescaledb/schema_dumper.rb', line 58

def timescale_hypertables(stream)
  sorted_hypertables.each do |hypertable|
    timescale_hypertable(hypertable, stream)
  end
end

#timescale_retention_policies(stream) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/timescaledb/schema_dumper.rb', line 64

def timescale_retention_policies(stream)
  if sorted_hypertables.any? { |hypertable| hypertable.jobs.exists?(proc_name: "policy_retention") }
    stream.puts # Insert a blank line above the retention policies, for readability
  end

  sorted_hypertables.each do |hypertable|
    timescale_retention_policy(hypertable, stream)
  end
end