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.



203
204
205
# File 'lib/sequel/adapters/shared/postgres.rb', line 203

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

Instance Method Details

#default ⇒ Object

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



248
249
250
# File 'lib/sequel/adapters/shared/postgres.rb', line 248

def default
  @default = true
end

#from(*v) ⇒ Object

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



221
222
223
# File 'lib/sequel/adapters/shared/postgres.rb', line 221

def from(*v)
  @from = v
end

#hash_values ⇒ Object

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



263
264
265
# File 'lib/sequel/adapters/shared/postgres.rb', line 263

def hash_values
  [@modulus, @remainder]
end

#list ⇒ Object

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



258
259
260
# File 'lib/sequel/adapters/shared/postgres.rb', line 258

def list
  @in
end

#maxvalue ⇒ Object

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



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

def maxvalue
  MAXVALUE
end

#minvalue ⇒ Object

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



209
210
211
# File 'lib/sequel/adapters/shared/postgres.rb', line 209

def minvalue
  MINVALUE
end

#modulus(v) ⇒ Object

Assumes hash partitioning, sets the modulus for this partition.



237
238
239
# File 'lib/sequel/adapters/shared/postgres.rb', line 237

def modulus(v)
  @modulus = v
end

#partition_type ⇒ Object

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

Raises:



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/sequel/adapters/shared/postgres.rb', line 269

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

#range ⇒ Object

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



253
254
255
# File 'lib/sequel/adapters/shared/postgres.rb', line 253

def range
  [@from, @to]
end

#remainder(v) ⇒ Object

Assumes hash partitioning, sets the remainder for this partition.



242
243
244
# File 'lib/sequel/adapters/shared/postgres.rb', line 242

def remainder(v)
  @remainder = v
end

#to(*v) ⇒ Object

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



227
228
229
# File 'lib/sequel/adapters/shared/postgres.rb', line 227

def to(*v)
  @to = v
end

#values_in(*v) ⇒ Object

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



232
233
234
# File 'lib/sequel/adapters/shared/postgres.rb', line 232

def values_in(*v)
  @in = v
end