Class: Sequel::Postgres::CreatePartitionOfTableGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/adapters/shared/postgres.rb

Overview

Generator used for creating tables that are partitions of other tables.

Constant Summary collapse

MINVALUE =
Sequel.lit('MINVALUE').freeze
MAXVALUE =
Sequel.lit('MAXVALUE').freeze

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ CreatePartitionOfTableGenerator

Returns a new instance of CreatePartitionOfTableGenerator.



156
157
158
# File 'lib/sequel/adapters/shared/postgres.rb', line 156

def initialize(&block)
  instance_exec(&block)
end

Instance Method Details

#defaultObject

Sets that this is a default partition, where values not in other partitions are stored.



201
202
203
# File 'lib/sequel/adapters/shared/postgres.rb', line 201

def default
  @default = true
end

#from(*v) ⇒ Object

Assumes range partitioning, sets the inclusive minimum value of the range for this partition.



174
175
176
# File 'lib/sequel/adapters/shared/postgres.rb', line 174

def from(*v)
  @from = v
end

#hash_valuesObject

The modulus and remainder to use for this partition for a hash partition.



216
217
218
# File 'lib/sequel/adapters/shared/postgres.rb', line 216

def hash_values
  [@modulus, @remainder]
end

#listObject

The values to include in this partition for a list partition.



211
212
213
# File 'lib/sequel/adapters/shared/postgres.rb', line 211

def list
  @in
end

#maxvalueObject

The minimum value of the data type used in range partitions, useful as an argument to #to.



168
169
170
# File 'lib/sequel/adapters/shared/postgres.rb', line 168

def maxvalue
  MAXVALUE
end

#minvalueObject

The minimum value of the data type used in range partitions, useful as an argument to #from.



162
163
164
# File 'lib/sequel/adapters/shared/postgres.rb', line 162

def minvalue
  MINVALUE
end

#modulus(v) ⇒ Object

Assumes hash partitioning, sets the modulus for this parition.



190
191
192
# File 'lib/sequel/adapters/shared/postgres.rb', line 190

def modulus(v)
  @modulus = v
end

#partition_typeObject

Determine the appropriate partition type for this partition by which methods were called on it.

Raises:



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/sequel/adapters/shared/postgres.rb', line 222

def partition_type
  raise Error, "Unable to determine partition type, multiple different partitioning methods called" if [@from || @to, @list, @modulus || @remainder, @default].compact.length > 1

  if @from || @to
    raise Error, "must call both from and to when creating a partition of a table if calling either" unless @from && @to
    :range
  elsif @in
    :list
  elsif @modulus || @remainder
    raise Error, "must call both modulus and remainder when creating a partition of a table if calling either" unless @modulus && @remainder
    :hash
  elsif @default
    :default
  else
    raise Error, "unable to determine partition type, no partitioning methods called"
  end
end

#rangeObject

The from and to values of this partition for a range partition.



206
207
208
# File 'lib/sequel/adapters/shared/postgres.rb', line 206

def range
  [@from, @to]
end

#remainder(v) ⇒ Object

Assumes hash partitioning, sets the remainder for this parition.



195
196
197
# File 'lib/sequel/adapters/shared/postgres.rb', line 195

def remainder(v)
  @remainder = v
end

#to(*v) ⇒ Object

Assumes range partitioning, sets the exclusive maximum value of the range for this partition.



180
181
182
# File 'lib/sequel/adapters/shared/postgres.rb', line 180

def to(*v)
  @to = v
end

#values_in(*v) ⇒ Object

Assumes list partitioning, sets the values to be included in this partition.



185
186
187
# File 'lib/sequel/adapters/shared/postgres.rb', line 185

def values_in(*v)
  @in = v
end