loomio/loomio — pull request #1239 by s01us (2014-01-01 23:34:41+00:00)
Title: Fix migrations

## how to fix a migration (of type renamed model)

I had a staging sever where I was trying to set up a db from fresh.
Here's the migration error :
```
== AddColumnDiscussionIdToMotionReadLog: migrating ===========================
-- add_column(:motion_read_logs, :discussion_id, :integer)
-> 0.0041s
rake aborted!
An error has occurred, this and all later migrations canceled:

uninitialized constant AddColumnDiscussionIdToMotionReadLog::MotionReadLog/app/db/migrate/20120510004528_add_column_discussion_id_to_motion_read_log.rb:4:in `up'
```

the offending file:
```ruby
class AddColumnDiscussionIdToMotionReadLog < ActiveRecord::Migration
def up
add_column :motion_read_logs, :discussion_id, :integer
MotionReadLog.reset_column_information
MotionReadLog.all.each do |log|
motion = Motion.find_by_id(log.motion_id)

...
```

#### the problem:
the model `MotionReadLog` doesn't exist, because in the current code the it has been renamed (several times) and ended up at `MotionReader`.

the calls `MotionReadLog.reset_column_information` and `MotionReadLog.all` in the migration would normally use ActiveRecord::Base magic to look for a table called `motion_read_logs` ... but because the model doesn't exist, the magic fails.

#### quick fix:

fake the model
```ruby
class AddColumnDiscussionIdToMotionReadLog < ActiveRecord::Migration
class MotionReadLog < ActiveRecord::Base #this helps migration find table
end

def up
add_column :motion_read_logs, :discussion_id, :integer
MotionReadLog.reset_column_information
MotionReadLog.all.each do |log|
motion = Motion.find_by_id(log.motion_id)
if motion

...
```