Class: ActiveRecord::Timescale::SchemaMigration::HyperTableOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/timescale/schema_migration.rb

Instance Method Summary collapse

Constructor Details

#initialize(partitioning_column: nil, number_partitions: nil, chunk_time_interval: "7 days", create_default_indexes: true, if_not_exists: false, partitioning_func: nil, associated_schema_name: "_timescaledb_internal", associated_table_prefix: "_hyper", migrate_data: false, time_partitioning_func: nil, replicator_factor: nil, data_nodes: [], distributed: nil, **other_args) ⇒ HyperTableOptions

Returns a new instance of HyperTableOptions.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/active_record/timescale/schema_migration.rb', line 74

def initialize(
  partitioning_column: nil,
  number_partitions: nil,
  chunk_time_interval: "7 days",
  create_default_indexes: true,
  if_not_exists: false,
  partitioning_func: nil,
  associated_schema_name: "_timescaledb_internal",
  associated_table_prefix: "_hyper",
  migrate_data: false,
  time_partitioning_func: nil,
  replicator_factor: nil,
  data_nodes: [],
  distributed: nil,
  **other_args
)

  @partitioning_column = partitioning_column
  @number_partitions = number_partitions
  @chunk_time_interval = chunk_time_interval
  @create_default_indexes = create_default_indexes
  @if_not_exists = if_not_exists
  @partitioning_func = partitioning_func
  @associated_schema_name = associated_schema_name
  @associated_table_prefix = associated_table_prefix
  @migrate_data = migrate_data
  @time_partitioning_func = time_partitioning_func
  @replicator_factor = replicator_factor
  @data_nodes = data_nodes
  @distributed = distributed
  @other_args = other_args
end

Instance Method Details

#argsObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/active_record/timescale/schema_migration.rb', line 107

def args
  @other_args.merge(
    {
      partitioning_column: @partitioning_column,
      number_partitions: @number_partitions,
      chunk_time_interval: @chunk_time_interval,
      create_default_indexes: @create_default_indexes,
      if_not_exists: @if_not_exists,
      partitioning_func: @partitioning_func,
      associated_schema_name: @associated_schema_name,
      associated_table_prefix: @associated_table_prefix,
      migrate_data: @migrate_data,
      time_partitioning_func: @time_partitioning_func,
      replicator_factor: @replicator_factor,
      data_nodes: @data_nodes,
      distributed: @distributed
    }
  )
end

#to_sqlObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/active_record/timescale/schema_migration.rb', line 127

def to_sql
  sql = []
  sql << "partitioning_column => '#{@partioning_column}'" unless @partitioning_column.nil?
  sql << "number_partitions => #{@number_partitions}" unless @number_partitions.nil?
  sql << "if_not_exists => #{@if_not_exists}"
  sql << "partitioning_func => '#{@partitioning_func}'" unless @partitioning_func.nil?
  sql << "associated_schema_name => '#{@associated_schema_name}'"
  sql << "associated_table_prefix => '#{@associated_table_prefix}'"
  sql << "migrate_data => #{@migrate_data}"
  sql << "time_partitioning_func => '#{@time_partitioning_func}'" unless @time_partitioning_func.nil?
  sql << "replicator_factor => #{@replicator_factor}" unless @replicator_factor.nil?
  sql << "data_nodes => '{ #{@data_nodes.join(", ")} }'" if @data_nodes.any?
  sql << "disstributed => #{@distributed}" unless @distributed.nil?
  sql <<
    if @chunk_time_interval.is_a? String
      "chunk_time_interval => INTERVAL '#{@chunk_time_interval}'"
    else
      "chunk_time_interval => #{@chunk_time_interval}"
    end

  sql.join(", ")
end