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.

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

#6178

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 UnknownMigrationVersionError.new(@target_version) if target.nil?
      unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))
        target.migrate(@direction)
        record_version_state_after_migrating(target.version)
      end
    end

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
        raise UnknownMigrationVersionError.new(@target_version)
      end
...
        # 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
          next
        end

        begin
          ddl_transaction do
            migration.migrate(@direction)
            record_version_state_after_migrating(migration.version)
          end
        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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. rails
    rails
    • 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.

    March 17th, 2011 @ 12:00 AM

  2. rails
    rails
    • State changed from open to stale

    March 17th, 2011 @ 12:00 AM