This project is archived and is in readonly mode.

#6178 ✓stale
Arthur Pirogovski

db:migrate:up and db:migrate:down don't use transactions

Reported by Arthur Pirogovski | December 16th, 2010 @ 03:33 AM

While db:migrate and db:rollback both wrap changes into transactions if database engine supports DDL transactions, db:migrate:up and db:migrate:down don't even try to detect if engine supports this.

Also, the code which handles this is not really very DRY.

up/down tasks are using this piece of code:

    def run
      target = migrations.detect { |m| m.version == @target_version }
      raise if target.nil?
      unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))

migrate/rollback tasks are using this one:

    def migrate
      current = migrations.detect { |m| m.version == current_version }
      target = migrations.detect { |m| m.version == @target_version }

      if target.nil? && !@target_version.nil? && @target_version > 0
        # On our way up, we skip migrating the ones we've already migrated
        next if up? && migrated.include?(migration.version.to_i)

        # On our way down, we skip reverting the ones we've never migrated
        if down? && !migrated.include?(migration.version.to_i)
          migration.announce 'never migrated, skipping'; migration.write

          ddl_transaction do
        rescue => e

Need to:

  • make both up/down and migrate/rollback use the same method

  • ensure up/down/migrate/rollback tasks are using ddl_transaction wrapper

  • backport to 2.x since it is also affected

Comments and changes to this ticket

  • rails

    rails March 17th, 2011 @ 12:00 AM

    • Tag changed from database, databases.rake, migrations, migrator, postgresql, rails3.0.3, sqlite, transactions to database, databasesrake, migrations, migrator, postgresql, rails303, sqlite, transactions
    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails March 17th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”

Create your profile

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

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket