Skip to content

Instantly share code, notes, and snippets.

@fujimura
Last active August 24, 2018 03:47
Show Gist options
  • Save fujimura/45809bea1af871a08edcb607214a8046 to your computer and use it in GitHub Desktop.
Save fujimura/45809bea1af871a08edcb607214a8046 to your computer and use it in GitHub Desktop.
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
@fujimura
Copy link
Author

im

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment