Archive for October, 2007

Recovering Databases after a MySQL Upgrade

Tuesday, October 30th, 2007

I ran into an issue with MySQL the other day. After upgrading to a newer version on my development server (a Mac), my databases, user privileges and root password were missing. This isn’t the first time I’ve felt that sinking feeling as I frantically searched for the missing files, and since the fix is easy I thought I should write it up to save you the panic if you ever find yourself in the same situation.

(more…)

What Motivates Programmers

Tuesday, October 30th, 2007

A pair of interesting posts by Nick Halstead:

“Hey, you got Google in MySQL…”

Thursday, October 25th, 2007

Google is one of the biggest users of MySQL and they have added many enhancements to get MySQL to meet their needs, including better database replication and tools to monitor a high volume of database instances.

Now, thanks to an agreement between Google and MySQL, some of those features are going to be put back into MySQL so that everyone can take advantage of them. These new features should start showing up around MySQL 6.1 in 2009 and are just part of the improvements on the roadmap to MySQL 7.0 recently laid out by the MySQL group.

Some of the other improvements scheduled on the MySQL roadmap are better enterprise-level security features, a new storage engine (Falcon), table and index partioning, and row-based replication. Most web developers won’t notice a difference, but power-users and database admins will welcome these high-level additions that put MySQL on par with Oracle and IBM solutions.

From ComputerWorld

Ruby on Rails Beyond the Basics

Thursday, October 18th, 2007

RoR BTB package

I’m happy to announce that my latest video training, Ruby on Rails Beyond the Basics, has been released on the lynda.com Online Training Library.

Ruby on Rails Beyond the Basics is the sequel to Ruby on Rails Essential Training and is 11.5 hours of video training for web developers who already feel comfortable with the fundamentals of Ruby and the Rails MVC framework. I teach more of the Ruby language and spend a lot of time on code blocks. Then, using the example of a blog as a project, I show you how to use migrations, demonstrate how to create CRUD that doesn’t simply mimic scaffold, and give you a better understanding of ActiveRecord and some of the pitfalls that often trip up developers. I also cover validations, callbacks, routes, pagination, performance improvements and more.

Ruby on Rails Beyond the Basics is available online as streaming video to subscribers of the lynda.com Online Training Library ($25/month, $250/year, $375/year with exercise files included). It is will also be available as a CD-ROM soon both through lynda.com and Amazon.com.

If you are a beginner, you will be better off if you first start with Ruby on Rails Essential Training which is available online to lynda.com OTL subscribers and on CD-ROM, both through lynda.com and Amazon.com, for $99.95.

If you try either of them and find that they are helpful, be sure to let me know!

Topics include:

  • Updating Ruby, Rails and projects
  • Using irb and the Rails console
  • Intermediate Ruby language techniques
  • Understanding code blocks
  • Catching errors and raising exceptions
  • Using migrations to manage database changes
  • Understanding ActiveRecord and avoiding common pitfalls
  • Creating flexible controllers and views
  • Improving performance with eager loading and cache counters
  • Working with form validations and model callbacks
  • Using partials and helpers to organize views
  • Salting passwords for increased security
  • Choosing how to store session data
  • Understanding and defining custom and named routes
  • Pagination
  • Using plug-ins

A List Apart: Web Design Survey Results

Wednesday, October 17th, 2007

A List Apart Web Survey

A List Apart has released their 2007 Web Design Survey results.

They received 33,000 reponses to their 37 question survey and massaged all that data into 80 pages of interesting findings. Not only do they share the summary of age, ethnicity, salary, and job field, but they also dive deeper to examine questions such as how many women felt their was a gender bias and is that bias reflected in their salaries. It is an impressive undertaking and worth a read.

Even though “Developers” seem to be well represented in the survey, keep in mind that the ALA audience skews toward designers, designer/developers and those interested in CSS, accessibility and usability, instead of hard-core code heads. If you surveyed enterprise Java developers or Oracle database administrators you might get different results.

Six Scaling Server Set-Ups

Tuesday, October 16th, 2007

Stuart Herbert has posted six ways to group and organise your web servers. He starts small with simple shared hosting and scales upward to web farms, clusters and n-Tier architectures. (Stuart is a PHP-guy but his server advice is platform and language agnostic.)

It’s a good overview for anyone who’s thinking that they are outgrowing their current server set up and wondering what options they should consider. If nothing else it should give you the language you need to go off and do more research on your own.

It’s also a good read if you aren’t outgrowing your server, but want to design applications smartly, so that they could scale if necessary.

Rails version 1.2.5 and Capistrano 2.1

Monday, October 15th, 2007

If you blinked you would have missed version 1.2.4. Rails version 1.2.5 has been released. For the most part, it is a security release to fix a JSON problem. If you aren’t using JSON, then it’s optional but never a bad idea.

If you didn’t upgrade to version 1.2.4 already, don’t be alarmed when gem install rails –include-dependencies downloads version 1.2.5 now.

If you want to upgrade to 1.2.5, you can follow the same steps as I outlined previously for 1.2.4.

And Capistrano 2.1 has been released.

Capistrano is a tool for automating tasks on remote servers, especially those running Ruby on Rails applications. It lets system administrators execute commands and roll back changes in parallel across multiple machines.

Rails version 1.2.4

Thursday, October 11th, 2007

As foreshadowed last week, Rails version 1.2.4 has been released. It’s mostly made up of security fixes and deprecation notices that will help you prepare for Rails 2.0.

Steps to Upgrade

Install Rails 1.2.4

Install the Rails 1.2.4 gem on your development server. You could install it by freezing a version into your vendor directory (like I recommended for Rails 2.0) but honestly, this release is minor and I recommend you simply upgrade the gem instead.

gem install rails --include-dependencies

#(or sudo gem install rails --include-dependencies)

You’ll end up with both your old Rails version and version 1.2.4 as gems.

# display all installed gems with:
gem list --local

You have a few choices on what to do with the old versions.

# Option 1: uninstall all gems which have a newer version
# (generally the best option after you are ready to commit to 1.2.4)
gem cleanup

#You can preview what cleanup will do with:
gem cleanup --dryrun

# Option 2: uninstall only the old Rails version
# (use if you need to keep old versions of other gems around)
# list the gems if you think you have different versions
gem uninstall rails --version 1.2.3
gem uninstall actionwebservice --version 1.2.3
gem uninstall activerecord --version 1.15.3
gem uninstall actionmailer --version 1.3.3
gem uninstall actionpack --version 1.13.3
gem uninstall activesupport --version 1.4.2

# Option 3: uninstall the new Rails version
# (only if something did not work out and
# you need to revert to your old version)
gem uninstall rails --verison 1.2.4

Track Down Deprecated Code

There are three ways that you can track down and update your deprecated code. I recommend doing as many of them as you can.

1. Run your application’s tests to see the deprecation warnings.

2. Click through your application by hand and watch the development log for the errors.

3. Save this code by Mislav Marohnić as “r2check.rb” and run it from the root of your application. It will scan through your application files searching for matches to regular expressions corresponding to deprecated code. (You won’t need to explicitly specify the location of your application—it will assume it is the current directory.)

For example:

cd /path/to/your_rails_app

ruby /path/to/r2check.rb

Watch Out for Previously Deprecated Code

You’ll also want to make sure you’ve taken care of all previous deprecations. I’ve listed a few key ones below.

  • @params, @sessions, @cookies, @flash, @request, @response, @headers, @env, and @template have all been deprecated in favor of simply using params, sessions, cookies, etc. without the @ prefix. (It’s a method call that returns an instance variable instead of an instance variable directly.)
  • @content_for_layout has been deprecated. Use yield instead.
  • Forms and links performing POST operations should use :method => :post instead of :post => true
  • start_form_tag and end_form_tag are outdated. Use form_tag() do {…} or form_for() do {…} instead.
  • render_partial has become render(:partial => ’something’)
  • find_all and find_first have become find(:all) and find(:first)

Install Pagination Plug-in

Pagination will be moving to a plug-in. If you have been using pagination anywhere in your application, you will want to install the plug-in for either ClassicPagination or change your code to use WillPaginate. (Both plug-ins can co-exist too if you want to start with ClassicPagination and move to WillPaginate over time.)

# Note: you'll need to have Subversion installed
ruby script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination
ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate

And then you’ll be in a great position to upgrade to Rails 2.0 once the final release comes out later this month!

UPDATE: I forgot to explicitly provide the final steps. Once you have the upgrade installed, go into your Rails application. Open up config/environment.rb and update the RAILS_GEM_VERSION to ‘1.2.4′ or ‘1.2.5′ (most likely on line #8). Save and close the file. Then from a command line from the root of your Rails application, run rake rails:update:configs. (First making backup of that directory is always the safest choice.) That will make sure your configuration files (like boot.rb) get updated with the latest code too.

She’s Geeky

Thursday, October 4th, 2007

She’s Geeky

She’s Geeky will be an (un)conference in Mountain View, CA on October 22-23. Tickets are $175.

It is designed to provide women who self-identify as geeky and who are engaged in various technology-focused disciplines with a gathering space in which they can exchange skills and discuss ideas and form community across and within disciplines.

What’s an “(un)conference”? There will not be an organized agenda, instead the attendees will decide on the content. There is a Wiki page with proposed topics.

Rails 2.0 Preview Release

Tuesday, October 2nd, 2007

Rails 2.0 PR

The Rails 2.0 Preview Release is out. David Heinemeier Hansson provides an overview of some of the new features. There may be several preview releases before the final release. I’m sure there will be bug fixes—but DHH said in his RailsConf Europe keynote that 37signals has been running many sites (including Basecamp) on most of the Rails 2.0 code for several months, so it ought to be pretty solid by now. If I had to guess, I’d say we are 3-4 weeks away from a final release.

Before the final release, the Rails core team have also promised to release version 1.2.4. The update to Rails 1.0 will likely include minor bug fixes, however it’s primary purpose will be to provide complete deprecation warnings. So the process will be: upgrade to 1.2.4, try everything, watch the log files for deprecation warnings, fix any incompatible code, then upgrade to 2.0. Don’t be surprised if 1.2.4 is released only a week before 2.0.

The best way to safely try out the preview release is to download it into the vendor directory of a Rails project. (You will need Subversion installed. If you are on a Mac, this guide can help you install it.) Using a command line, navigate into the root of the project and type:

rake rails:freeze:edge TAG=rel_2-0-0_PR

Once the download is complete, that Rails project (and only that project) will be running on the preview release. Type rake rails:unfreeze if you want to go back to your regularly installed Rails version. Advanced users can opt to install the gem version of the preview release instead.

UPDATE: If you are on Rails 1.2.3, you’ll need to run the “freezing” twice. The first time will not download the new ActiveResource pieces (Rails 1.2.3 doesn’t know about them) and you’ll get errors when you try to start the server. When you run it the second time, Rails will know that it should have ActiveResource and will retrieve it for you.