Class: Gitlab::Database::Partitioning::SingleNumericListPartition
- Inherits:
-
Object
- Object
- Gitlab::Database::Partitioning::SingleNumericListPartition
- Includes:
- Comparable
- Defined in:
- lib/gitlab/database/partitioning/single_numeric_list_partition.rb
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #data_size ⇒ Object
- #hash ⇒ Object
-
#initialize(table, value, partition_name: nil) ⇒ SingleNumericListPartition
constructor
A new instance of SingleNumericListPartition.
- #partition_name ⇒ Object
- #to_detach_sql ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(table, value, partition_name: nil) ⇒ SingleNumericListPartition
Returns a new instance of SingleNumericListPartition.
22 23 24 25 26 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 22 def initialize(table, value, partition_name: nil) @table = table @value = value @partition_name = partition_name end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
20 21 22 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 20 def table @table end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 20 def value @value end |
Class Method Details
.from_sql(table, partition_name, definition) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 9 def self.from_sql(table, partition_name, definition) # A list partition can support multiple values, but we only support a single number matches = definition.match(/FOR VALUES IN \('?(?<value>\d+)'?\)/) raise ArgumentError, 'Unknown partition definition' unless matches value = Integer(matches[:value]) new(table, value, partition_name: partition_name) end |
Instance Method Details
#<=>(other) ⇒ Object
62 63 64 65 66 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 62 def <=>(other) return if table != other.table value <=> other.value end |
#==(other) ⇒ Object Also known as: eql?
51 52 53 54 55 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 51 def ==(other) table == other.table && partition_name == other.partition_name && value == other.value end |
#data_size ⇒ Object
32 33 34 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 32 def data_size execute("SELECT pg_table_size(#{quote(full_partition_name)})").first['pg_table_size'] end |
#hash ⇒ Object
58 59 60 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 58 def hash [table, partition_name, value].hash end |
#partition_name ⇒ Object
28 29 30 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 28 def partition_name @partition_name || "#{table}_#{value}" end |
#to_detach_sql ⇒ Object
44 45 46 47 48 49 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 44 def to_detach_sql <<~SQL ALTER TABLE #{quote_table_name(table)} DETACH PARTITION #{fully_qualified_partition} SQL end |
#to_sql ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb', line 36 def to_sql <<~SQL CREATE TABLE IF NOT EXISTS #{fully_qualified_partition} PARTITION OF #{quote_table_name(table)} FOR VALUES IN (#{quote(value)}) SQL end |