Class: Redcord::Migration::Migrator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/redcord/migration/migrator.rb

Class Method Summary collapse

Class Method Details

.migrate(redis:, version:, direction:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redcord/migration/migrator.rb', line 14

def self.migrate(redis:, version:, direction:)
  migration = load_version(version)
  print [
    T.must("#{redis.inspect.match('(redis://.*)>')[1]}"[0...30]),
    direction.to_s.upcase,
    version,
    T.must(migration.name).underscore.humanize,
  ].map { |str| str.ljust(30) }.join("\t")

  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  migration.new(redis).send(direction)
  if direction == :up
    redis.sadd(
      Redcord::Migration::Version::MIGRATION_VERSIONS_REDIS_KEY,
      version,
    )
  else
    redis.srem(
      Redcord::Migration::Version::MIGRATION_VERSIONS_REDIS_KEY,
      version,
    )
  end
  end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  puts "\t#{(end_time - start_time) * 1000.0.round(3)} ms"
end

.need_to_migrate?(redis) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/redcord/migration/migrator.rb', line 7

def self.need_to_migrate?(redis)
  local_version = Redcord::Migration::Version.new
  remote_version = Redcord::Migration::Version.new(redis: redis)
  !(local_version.all - remote_version.all).empty?
end