summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/schema_validation/indexes.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/schema_validation/indexes.rb')
-rw-r--r--lib/gitlab/database/schema_validation/indexes.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/database/schema_validation/indexes.rb b/lib/gitlab/database/schema_validation/indexes.rb
new file mode 100644
index 00000000000..b7c3705bde9
--- /dev/null
+++ b/lib/gitlab/database/schema_validation/indexes.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Database
+ module SchemaValidation
+ class Indexes
+ def initialize(structure_sql, database)
+ @structure_sql = structure_sql
+ @database = database
+ end
+
+ def missing_indexes
+ structure_sql.indexes.map(&:name) - database.indexes.map(&:name)
+ end
+
+ def extra_indexes
+ database.indexes.map(&:name) - structure_sql.indexes.map(&:name)
+ end
+
+ def wrong_indexes
+ structure_sql.indexes.filter_map do |structure_sql_index|
+ database_index = database.fetch_index_by_name(structure_sql_index.name)
+
+ next if database_index.nil?
+ next if database_index.statement == structure_sql_index.statement
+
+ structure_sql_index.name
+ end
+ end
+
+ private
+
+ attr_reader :structure_sql, :database
+ end
+ end
+ end
+end