Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/partitioning/single_numeric_list_partition.rb')
-rw-r--r--lib/gitlab/database/partitioning/single_numeric_list_partition.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/gitlab/database/partitioning/single_numeric_list_partition.rb b/lib/gitlab/database/partitioning/single_numeric_list_partition.rb
index 23ac73a0e53..4e38eea963b 100644
--- a/lib/gitlab/database/partitioning/single_numeric_list_partition.rb
+++ b/lib/gitlab/database/partitioning/single_numeric_list_partition.rb
@@ -8,7 +8,7 @@ module Gitlab
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+)'\)/)
+ matches = definition.match(/FOR VALUES IN \('?(?<value>\d+)'?\)/)
raise ArgumentError, 'Unknown partition definition' unless matches
@@ -29,17 +29,21 @@ module Gitlab
@partition_name || "#{table}_#{value}"
end
+ def data_size
+ execute("SELECT pg_table_size(#{quote(full_partition_name)})").first['pg_table_size']
+ end
+
def to_sql
<<~SQL
CREATE TABLE IF NOT EXISTS #{fully_qualified_partition}
- PARTITION OF #{conn.quote_table_name(table)}
- FOR VALUES IN (#{conn.quote(value)})
+ PARTITION OF #{quote_table_name(table)}
+ FOR VALUES IN (#{quote(value)})
SQL
end
def to_detach_sql
<<~SQL
- ALTER TABLE #{conn.quote_table_name(table)}
+ ALTER TABLE #{quote_table_name(table)}
DETACH PARTITION #{fully_qualified_partition}
SQL
end
@@ -63,8 +67,14 @@ module Gitlab
private
+ delegate :execute, :quote, :quote_table_name, to: :conn, private: true
+
+ def full_partition_name
+ "%s.%s" % [Gitlab::Database::DYNAMIC_PARTITIONS_SCHEMA, partition_name]
+ end
+
def fully_qualified_partition
- "%s.%s" % [conn.quote_table_name(Gitlab::Database::DYNAMIC_PARTITIONS_SCHEMA), conn.quote_table_name(partition_name)]
+ quote_table_name(full_partition_name)
end
def conn