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?