#100 √ resolved
Evan Dorn

Some insoshi migrations are brittle vs. model changes

Reported by Evan Dorn | July 20th, 2008 @ 10:51 PM

Some of the insoshi migrations declare and use instances of ActiveRecord objects (Person in 013 and 023 and Forum in 005). This is brittle and can cause migrations of new (empty) databases to fail if the appropriate app/models/model.rb file is changed in the future such that it invokes fields not currently in the database as of those migrations.

I have implemented a fix to this bug in the edge branch of my own fork of Insoshi, and will issue a pull request momentarily. (commit 81633e05d3ee83d959d2c4c9afb230692ccc958d of git@github.com:IdahoEv/insoshi.git)

Here's how to quickly reproduce the bug:

git clone git://github.com/insoshi/insoshi.git

cd insoshi

cp config/database.example config/database.yml

git branch --track edge origin/edge

git checkout edge

rake db:migrate #<< Works fine!

## fine so far. But try this:

rake script/generate migration add_foofield_to_person foofield:string

rake db:migrate

$EDITOR app/models/person.rb

## add this line to person.rb:

  1. validates_inclusion_of :foofield

rm db/development.sqlite3

rake db:migrate # FAILS at migration 013!!

## You should see this error:

  1. > rake aborted!
  2. > Validation failed: Foofield can't be blank

The solution is to declare the re-declare the model inside the migration, superseding the declaration in app/models/.rb, and adding only any functionality necessary to make the migration run.

This way when the model is instantiated or invoked inside the migration, it uses a version that does not call any attribute methods that might not exist yet because those fields are not in the database.

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket