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

schema_cleaner.rb « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c415287878a412e3e1b244bb188bff7fc997132 (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
33
34
35
36
# 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
        structure.gsub!(/^COMMENT ON EXTENSION.*/, '')
        structure.gsub!(/^SET.+/, '')
        structure.gsub!(/^SELECT pg_catalog\.set_config\('search_path'.+/, '')
        structure.gsub!(/^--.*/, "\n")

        structure = "SET search_path=public;\n" + structure

        structure.gsub!(/\n{3,}/, "\n\n")

        io << structure
        io << <<~MSG
          -- schema_migrations.version information is no longer stored in this file,
          -- but instead tracked in the db/schema_migrations directory
          -- see https://gitlab.com/gitlab-org/gitlab/-/issues/218590 for details
        MSG

        nil
      end
    end
  end
end