Last active
August 24, 2018 03:47
-
-
Save fujimura/45809bea1af871a08edcb607214a8046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cli/ui' | |
unless ActiveRecord::SchemaMigration.table_exists? | |
abort "Schema migrations table does not exist yet." | |
end | |
def migrations | |
ActiveRecord::Base.connection.migration_context.migrations_status.map do |status, version, name| | |
"#{status.ljust(8)} #{version.ljust(14)} #{name}" | |
end | |
end | |
while migration = CLI::UI.ask('Select migration', options: [*migrations.last(10), 'EXIT']) | |
exit 0 if migration == 'EXIT' | |
operation = CLI::UI.ask("Select Operation for '#{migration}'", options: ['up', 'down']) | |
_, version = migration.split | |
ActiveRecord::Base.connection.migration_context.run( | |
operation.to_sym, | |
version.to_i | |
) | |
Rails.application.load_tasks | |
Rake::Task['db:_dump'].invoke | |
end |
Author
fujimura
commented
Aug 24, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment