Skip to content

Instantly share code, notes, and snippets.

@QQism
Created August 1, 2012 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QQism/3228321 to your computer and use it in GitHub Desktop.
Save QQism/3228321 to your computer and use it in GitHub Desktop.
dotCloud postinstall to overwrite database.yml for rails app
#!/usr/bin/env ruby
require 'yaml'
DB_ADAPTER = "postgresql"
DATABASE = "my_database"
ENCODING = 'utf8'
TEMPLATE = 'template0'
TIMEOUT = 5000
POOL = 5
def load_dotcloud_env
env = YAML.load(IO.read('/home/dotcloud/environment.yml'))
end
def overwrite_database_file
env = load_dotcloud_env
database = {
'production' => {
'adapter' => DB_ADAPTER,
'database' => DATABASE,
'host' => env['DOTCLOUD_DB_SQL_HOST'],
'port' => env['DOTCLOUD_DB_SQL_PORT'].to_i,
'username' => env['DOTCLOUD_DB_SQL_LOGIN'],
'password' => env['DOTCLOUD_DB_SQL_PASSWORD'],
'encoding' => ENCODING,
'template' => TEMPLATE,
'timeout' => TIMEOUT,
'pool' => POOL
}
}
File.open('config/database.yml', 'w') do |file|
file.write database.to_yaml
end
end
puts '=== Start to overwrite database.yml ==='
overwrite_database_file
puts '=== Finished overwriting! ==='
@QQism
Copy link
Author

QQism commented Aug 1, 2012

This file is intended to use with PostgreSQL with default dotCloud database settings, but also can be modified to fit with MySQL as well.
Don't forget to make this file executable by chmod +x postinstall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment