paul doerwald
my fresh thoughts
Now running on Jekyll
Posted on 13 Nov 2009
At long last, I’ve migrated off of Mephisto on to Jekyll, as much of the Rails community has done. This message serves as a test, more than anything else, but at least now I can start posting again soon.
Although they tell you that Rails (2.3) is ready for Ruby 1.9, the reality is that few of the gems are. On a particular project where we really wanted to use Ruby 1.9's new M17N and I18N functionality, I didn't actually run into too many problems with most of the gems I use, but for one, VERY painful one: the postgres(/pg/ruby-pg) gem.
Interestingly enough, the gems work just fine until you pull some UTF-8 content from the database. The existing database adapters (and mysql is included in this) return that content as encoding ASCII-8BIT (aka BINARY). As soon as you try to show that content on a page that is otherwise encoded UTF-8, you get incompatible character encodings: ASCII-8BIT and UTF-8.
This is definitely a problem with the database drivers, which should be returning the same encoding as the database. This problem hasn't officially been fixed yet, but there has been some effort to that end. For postgres, you'll need to use ruby-pg (rather than postgres or pg, even though they're somehow the same, yet different... if anyone cares to explain...?) along with a patch that's referenced in an excellent ticket on the topic. I know this works on Mac OS X and on Fedora 8. For Windows, YMMV:
# do everything as root (it's just easier this way) sudo bash # get rid of the pg if you have it already; you might want to do this for ruby-pg as well /usr/local/bin/gem uninstall pg # change to some convenient working directory cd /usr/local/src svn checkout http://ruby-pg.rubyforge.org/svn cd svn/ruby-pg/trunk/ext # download and install the patch curl -O http://rubyforge.org/tracker/download.php/3214/12398/25931/4535/pg-m17n3.patch patch < pg-m17n3.patch # should respond indicating that all patches successfully applied # set up an important environment variable export ARCHFLAGS='-arch i386' /usr/local/bin/ruby extconf.rb make make install
Worked for me. Let me know in the comments if I need to make a change to the instructions above.
Update
It strikes me that if you run into any troubles applying the patch, then these instructions may be out-of-date, and you can probably just go ahead and install the latest gem, assuming it's something higher than 0.8.0.
Staging/development instance
Posted on 30 Apr 2009
For a client I needed to set up a sort of staging/development instance. We're a distributed team and in order for us to review each others' work before it's deployed, we need to host it somewhere that's not the production server.
Apparently there's a Capistrano extension for handling this, and there's some good, well-cited documentation out there as well, but it all felt really heavy weight until I found this article.
I love the simplest, most elegant solution, and this approach wins. Now deploying the staging version (off the git staging branch) is as simple as cap staging deploy. If I want the main production branch, I cap production deploy, and I can easily add another branch if I wish. The code (from deploy.rb):
task :production do role :app, "192.168.100.1" role :web, "192.168.100.1" role :db, "192.168.100.1", :primary => true set :branch, "master" end task :staging do role :app, "192.168.100.2" role :web, "192.168.100.2" role :db, "192.168.100.2", :primary => true set :branch, "staging" end
cap staging deploy:migrations, cap production mongrel:cluster:start, etc. all work as expected, and even better yet, if I fall into my old habits of cap deploy I'll get an error which reminds me that I have to specify a deploy target.
Who needs complex capistrano extensions when you have this? I don't think it can get cleaner or simpler!
I've taken over a Rails project whose database is MySQL. While I've grudgingly come to respect MySQL, I still vastly prefer PostgreSQL, largely because I'm more familiar with it. I decided to take the plunge and migrate the project from MySQL to PostgreSQL.
A search for MySQL to Postgres conversion scripts turns up pretty empty, but then it struck me that I can do the conversion using ActiveRecord's schema dumping. The problem with this approach is that AR ignores constraints, foreign keys, etc., but in my case, the data I was migrating used none of those. Then to copy the data, I used MySQL's select into outfile feature and PostgreSQL's copy from file feature. The steps were:
- I created a postgres database
application_developmentand put it in thetestsection ofconfig/database.yml. - I dumped the current schema by running
rake db:schema:dump. - I loaded that schema by running
RAILS_ENV=test rake db:schema:load. - Grant your MySQL user file privileges. Log on to MySQL as root:
mysql -u root, and then do the grant:grant File on *.* to 'paul'@'localhost';— bear in mind that this may introduce a significant security risk in a production system; be safe and revoke the privilege when you're done. - Create a
/dumpsdirectory and give it777(world write) permissions. - For each table (
users,profiles,friendships, etc.) in MySQL, run:select * into outfile '/dumps/users.sql' from users;. - In Postgres, load the dumps. You'll have to do this as a postgres superuser, or you'll have to copy from STDIN.
copy users from '/dumps/profiles.sql';.
From here, I updated my config/database.yml and restarted my mongrels, and everything worked perfectly! I'm going to start adding database constraints now...