Daily ArchiveFriday, June 17th, 2005
Uncategorized 17 Jun 2005 10:24 pm
Script to load your database
If you have a bunch of database DDL and DML files to load to get your app configured, here’s a little script I wrote that might help. It is set to be run from your db directory alongside your .sql files. You can have your type tables in subdirectories if you like – I do. Here’s my folder layout:
db
configure.rb --> the script below
create.sql
drop.sql
types
exec-1
ability_types.dml
costs.dml
...
exec-2
divisions.dml
exec-3
teams.dml
The script will run the top level sql first assuming it is the db definition. It then goes through all the lower directories and loads them up. In the example above the divisions.dml depends on types from exec-1 being loaded, teams.dml depends on divisions.dml, etc.
Here’s the script (configure.rb):
require 'yaml'
# You can comment or delete the puts calls --
# they're just so I can follow along and feel all warm and fuzzy.
# you may need to hard-code your env if it isn't in your environment settings:
RAILS_ENV = ENV['RAILS_ENV'] || 'development'
CONFIG_DIR = File.dirname(__FILE__) + "/../config/"
db_settings = YAML::load(File.open(CONFIG_DIR + "database.yml"))
db_host = db_settings[RAILS_ENV]['host']
db_user = db_settings[RAILS_ENV]['username']
db_pass = db_settings[RAILS_ENV]['password']
db_name = db_settings[RAILS_ENV]['database']
DB_CONNECT = "-u #{db_user} --password=#{db_pass} -h #{db_host} #{db_name} "
# This runs the drop.sql and create.sql first
# reverse is used to execute a 'drop.sql' before a 'create.sql'
# you may want to tweak for your situation
Dir["**/*.sql"].reverse.each do |f|
cmd = "mysql " + DB_CONNECT << " < " << f
system cmd
puts cmd
end
# Then all the dml gets loaded
Dir["**/*.dml"].each do |f|
cmd = "mysql " + DB_CONNECT << " < " << f
system cmd
puts cmd
end
Uncategorized 17 Jun 2005 12:42 pm
DreamHost adds Rails support
It is unofficially offical as announced in the DreamHost discussion forums and through communications with those involved.
This is a new install of Typo running on Apache/FastCGI here at DreamHost.
I’d like to thank DreamHost for taking this up quickly. It isn’t easy to turn a big ship like theirs, but they’ve gone from talking about getting this installed in mid March to getting it running by mid June. That’s pretty good considering.