Repetitive migrations for the same columns?

17 views
Skip to first unread message

JezC

unread,
Dec 31, 2011, 9:36:42 PM12/31/11
to Hobo Users
Hi - another repetitive migration issue - Hobo 1.3, Ruby 1.9.2p290,
Rails 3.0.11

hobo generate resource foo status:string
hobo generate resource bar status:string

Field definitions for both include:

status enum_string(:one, :two, :three), :default => :one

You can then run successive "hobo g migration" and it will
persistently re-create the same migration to make status columns with
"active" as a default.

How can I suppress this redundant migration, am I doing the wrong
thing and therefore triggering this because I don't what I'm doing, or
have I found a bug? Help!

Bob Sleys

unread,
Jan 1, 2012, 10:33:17 AM1/1/12
to hobo...@googlegroups.com
When you run the hobo g migration do you choose the option to 'm' to run the migration after creating it?  I believe Hobo just compares the actual database to the models looking for changes so if you only create the migratino files but don't migrate the database it won't "see" the previous migration and do it again.  You need to migrate the database between each hobo g migration iteration and not just create the migration files themselves.

Bob

JezC

unread,
Jan 1, 2012, 11:43:15 AM1/1/12
to Hobo Users
Hi Bob,

yes, I'm using 'm' to apply the migrations.

If I don't, I get a message about having "pending migrations" and I
need to run "bundle exec rake db:migrate" to solve that and allow the
next 'hobo g migration' to work.

Having run "hobo g migration" and accepted the migration with 'm', if
I run 'hobo g migration' again, then hobo wants to add three fields
with default values, again. If I accept that with an 'm', and re-run,
exactly the same thing will happen. I got bored when I reached the 7th
repetition - more than enough proof that it is repeatable, I
think ;) . It happens consistently and persistently for me (using
1.9.2p290, rails 3.0.11, hobo 1.3 - I haven't tried any other
combinations).

Thanks, JeremyC

JezC

unread,
Jan 1, 2012, 11:48:27 AM1/1/12
to Hobo Users
Oops - that should be 'two fields', not 'three fields' as mentioned. I
stumbled into this with a project that had three fields in different
models that do this. I then reproduced in a test app with just the two
models, as described in my initial posting. The example I gave will
only generate two fields where a hobo generated migration repeats the
column set up and drop, repeatedly - so long as you accept the
migrations.

Cheers, JeremyC.

Matt Jones

unread,
Jan 1, 2012, 1:05:27 PM1/1/12
to hobo...@googlegroups.com

On Dec 31, 2011, at 9:36 PM, JezC wrote:

> Hi - another repetitive migration issue - Hobo 1.3, Ruby 1.9.2p290,
> Rails 3.0.11
>
> hobo generate resource foo status:string
> hobo generate resource bar status:string
>
> Field definitions for both include:
>
> status enum_string(:one, :two, :three), :default => :one

Does this still exhibit the same behavior if you write it as:

status enum_string(:one, :two, :three), :default => 'one'

(change the default to a string and not a symbol).

--Matt Jones

JezC

unread,
Jan 1, 2012, 3:47:41 PM1/1/12
to Hobo Users
No extra migrations iff I use ":default => 'one'"

So, yes, a string makes the problem go away. :)

OK, I can finish my models properly now!

Unexpected that I'd have to use a string there, though. Aren't symbols
supposed to be the right thing to use for this?

Thanks for the help.

Cheers, JeremyC.
Reply all
Reply to author
Forward
0 new messages