Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rake db:migrate queries the schema_migrations table many times (unnecessarily?)

#845

Here's the log when running "rake db:migrate" when there are 4 migrations in the db/migrate folder (all have already been run).


  SQL (0.008272)   SELECT version FROM schema_migrations
  SQL (0.000360)   SELECT version FROM schema_migrations
  SQL (0.000286)   SELECT version FROM schema_migrations
  SQL (0.000271)   SELECT version FROM schema_migrations
Migrating to CreateSessions (20080812190111)
  SQL (0.000289)   SELECT version FROM schema_migrations
Migrating to CreateUsers (20080812190627)
  SQL (0.000256)   SELECT version FROM schema_migrations
Migrating to AddDefaultUser (20080812205823)
  SQL (0.000256)   SELECT version FROM schema_migrations
Migrating to AddUsersAdmin (20080813112503)
  SQL (0.000266)   SELECT version FROM schema_migrations
  SQL (0.000309)   SELECT version FROM schema_migrations

It appears to be fetching the list of versions once per migration file found in db/migrate, and then some.

This isn't too bad with only a handful of migrations, but older, larger projects with hundreds of migrations can take a while to run, even if you're up to date. The db:migrate task could be smarter and only fetch the versions once at start.

Reported by Jeremy Weiskotten · August 25th, 2008 @ 04:59 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Tarmo Tänav
    Tarmo Tänav
    • Tag set to activerecord, migrations

    Please test the attached patch

    August 26th, 2008 @ 03:00 AM

  2. Repository
    Repository
    • State changed from new to resolved
    • Tag changed from activerecord, migrations to activerecord, migrations, patch

    (from [3d2ac918b987ef0cff34f6a7fdd20926b7a9e5d9]) Cache migrated versions list in Migrator and use it to fetch the latest migrated version name [#845 rake db:migrate queries the schema_migrations table many times (unnecessarily?) state:resolved]

    Also optimized Migrator#current_version class method to fetch only the latest version number and not all of them.

    With this change no matter how many migrations there are the schema_migrations table is only SELECTed from once.

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    August 26th, 2008 @ 06:04 AM

  3. Repository
    Repository

    (from [7d2b72f3ae6f92e61d131349c4580be0d1dd12ca]) Cache migrated versions list in Migrator and use it to fetch the latest migrated version name [#845 rake db:migrate queries the schema_migrations table many times (unnecessarily?) state:resolved]

    Also optimized Migrator#current_version class method to fetch only the latest version number and not all of them.

    With this change no matter how many migrations there are the schema_migrations table is only SELECTed from once.

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    August 26th, 2008 @ 06:04 AM