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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/remote_database_importer/config.rb', line 37
def create_default_config
enter_new_environments = true
environment_count = 1
local_db_name = ask("Whats the name of the local database you wanna import to?", default: "myawesomeapp_development")
config.set(:local_db_name, value: local_db_name)
puts
while enter_new_environments
puts Colorize.green("#{environment_count}. Environment")
env = ask("Whats the name of the #{environment_count}. environment you wanna add?", default: "staging")
puts
puts Colorize.green("Database settings:")
db_name = ask("Enter the DB name for the #{env} environment:", default: "myawesomeapp_#{env}")
db_user = ask("Enter the DB user for the #{env} environment:", default: "deployer")
puts
puts Colorize.green("Connection settings:")
host = ask("Enter the IP or hostname of the DB server:", default: "myawesomeapp.com")
dump_type = ask("Should the DB dump happen over a ssh tunnel or can pg_dump connect to the DB port directly?", default: "pg_dump", options: ["ssh_tunnel", "pg_dump"])
ssh_user, ssh_port, postgres_port = nil
if dump_type == "ssh_tunnel"
ssh_user = ask("Enter the username for the SSH connection:", default: "deployer")
ssh_port = ask("Enter the port for the SSH connection:", default: "22")
else
postgres_port = ask("Enter the database port for the pg_dump command:", default: "5432")
end
puts Colorize.green("Define custom commands that run after successful import:")
custom_commands = ask("Enter semicolon separated commands that should run after importing the DB:", default: "rake db:migrate; echo 'All Done'")
puts
env_config = {
env.to_s => {
"database" => {
"name" => db_name,
"user" => db_user
},
"connection" => {
"host" => host,
"dump_type" => dump_type,
"postgres_port" => postgres_port,
"ssh_user" => ssh_user,
"ssh_port" => ssh_port
},
"custom_commands" => custom_commands
}
}
config.append(env_config, to: :environments)
continue = ask("Do you wanna add another environment? (anything other than 'yes' will exit)")
if continue&.downcase == "yes"
environment_count += 1
else
enter_new_environments = false
end
end
config.write
end
|