Created
August 1, 2012 16:17
-
-
Save QQism/3228321 to your computer and use it in GitHub Desktop.
dotCloud postinstall to overwrite database.yml for rails app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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! ===' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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