Class: SwitchDb::Command::Restore

Inherits:
Base
  • Object
show all
Defined in:
lib/switch_db/command/restore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SwitchDb::Command::Base

Instance Attribute Details

#referenceObject (readonly)

Returns the value of attribute reference.



4
5
6
# File 'lib/switch_db/command/restore.rb', line 4

def reference
  @reference
end

Instance Method Details

#run(name:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/switch_db/command/restore.rb', line 6

def run(name:, **)
  reference = @reference_set.references[name.to_s]

  unless reference
    $stderr.puts("#{name} not exists")
    exit
  end

  database = SwitchDb::Database.current_database

  threads = reference.database_paths.map do |database_name, database_path|
    Thread.new do
      database.drop_database(database_name)
      database.create_database(database_name)
      database.import_database(database_name, database_path)
      puts "Restored database a '#{database_name}'"
    end
  end

  threads.each(&:join)
end