Class: Gitlab::Database::SchemaCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/schema_cleaner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_schema) ⇒ SchemaCleaner

Returns a new instance of SchemaCleaner.


8
9
10
# File 'lib/gitlab/database/schema_cleaner.rb', line 8

def initialize(original_schema)
  @original_schema = original_schema
end

Instance Attribute Details

#original_schemaObject (readonly)

Returns the value of attribute original_schema


6
7
8
# File 'lib/gitlab/database/schema_cleaner.rb', line 6

def original_schema
  @original_schema
end

Instance Method Details

#clean(io) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/database/schema_cleaner.rb', line 12

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