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/async_indexes/postgres_async_index.rb')
-rw-r--r--lib/gitlab/database/async_indexes/postgres_async_index.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/gitlab/database/async_indexes/postgres_async_index.rb b/lib/gitlab/database/async_indexes/postgres_async_index.rb
index 9f5f39613ed..a3c600a4519 100644
--- a/lib/gitlab/database/async_indexes/postgres_async_index.rb
+++ b/lib/gitlab/database/async_indexes/postgres_async_index.rb
@@ -8,13 +8,17 @@ module Gitlab
self.table_name = 'postgres_async_indexes'
+ # schema_name + . + table_name
+ MAX_TABLE_NAME_LENGTH = (Gitlab::Database::MigrationHelpers::MAX_IDENTIFIER_NAME_LENGTH * 2) + 1
MAX_IDENTIFIER_LENGTH = Gitlab::Database::MigrationHelpers::MAX_IDENTIFIER_NAME_LENGTH
MAX_DEFINITION_LENGTH = 2048
validates :name, presence: true, length: { maximum: MAX_IDENTIFIER_LENGTH }
- validates :table_name, presence: true, length: { maximum: MAX_IDENTIFIER_LENGTH }
+ validates :table_name, presence: true, length: { maximum: MAX_TABLE_NAME_LENGTH }
validates :definition, presence: true, length: { maximum: MAX_DEFINITION_LENGTH }
+ validate :ensure_correct_schema_and_table_name
+
scope :to_create, -> { where("definition ILIKE 'CREATE%'") }
scope :to_drop, -> { where("definition ILIKE 'DROP%'") }
scope :ordered, -> { order(attempts: :asc, id: :asc) }
@@ -22,6 +26,24 @@ module Gitlab
def to_s
definition
end
+
+ private
+
+ def ensure_correct_schema_and_table_name
+ return unless table_name
+
+ schema, table, *rest = table_name.split('.')
+
+ too_long = (table.nil? && schema.length > MAX_DEFINITION_LENGTH) || # no schema given
+ # both schema and table given
+ (schema.length > MAX_IDENTIFIER_LENGTH || (table && table.length > MAX_IDENTIFIER_LENGTH))
+
+ if too_long
+ errors.add(:table_name, :too_long)
+ elsif rest.any?
+ errors.add(:table_name, :invalid)
+ end
+ end
end
end
end