Created
December 2, 2012 08:51
-
-
Save vitaliel/4187770 to your computer and use it in GitHub Desktop.
Read database.yml file and generate sql to create databases
This file contains hidden or 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 | |
| # Read database.yml file and generate sql to create databases | |
| # ./rails_db_create.rb | mysql | |
| require 'yaml' | |
| config = YAML.load_file 'database.yml' | |
| dbs = {} | |
| config.each do |env, opts| | |
| dbs[opts['database']] = opts | |
| end | |
| dbs.each do |db, opts| | |
| puts "CREATE DATABASE `#{db}` DEFAULT CHARACTER SET #{opts['encoding']};" | |
| puts "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX | |
| ON #{db}.* | |
| TO #{opts['username']}@localhost IDENTIFIED BY '#{opts['password']}'; | |
| flush privileges;" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment