Sha256: 5c153505f5ad99f1220edcc4397ea43bad432c9751b253610ad271729fb2b8e3

Contents?: true

Size: 772 Bytes

Versions: 17

Compression:

Stored size: 772 Bytes

Contents

require 'ghost_adapter/command'

module GhostAdapter
  class MigrationError < StandardError
    def initialize(exit_code)
      super("gh-ost migration failed. exit code: #{exit_code}")
    end
  end

  class Migrator
    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
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ghost_adapter-0.7.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.6.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.5.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.4.2 lib/ghost_adapter/migrator.rb
ghost_adapter-0.4.1 lib/ghost_adapter/migrator.rb
ghost_adapter-0.4.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.3.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.2.3 lib/ghost_adapter/migrator.rb
ghost_adapter-0.2.2 lib/ghost_adapter/migrator.rb
ghost_adapter-0.2.1 lib/ghost_adapter/migrator.rb
ghost_adapter-0.2.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.1.4 lib/ghost_adapter/migrator.rb
ghost_adapter-0.1.3 lib/ghost_adapter/migrator.rb
ghost_adapter-0.1.2 lib/ghost_adapter/migrator.rb
ghost_adapter-0.1.1 lib/ghost_adapter/migrator.rb
ghost_adapter-0.1.0 lib/ghost_adapter/migrator.rb
ghost_adapter-0.0.2 lib/ghost_adapter/migrator.rb