Class: Gitlab::Database::Migrations::BatchedMigrationLastId

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

Constant Summary collapse

FILE_NAME =
'last-batched-background-migration-id.txt'

Instance Method Summary collapse

Constructor Details

#initialize(connection, base_dir) ⇒ BatchedMigrationLastId

Returns a new instance of BatchedMigrationLastId.



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

def initialize(connection, base_dir)
  @connection = connection
  @base_dir = base_dir
end

Instance Method Details

#readInteger?

Reads the last id from the file

Examples:

Integer('4', exception: false) # => 4
Integer('', exception: false) # => nil

Returns:

  • (Integer, nil)


28
29
30
31
32
# File 'lib/gitlab/database/migrations/batched_migration_last_id.rb', line 28

def read
  return unless File.exist?(file_path)

  Integer(File.read(file_path).presence, exception: false)
end

#storeObject



14
15
16
# File 'lib/gitlab/database/migrations/batched_migration_last_id.rb', line 14

def store
  File.open(file_path, 'wb') { |file| file.write(last_background_migration_id) }
end