Home

Transition Between Database Adapters in Rails

Transitioning from one database to another, or even to a whole new database with a new adapter, can be tough. Here's an easy way to transition content.

For whatever reason, you might just need to transition your Rails app's content from one database type to another (or even just to a new database with the same adapter). I've found that yaml_db does a great job helping you with this task.

The first thing to do is get yaml_db installed.

Gemfile

gem 'yaml_db'

Then bundle.

$ bundle install

To dump the data, just run the appropriate rake task.

$ bundle exec rake db:data:dump

Then, switch your database over to the new database. Note: If you're switching adapters, make sure you have the appropriate gem(s) installed.

You'll need to make sure your database is setup. If it isn't, then get on it!

$ bundle exec rake db:create
$ bundle exec rake db:migrate

And then you can bring the data into the new database.

$ bundle exec rake db:data:load

Nice and easy! Be sure to note that if you're doing this to move content, then you may need to go through additional steps to move any uploaded assets.


References:

Let's Connect

Keep Reading

Big Oops: Just a Few (Old) Notifications

I've learned a few things the hard way. How to properly use Active Record callbacks with Ruby on Rails is one of those things.

Jun 15, 2020

Bi-Directional has_and_belongs_to_many on a Single Model in Rails

Bi-directional HABTM relationships are easy in Rails, but when you need to do it on a single model, that's when it gets tricky. Here's one approach.

May 04, 2015

Access A Deleted Class In A Rails Migration

Sometimes you need to get to a class that you have deleted or renamed within a migration file. Here's how you do it.

Mar 13, 2016