Implement methods for .sql validation source

What does this MR do and why?

Previously you could only run the schema validation checker diff against a structure.sql and an actual database, but it is useful to run a diff between two different SQL files. Previously this did not work because the methods implemented by the database source (such as fetch_index_by_name) did not exist.

This commit adds those methods and refactors the existing methods to use them.

How to set up and validate locally

On macOS, I needed !195581 (merged) to build a more recent version of pg_query.

Attached are two .sql files:

17.9.3.sql

mysql-17.9.2.sql

I was able to generate a diff via:

require 'gitlab/schema/validation'

good_sql = Gitlab::Schema::Validation::Sources::StructureSql.new('17.9.3.sql')
bad_sql = Gitlab::Schema::Validation::Sources::StructureSql.new('mysql-17.9.2.sql')
validators = Gitlab::Schema::Validation::Validators::Base.all_validators

inconsistencies =
  Gitlab::Schema::Validation::Runner.new(good_sql, bad_sql, validators: validators).execute

inconsistencies.each do |inconsistency|
  puts inconsistency.display
end

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Stan Hu

Merge request reports

Loading