I have a website that I’ve been using to track timesheets for a number of people. It’s one of the first websites I wrote in rails, written about four years ago. The only person who really uses it is me, but a few other people also login to view the information. Anyway, the site was written in rails 3.2.11 and now the latest version is 4.2. I’ve decided that since I know a bit more rails now (I wouldn’t say I’m a good programmer), I’d rewrite the program. It’s not that elaborate, but it does work really well for me.

Anyway, after getting the database set up on my laptop, I thought that I’d copy the current data from the server to my laptop. This was pretty easy to do with mysqldump.

$ /usr/bin/mysqldump --opt rails_db -u user1 -p > rails_db.sql

I then brought the sql file to my laptop and loaded it into the database.

$ mysql -u user1 -p rails_db < rails_db.sql

This worked great. However, I then had the idea to add another field to one of my tables. I made a migration, but when I tried to run it things didn’t work. I basically got a message that there were other migrations that needed to run. A quick look at the database shows the problem.

Before loading the old sql file, the schema_migrations table looked like this:

| version        |
| 20150205145024 |
| 20150210163003 |
| 20150210200817 |
| 20150210210129 |
| 20150211152635 |

After loading the old database, the schema_migrations table looked like this.

| version        |
| 20111201141509 |
| 20111202204541 |
| 20111203022621 |
| 20111206141445 |
| 20111206141755 |

All of my migration files had the versions from 2015. So I needed to change these values. And I did it by simply running the following command a once for each entry.

mysql> update schema_migrations set version='20150205145024' where version="20111201141509";