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

missing_table_columns.rb « validators « validation « schema « gitlab « lib « gitlab-schema-validation « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b441e196543476158ad86adfa64661731de2e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Gitlab
  module Schema
    module Validation
      module Validators
        class MissingTableColumns < Base
          ERROR_MESSAGE = "The table %s has columns missing from the database"

          def execute
            structure_sql.tables.filter_map do |structure_sql_table|
              table_name = structure_sql_table.name
              database_table = database.fetch_table_by_name(table_name)

              next unless database_table

              inconsistencies = structure_sql_table.columns.filter_map do |structure_table_column|
                next if database_table.column_exists?(structure_table_column.name)

                structure_table_column
              end

              if inconsistencies.any?
                build_inconsistency(self.class, nil, SchemaObjects::Table.new(table_name, inconsistencies))
              end
            end
          end
        end
      end
    end
  end
end