Skip to main content

Benjamin Oakes

Photo of Ben Oakes

Hi, I'm Ben Oakes and this is my geek blog. Currently, I'm a Software Developer at Hedgeye. Previously, I was a Research Assistant in the Early Social Cognition Lab at Yale University and a student at the University of Iowa. I also organize NewHaven.rb. I do development with Ruby, JavaScript, SQL, HTML, and CSS. I have an amazing fiancée named Danielle Smith.

Blocking migration creation in Rails

by Ben

We have a project that accesses a shared database. To prevent problems (and confusion) we wanted to block the creation of migrations in the “secondary” applications so that there was one authoritative place for migrations to live.

It’s easy to accomplish in a simple way.

If you’ve never made any migrations in the secondary application, just do this:

$ echo "NOTE Please do not make migrations in this project.  They should all live in _primary app_." > db/migrate

That way, when you run rails g migration foo, you’ll get this:

$ rails g migration foo
      invoke  active_record
      create    db/migrate/20111129162804_foo.rb
[...]/ruby-1.9.2-p180/lib/ruby/1.9.1/fileutils.rb:243:in `mkdir': File exists - [...]/db/migrate (Errno::EEXIST)

When you try to cd into that directory, you’ll get this:

$ cd db/migrate
bash: cd: db/migrate: Not a directory

After you get over the initial “wha?” reaction, you’ll look at db/migrate and see the message:

$ cat db/migrate
NOTE Please do not make migrations in this project.  They should all live in _primary app_.

Pretty nice, right?

Comments

You can leave a comment, or trackback from your site. Article comments

Leave a comment