Rails on the Run

Rails experiments by Matt Aimonetti

Browsing Posts tagged database

What’s new?

  • Rails default database is now sqlite3. If you are running Leopard, everything is already setup for you. As DHH mentioned, just “rails -d mysql yourappname” if you want to generate a new app preconfigured for MySQL.
    Sqlite3 is great and if the only reason why you didn’t give it a try is because you have to use CocoaMySQL, then check out sqlitebrowser

  • Other new feature: rake secret to generate a key used to encrypt your session. Really useful task when you’re migrating an app to 2.x

  • To improve performance, some changes were made to the template caching and you have to restart your production server after a template modification.

  • Validates acceptance of still works for non-existent tables . (sorry Josh, I won’t post after 2am, especially when I forget your life changing bug fix ;) )

  • Added option to pass proc to ActionController::Base.asset_host for maximum configurability. Example:

    ActionController::Base.asset_host = Proc.new { |source|
      if source.starts_with?('/images')
  • Finally, I added 2 new rake tasks: db:migrate:redo and db:migrate:reset

    db:migrate:redo rolls back your database and then migrates it up. You can define the STEP constant to specify the amount of steps you want to rollback. This task is very useful in development mode when making a modification to the latest migration(s).
    db:migrate:reset will drop your database, re create it and migrate it up. Only use this task if you really have to and only in development/test environment. Use db:reset in production mode since it uses the schema.rb file and won’t go through the hundreds of migrations you might have.


2.0.2 (December 16th, 2007)

  • Changed the default database from mysql to sqlite3, so now running “rails myapp” will have a config/database.yml that’s setup for SQLite3 (which in OS X Leopard is installed by default, so is the gem, so everything Just Works with no database configuration at all). To get a Rails application preconfigured for MySQL, just run “rails -d mysql myapp” [DHH]

  • Turned on ActionView::Base.cachetemplateloading by default in config/environments/production.rb to prevent file system stat calls for every template loading to see if it changed (this means that you have to restart the application to see template changes in production mode) [DHH]

  • Introduce rake secret to output a crytographically secure secret key for use with cookie sessions #10363 [revans]

  • Fixed that local database creation should consider local #9026 [parcelbrat]

  • Fixed that functional tests generated for scaffolds should use fixture calls instead of hard-coded IDs #10435 [boone]

  • Added db:migrate:redo and db:migrate:reset for rerunning existing migrations #10431, #10432 [matt]

  • RAILSGEMVERSION may be double-quoted also. #10443 [James Cox]

  • Update rails:freeze:gems to work with RubyGems 0.9.5. [Jeremy Kemper]

  • Added deleteviaredirect and putviaredirect to integration testing #10497 [philodespotos]

  • Allow headers['Accept'] to be set by hand when calling xmlhttprequest #10461 [BMorearty]

  • Added OPTIONS to list of default accepted HTTP methods #10449 [holoway]

  • Added option to pass proc to ActionController::Base.asset_host for maximum configurability #10521 [chuyeow]. Example:

    ActionController::Base.asset_host = Proc.new { |source|
    if source.starts_with?(‘/images’)

  • Fixed that ActionView#fileexists? would be incorrect if @firstrender is set #10569 [dbussink]

  • Added that Array#toparam calls toparam on all it’s elements #10473 [brandon]

  • Ensure asset cache directories are automatically created. #10337 [Josh Peek, Cheah Chu Yeow]

  • render :x ml and :json preserve custom content types. #10388 [jmettraux, Cheah Chu Yeow]

  • Refactor Action View template handlers. #10437, #10455 [Josh Peek]

  • Fix DoubleRenderError message and leave out mention of returning false from filters. Closes #10380 [Frederick Cheung]

  • Clean up some cruft around ActionController::Base#head. Closes #10417 [ssoroka]

  • Ensure optimistic locking handles nil #lock_version values properly. Closes #10510 [rick]

  • Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases. Closes #10379 [brynary]

  • Fix that validatesacceptanceof still works for non-existent tables (useful for bootstrapping new databases). Closes #10474 [hasmanyjosh]

  • Ensure that the :uniq option for has_many :through associations retains the order. #10463 [remvee]

  • Base.exists? doesn’t rescue exceptions to avoid hiding SQL errors. #10458 [Michael Klishin]

  • Documentation: Active Record exceptions, destroyall and deleteall. #10444, #10447 [Michael Klishin]

I just released a simple plugin that I use to backup and restore databases instead of using a mysql dump.

check out the plugin page

File structure will look like that:


I use this plugin to backup my apps running in production. When I need to debug an application, I just need to restore the db locally and debug. The fact that it uses fixtures helps me finding data quickly and I can easily decide to only restore few tables.

I also have a Capistrano recipe to create backups before each deployment.

oohh and the plugin is Sake compatible, give it a try :)


I’m quite glad to let you know that my first patch made it to Rails Edge.

UPDATE: Ryan Daigle covered the new added features in his blog
How cool is that?

That’s a great achievement that I owe to josh Knowles and Josh Susser

Josh Knowles and Matt Heidemann from Integrum started working on rake_tasks a little while ago. I helped them hacking this cool plugin. After a while, we realized that the plugin was getting too big and we decided to split it in two:

  • db_tasks
  • svn_tasks

Without telling the other guys (sorry!), I started discussing merging some of the rake_tasks plugin in Rails core.

I then submitted my patch following Josh Susser recommendations.

Today, Josh congratulated me on the merge. I’m quite glad/proud that our work made it to Edge.

What’s that patch anyway?

Here are the 2 features my patch added to the future Rails 2.0:

  • MySQL: create_database takes :charset and :collation options. Charset defaults to utf8.
  • Add db:create, drop, reset, charset, and collation tasks

That means that you cna now do that:

$rails my_app
$rake db:create
$ruby script/server

That’s it, you have a working Rails app!! Well, almost, there’s nothing it in yet but at least your databases are created. Ohh, and your database is unicode, that also means that all your new tables will be utf8.

Enjoy :)