Module: Voodoo::Commands

Extended by:
Commands
Included in:
Commands
Defined in:
lib/voodoo/commands.rb,
lib/voodoo/commands/add.rb,
lib/voodoo/commands/run.rb,
lib/voodoo/commands/list.rb,
lib/voodoo/commands/show.rb,
lib/voodoo/commands/build.rb,
lib/voodoo/commands/config.rb,
lib/voodoo/commands/remove.rb,
lib/voodoo/commands/archive.rb,
lib/voodoo/commands/compare.rb,
lib/voodoo/commands/migrate.rb,
lib/voodoo/commands/template.rb

Defined Under Namespace

Classes: ErbBinding

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add(args = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/voodoo/commands/add.rb', line 6

def self.add(args=nil)
  settings = {}
  puts "\n----Appdesigner/Datamover/AppEngine Settings------"
  if args.first.nil?
    name = ask("Database name: ").upcase
  else
    name = args.first.upcase
  end
  settings['db_type'] = ask("Database type: ", %w{ORACLE}) { |q| q.default = "ORACLE" }
  settings['app_username'] = ask("Application username: ")

  puts "\n----Output Archive Settings-----------------------"
  if agree("\nWould you like to archive migration output files for this environment? (y/n) ") == true
    settings['migration_archive'] = get_path("Archive destination")
  end

  puts "\n----SQR Settings----------------------------------"
  settings['db_username'] = ask("Database username: ") { |q| q.default = "sysadm" }
  settings['ps_home'] = get_path("PS_HOME directory")

  new_env = {name => settings}
  LOG.debug("Adding #{name} to the list of configured environments")
  ENVIRONMENTS.merge!(new_env)
  Voodoo.write_env_file
end

.configObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/voodoo/commands/config.rb', line 6

def self.config
  settings = {}
  puts "\n----Global Configuration Settings-----------------"
  settings[:ps_home] = get_path("Local tools directory")
  settings[:migration_output_dir] = get_path("Default output directory for migration data")

  # if agree("\nWould you like to define email notification settings? (y/n) ") == true
  #   settings[:mail_server] = ask("SMTP server: ")
  #   settings[:smtp_port] = ask("SMTP port: ") { |q| q.default = "587" }
  #   settings[:email_from] = ask("Email from address: ")
  # end
  Voodoo.write_config_file(settings)
end

.listObject



5
6
7
8
9
10
11
12
13
# File 'lib/voodoo/commands/list.rb', line 5

def self.list
  setup?
  env_table = table
  env_table.headings = ['ENVIRONMENTS']
  Voodoo.environments.keys.each do |env|
    env_table << [env]
  end
  puts env_table
end

.remove(args = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/voodoo/commands/remove.rb', line 6

def self.remove(args=nil)
  if args[0].nil?
    env = ask("Environment to remove?: ", ENVIRONMENTS.keys)
  else
    env = args[0].upcase
  end
  LOG.debug("Removing #{env} from the list of configured environments")
  ENVIRONMENTS.delete(env)
  Voodoo.write_env_file
end

.show(args = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/voodoo/commands/show.rb', line 6

def self.show(args=nil)
  setup?
  if args[0].nil?
    source = ask("Environment name: ", ENVIRONMENTS.keys).upcase
  else
    source = args[0].upcase
  end

  validate_env(source)

  env = Voodoo.environments[source]
  user_table = table
  user_table.headings = source.upcase, ' '
  env.each do |key, value|
    user_table << [key, value]
  end
  puts user_table
end

Instance Method Details

#archive(args = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/voodoo/commands/archive.rb', line 7

def archive(args=nil)
  setup?

  if args[0].nil?
    project = get_project
  else
    project = args.first
  end

  if args[1].nil?
    source = get_source
  else
    source = get_env(args[1].upcase)
  end

  migration = get_migration

  ad = Voodoo::AppDesigner.new

  ad.copy_to_file(project, migration, source)
end

#build(args = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/voodoo/commands/build.rb', line 7

def build(args=nil)
  setup?

  if args[0].nil?
    project = get_project
  else
    project = args.first
  end

  if args[1].nil?
    source = get_source
  else
    source = get_env(args[1].upcase)
  end

  migration = get_migration

  ad = Voodoo::AppDesigner.new
  dm = Voodoo::DataMover.new

  ad.build_project(project, migration, source)
  dm.run(migration, source, "PSBUILD.sql")
end

#compare(args = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/voodoo/commands/compare.rb', line 7

def compare(args=nil)
  setup?

  if args[0].nil?
    project = get_project
  else
    project = args.first
  end

  if args[1].nil?
    source = get_source
  else
    source = get_env(args[1].upcase)
  end

  if args[2].nil?
    target = get_target
  else
    target = get_env(args[2].upcase)
  end

  migration = get_migration

  ad = Voodoo::AppDesigner.new
  ad.compare(project, migration, source, target)
end

#dttmObject



97
98
99
# File 'lib/voodoo/commands.rb', line 97

def dttm
  Time.now.strftime("%m/%d/%Y %H:%M:%S") + " >>> "
end

#get_appengineObject



85
86
87
# File 'lib/voodoo/commands.rb', line 85

def get_appengine
  ask("Appengine name: ").upcase
end

#get_databaseObject



67
68
69
70
71
72
73
# File 'lib/voodoo/commands.rb', line 67

def get_database
  name = ask("Database name: ", ENVIRONMENTS.keys)
  env = OpenStruct.new(ENVIRONMENTS[name])
  env.name = name
  env.db_password = get_db_password(name)
  return env
end

#get_db_env(name) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/voodoo/commands.rb', line 39

def get_db_env(name)
  if ENVIRONMENTS[name]
      env = OpenStruct.new(ENVIRONMENTS[name])
      env.name = name
      env.db_password = get_db_password(name)
  else
      puts "#{name} is not listed in the configuration file"
      exit
  end
  return env
end

#get_env(name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/voodoo/commands.rb', line 27

def get_env(name)
  if ENVIRONMENTS[name]
      env = OpenStruct.new(ENVIRONMENTS[name])
      env.name = name
      env.app_password = get_app_password(name)
  else
      puts "#{name} is not listed in the configuration file"
      exit
  end
  return env
end

#get_migrationObject



75
76
77
78
# File 'lib/voodoo/commands.rb', line 75

def get_migration
  folder_name = ask("Name for output folder: ").upcase
  Migration.new(folder_name)
end

#get_path(prompt) ⇒ Object

TODO: change this so that you can specify the root of a drive



90
91
92
93
94
95
# File 'lib/voodoo/commands.rb', line 90

def get_path(prompt)
  ask("#{prompt}: ") do |q|
    q.validate = %r=^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*))=
    q.responses[:not_valid] = "Please enter a valid folder path."
  end
end

#get_projectObject



23
24
25
# File 'lib/voodoo/commands.rb', line 23

def get_project
  ask("Project name: ").upcase
end

#get_sourceObject



51
52
53
54
55
56
57
# File 'lib/voodoo/commands.rb', line 51

def get_source
  source = ask("Source environment: ", ENVIRONMENTS.keys)
  env = OpenStruct.new(ENVIRONMENTS[source])
  env.name = source
  env.app_password = get_app_password(source)
  return env
end

#get_sqrObject

TODO: figure out how to get this to recursively search a directory



81
82
83
# File 'lib/voodoo/commands.rb', line 81

def get_sqr
  ask("SQR name: ")
end

#get_targetObject



59
60
61
62
63
64
65
# File 'lib/voodoo/commands.rb', line 59

def get_target
  target = ask("Target environment: ", ENVIRONMENTS.keys)
  env = OpenStruct.new(ENVIRONMENTS[target])
  env.name = target
  env.app_password = get_app_password(target)
  return env
end

#migrate(args = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/voodoo/commands/migrate.rb', line 7

def migrate(args=nil)
  setup?

  if args[0].nil?
    project = get_project
  else
    project = args.first
  end

  if args[1].nil?
    source = get_source
  else
    source = get_env(args[1].upcase)
  end

  if args[2].nil?
    target = get_target
  else
    target = get_env(args[2].upcase)
  end

  # Check for source and target being the same
  if source == target
    says("Source and target cannot be the same")
    exit
  end

  migration = get_migration
  ad = Voodoo::AppDesigner.new

  # Compare source to target
  ad.compare(project, migration, source, target)
  migration.continue?

  # Copy source to file
  ad.copy_to_file(project, migration, source)

  # Copy definition only to database
  ad.migrate_project_definition(project, migration, source, target)

  # Copy target to file
  ad.copy_to_file(project, migration, target)

  # Copy full project
  ad.migrate_full_project(project, migration, source, target)

  # Run second compare report
  ad.compare(project, migration, target,source)

  # Build project in target database
  if agree("Build project in target database? ") == true
    dm = Voodoo::DataMover.new
    ad.build_project(project, migration, target)
    dm.run(migration, target, "PSBUILD.sql")
  end

  # Move output files to archive folder for the target
  if target.migration_archive && agree("Copy output files to archive folder for #{target.name}? ") == true
    migration.copy_to_archive(target.migration_archive)
  end


end

#run_appengine(args = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/voodoo/commands/run.rb', line 27

def run_appengine(args=nil)
  setup?

  if args[0].nil?
    ae_name = get_appengine
  else
      ae_name = args[0].upcase
  end

  if args[1].nil?
    target = get_target
  else
    target = get_env(args[1].upcase)
  end

  instance = Voodoo::AppEngine.new
  instance.run(ae_name, target)
end

#run_sqr(args = nil) ⇒ Object



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

def run_sqr(args=nil)
  setup?

  if args[0].nil?
    sqr_name = get_sqr
  else
    sqr_name = args.first
  end

  if args[1].nil?
    target = get_database
  else
    target = get_db_env(args[1].upcase)
  end

  migration = get_migration

  instance = Voodoo::Sqr.new
  instance.run(migration, target, sqr_name)
end

#setup?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/voodoo/commands.rb', line 10

def setup?
  if CONFIGURATION.ps_home == nil
    puts "Global configuration not defined...use <voodoo config>"
    exit
  end

  if ENVIRONMENTS.empty?
    puts "No environments defined....use <voodoo add [environment]>"
    exit
  end

end

#template_datafix(args = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/voodoo/commands/template.rb', line 14

def template_datafix(args=nil)

  if args[0].nil?
    datafix = get_migration
  else
    datafix = Migration.new(args.first.upcase)
  end

  records = ask("Records to be affected: ", Array)

  backup_template = File.read(File.join((File.dirname(__FILE__)), '/templates/backup.dms').gsub!(File::SEPARATOR, File::ALT_SEPARATOR))
  script_template = File.read(File.join((File.dirname(__FILE__)), '/templates/script.sql').gsub!(File::SEPARATOR, File::ALT_SEPARATOR))

  vars = ErbBinding.new
  vars.name = datafix.migration_name
  vars.folder = datafix.migration_folder
  vars.records = records
  vars_binding = vars.send(:get_binding)

  generated_backup = ERB.new(backup_template, 0, "%<>")
  generated_script = ERB.new(script_template, 0, "%<>")

  backup_file = File.join(datafix.migration_folder, 'backup.dms').gsub!(File::SEPARATOR, File::ALT_SEPARATOR)
  puts "Creating file #{backup_file}"
  File.open(backup_file, 'w') {|f| f.write(generated_backup.result(vars_binding))}

  script_file = File.join(datafix.migration_folder, 'script.sql').gsub!(File::SEPARATOR, File::ALT_SEPARATOR)
  puts "Creating file #{script_file}"
  File.open(script_file, 'w') {|f| f.write(generated_script.result(vars_binding))}

  # puts File.expand_path(__FILE__)
end

#validate_env(name) ⇒ Object



101
102
103
104
105
106
# File 'lib/voodoo/commands.rb', line 101

def validate_env(name)
  unless ENVIRONMENTS[name]
    puts "#{name} is not listed in the configuration file"
    exit
  end
end