DEV Community

Michel Sánchez Montells
Michel Sánchez Montells

Posted on

2 1

Run a specific migration

Sometimes we search how to do something. We find out the correct answer, we use the tip and we forget how to do it again because this situation is not frequent at all.

This entry is just for having my own memory and easy search something that I am sure will be removed from my brain soon.

There is not common but can happen that you need to run an specific migration and don't want to run the subsequent migrations.

Let's go:

require "{Rails.root.to_s}/db/migrate/20090408054532_add_foos.rb""
AddFoos.new.migrate(:up)
Enter fullscreen mode Exit fullscreen mode

In details...

Identify the migration

20090408054532_add_foos.rb

  • Open console

rails c

  • Require the migration

require "#{Rails.root.to_s}/db/migrate/20090408054532_add_foos.rb"

  • Run the migration

AddFoos.new.migrate(:up)

DONE ;-)

visit: https://stackoverflow.com/questions/753919/run-a-single-migration-file

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more