Class: Gitlab::Database::SchemaMigrations::Migrations

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

Constant Summary collapse

MIGRATION_VERSION_GLOB =
'20[0-9][0-9]*'

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Migrations

Returns a new instance of Migrations.


9
10
11
# File 'lib/gitlab/database/schema_migrations/migrations.rb', line 9

def initialize(context)
  @context = context
end

Instance Method Details

#load_allObject


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/database/schema_migrations/migrations.rb', line 28

def load_all
  return if version_filenames.empty?

  values = version_filenames.map { |vf| "('#{@context.connection.quote_string(vf)}')" }

  @context.connection.execute(<<~SQL)
  INSERT INTO schema_migrations (version)
  VALUES #{values.join(',')}
  ON CONFLICT DO NOTHING
  SQL
end

#touch_allObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/database/schema_migrations/migrations.rb', line 13

def touch_all
  return unless @context.versions_to_create.any?

  version_filepaths = version_filenames.map { |f| File.join(schema_directory, f) }
  FileUtils.rm(version_filepaths)

  @context.versions_to_create.each do |version|
    version_filepath = File.join(schema_directory, version)

    File.open(version_filepath, 'w') do |file|
      file << Digest::SHA256.hexdigest(version)
    end
  end
end