Skip to content

Instantly share code, notes, and snippets.

@zeisler
Created March 15, 2019 21:52
Show Gist options
  • Save zeisler/72c7975de980d37d0675446573cb4a3e to your computer and use it in GitHub Desktop.
Save zeisler/72c7975de980d37d0675446573cb4a3e to your computer and use it in GitHub Desktop.
CLI for managing Rails Migrations
#!/usr/bin/env ruby
require "./config/environment"
require "active_record/migration"
require "tty-prompt"
migration = TTY::Prompt.new(interrupt: :exit)
migration_version = migration.select("Select Migration", filter: true) do |menu|
ActiveRecord::Base.connection.migration_context.migrations_status.reverse.each do |status, version, name|
menu.choice "#{status.center(8)} #{version.ljust(14)} #{name}", version
end
end
migration_action = migration.select("Version: #{ActiveRecord}", filter: true) do |menu|
menu.choice "migrate", "db:rollback"
menu.choice "rollback", "db:rollback"
menu.choice "redo", "db:migrate:redo"
end
system("VERSION=#{migration_version} rails #{migration_action}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment