Class: GhostAdapter::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/ghost_adapter/migrator.rb

Class Method Summary collapse

Class Method Details

.execute(table, query, database, dry_run) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ghost_adapter/migrator.rb', line 11

def self.execute(table, query, database, dry_run)
  command = GhostAdapter::Command.new(
    alter: query, table: table, database: database, dry_run: dry_run
  )
  Open3.popen2e(*command.to_a) do |_stdin, stdout_stderr, wait_thread|
    stdout_stderr.each_line do |line|
      puts "[gh-ost]:\t\t#{line}"
    end

    raise MigrationError, wait_thread.value.exitstatus unless wait_thread.value.success?
  end
  # A little buffer time in case of consecutive alter table commands
  sleep 5
end