2020-04-22 19:07:51 +05:30
|
|
|
# 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-23 00:09:42 +05:30
|
|
|
structure.gsub!(/^COMMENT ON EXTENSION.*/, '')
|
2020-04-22 19:07:51 +05:30
|
|
|
structure.gsub!(/^SET.+/, '')
|
|
|
|
structure.gsub!(/^SELECT pg_catalog\.set_config\('search_path'.+/, '')
|
|
|
|
structure.gsub!(/^--.*/, "\n")
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
structure = "SET search_path=public;\n" + structure
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
structure.gsub!(/\n{3,}/, "\n\n")
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
io << structure
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|