Run a single migration file

后端 未结 11 750
说谎
说谎 2020-11-30 16:01

Is there an easy way to run a single migration? I don\'t want to migrate to a certain version I just want to run a specific one.

11条回答
  •  猫巷女王i
    2020-11-30 17:04

    If you've implemented a change method like this:

    class AddPartNumberToProducts < ActiveRecord::Migration
      def change
        add_column :products, :part_number, :string
      end
    end
    

    You can create an instance of the migration and run migrate(:up) or migrate(:down) on an instance, like this:

    $ rails console
    >> require "db/migrate/20090408054532_add_part_number_to_products.rb"
    >> AddPartNumberToProducts.new.migrate(:down)
    

提交回复
热议问题