Class: Commands::CreateDatabase

Inherits:
Object
  • Object
show all
Extended by:
Citrin::Helpers
Defined in:
lib/citrin/commands/create_database.rb

Class Method Summary collapse

Methods included from Citrin::Helpers

database_template_file, logrotate_config_template, rails_app_log_file, webserver_template_file

Class Method Details

.run(app) ⇒ Object



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

def self.run(app)
  @app = app
  db_queries = %Q{
    create database #{@app.db_name};
    GRANT ALL ON #{@app.db_user}.* TO '#{@app.db_name}'@'localhost';
    SET PASSWORD FOR '#{@app.db_user}'@'localhost' = PASSWORD('#{@app.db_pass}');
  }
  `sudo mysql --defaults-extra-file=/root/.my.cnf -u root -e "#{db_queries}"`

  template_file = database_template_file(@app.env)
  template = ERB.new(File.read(template_file), 0, "%<>")
  result = template.result(binding)

  puts %Q{
Put this in your config/database.yml
#{result}

and run
  RAILS_ENV=#{@app.fullenv} rake db:migrate"
  }
  return @app    
end