Class: Veksel::Commands::Fork

Inherits:
Object
  • Object
show all
Defined in:
lib/veksel/commands/fork.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ Fork

Returns a new instance of Fork.



6
7
8
9
10
11
# File 'lib/veksel/commands/fork.rb', line 6

def initialize(db)
  @adapter = Veksel.adapter_for(db.configuration_hash)
  @source_db = adapter.main_database
  @target_db = adapter.db_name_for_suffix(Veksel.suffix)
  raise "Source and target databases cannot be the same" if source_db == target_db
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



4
5
6
# File 'lib/veksel/commands/fork.rb', line 4

def adapter
  @adapter
end

#source_dbObject (readonly)

Returns the value of attribute source_db.



4
5
6
# File 'lib/veksel/commands/fork.rb', line 4

def source_db
  @source_db
end

#target_dbObject (readonly)

Returns the value of attribute target_db.



4
5
6
# File 'lib/veksel/commands/fork.rb', line 4

def target_db
  @target_db
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
20
21
# File 'lib/veksel/commands/fork.rb', line 13

def perform
  return false unless adapter
  return false if adapter.target_populated?(target_db)

  adapter.kill_connection(source_db)
  adapter.create_database(target_db, template: source_db)

  true
end