2020-03-22 15:09:49 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
|
|
|
class SchemaCleaner
|
|
|
|
attr_reader :original_schema
|
|
|
|
|
|
|
|
def initialize(original_schema)
|
|
|
|
@original_schema = original_schema
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean(io)
|
|
|
|
structure = original_schema.dup
|
|
|
|
|
|
|
|
# Remove noise
|
2020-06-05 09:08:05 +00:00
|
|
|
structure.gsub!(/^COMMENT ON EXTENSION.*/, '')
|
2020-03-22 15:09:49 +00:00
|
|
|
structure.gsub!(/^SET.+/, '')
|
|
|
|
structure.gsub!(/^SELECT pg_catalog\.set_config\('search_path'.+/, '')
|
|
|
|
structure.gsub!(/^--.*/, "\n")
|
|
|
|
|
2020-06-05 09:08:05 +00:00
|
|
|
structure = "SET search_path=public;\n" + structure
|
2020-03-22 15:09:49 +00:00
|
|
|
|
2020-06-05 09:08:05 +00:00
|
|
|
structure.gsub!(/\n{3,}/, "\n\n")
|
2020-03-22 15:09:49 +00:00
|
|
|
|
|
|
|
io << structure
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|