Class: Brut::CLI::Apps::DB::Create
Instance Attribute Summary
#parent_command
Instance Method Summary
collapse
#accepts, #args_description, #argv, #commands, #default_command, #default_command_class, #env, #env_vars, #execute, #name, #options, #opts, #puts, #stderr, #stdin, #stdout, #system!
Instance Method Details
#bootstrap? ⇒ Boolean
61
|
# File 'lib/brut/cli/apps/db.rb', line 61
def bootstrap? = false
|
#default_rack_env ⇒ Object
60
|
# File 'lib/brut/cli/apps/db.rb', line 60
def default_rack_env = "development"
|
#description ⇒ Object
59
|
# File 'lib/brut/cli/apps/db.rb', line 59
def description = "Create the database if it does not exist"
|
#run ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/brut/cli/apps/db.rb', line 63
def run
connection = Sequel.connect(Brut.container.database_url)
stdout.puts "Database already exists"
connection.disconnect
0
rescue Sequel::DatabaseConnectionError => ex
uri_no_database = URI(Brut.container.database_url.to_s)
database_name = uri_no_database.path.gsub(/^\//,"")
uri_no_database.path = ""
begin
connection = Sequel.connect(uri_no_database.to_s)
stdout.puts "Database #{database_name} does not exist. Creating..."
connection.run("CREATE DATABASE \"#{database_name}\"")
connection.disconnect
0
rescue Sequel::DatabaseConnectionError => ex2
stderr.puts "Database server is not running at #{uri_no_database}: #{ex2.message}"
stderr.puts "This could be a problem with your dev environment generally, or your .env.test or .env.test.local files"
1
end
end
|