Class: CapistranoSyncTask::Db

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/capistrano-sync/sync.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#_capture, #check_deps, #get_ssh_command, #log

Constructor Details

#initialize(cap, rails_env, local_rails_env, tables) ⇒ Db

Returns a new instance of Db.



43
44
45
46
47
48
# File 'lib/capistrano-sync/sync.rb', line 43

def initialize(cap, rails_env, local_rails_env, tables)
  self.rails_env = rails_env
  self.local_rails_env = local_rails_env
  self.tables = tables
  self.cap = cap
end

Instance Attribute Details

#capObject

Returns the value of attribute cap.



41
42
43
# File 'lib/capistrano-sync/sync.rb', line 41

def cap
  @cap
end

#local_rails_envObject

Returns the value of attribute local_rails_env.



41
42
43
# File 'lib/capistrano-sync/sync.rb', line 41

def local_rails_env
  @local_rails_env
end

#rails_envObject

Returns the value of attribute rails_env.



41
42
43
# File 'lib/capistrano-sync/sync.rb', line 41

def rails_env
  @rails_env
end

#tablesObject

Returns the value of attribute tables.



41
42
43
# File 'lib/capistrano-sync/sync.rb', line 41

def tables
  @tables
end

Instance Method Details

#syncObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/capistrano-sync/sync.rb', line 50

def sync
  check_deps
  remote_config = remote_database_config
  local_config  = local_database_config

  dump_method = remote_config[:adapter] + "_dump"
  load_method = local_config[:adapter] + "_load"
  unless self.private_methods.include?(dump_method)
    puts "FATAL: Can't dump: unknown adapter #{remote_config[:adapter].inspect}"
    exit(1)
  end
  unless self.private_methods.include?(load_method)
    puts "FATAL: Can't load: unknown adapter #{local_config[:adapter].inspect}"
    exit(1)
  end

  dump_command    = __send__(dump_method, remote_config)
  load_command    = __send__(load_method, local_config)
  ssh_cmd, server = get_ssh_command

  log "drop and create local database"
  drop_and_create_local_db
  log "dump from #{server} and load to local #{local_rails_env} db (see progress)"

  cmd = "#{ssh_cmd} #{dump_command} | pv | #{load_command}"
  system cmd
end