#672 open
Betelgeuse

Migration generator index code should check the field exists

Reported by Betelgeuse | March 13th, 2010 @ 10:57 AM | in Hobo 1.4

betelgeuse@pena ~/hobo/hobo-loop $ ./script/generate hobo_migration

---------- Up Migration ----------
add_index :models, [:foo, :bar]
----------------------------------

---------- Down Migration --------
remove_index :models, :name => :index_models_on_foo_and_bar rescue ActiveRecord::StatementInvalid
----------------------------------
What now: [g]enerate migration, generate and [m]igrate now or [c]ancel? m

Migration filename:
(you can type spaces instead of '_' -- every little helps)
Filename [hobo_migration_4]: 
      exists  db/migrate
      create  db/migrate/20100313105517_hobo_migration_4.rb
(in /home/betelgeuse/hobo/hobo-loop)
==  HoboMigration4: migrating =================================================
-- add_index(:models, [:foo, :bar])
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table models has no column named foo: CREATE  INDEX "index_models_on_foo_and_bar" ON "models" ("foo", "bar")

(See full trace by running task with --trace)

The migration should not be generated when the column doesn't exist.

Comments and changes to this ticket

  • Matt Jones

    Matt Jones March 14th, 2010 @ 05:17 PM

    • Milestone set to Hobo 1.1
    • Tag changed from migration-generator to defect, migration-generator
    • State changed from “new” to “open”
    • Assigned user set to “Matt Jones”

    Thanks for catching this - I'll take a look. There's actually several edge cases we miss when generating/removing indexes; for instance, most DBs will automatically drop an index on a removed/renamed column.

  • Matt Jones

    Matt Jones September 21st, 2011 @ 04:16 PM

    • Milestone changed from Hobo 1.1 to Hobo 1.4
    • Milestone order changed from “0” to “0”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

Pages