Open jqr opened 14 years ago
+1 on this too.
+1
+1
I wrote a rake task that we use as part of our build process to put our app in maintenance mode only if there are pending migrations, but it would be nice to leverage this to not even run the migrate & restart steps from heroku_san if there are no pending migrations. Here's the rake task:
task :heroku_pending_migrations, [:app] => :environment do |t, args|
# returns an array of the schema_migrations run on heroku app +app_name+
def get_remote_migrations(app_name)
connection_string = `heroku pg:credentials DATABASE_URL --app #{app_name} | head -2 | tail -1`.strip
`psql #{connection_string} -Atc "SELECT * FROM schema_migrations;"`.split
end
app_name = args[:app]
remote_migrations = get_remote_migrations(app_name)
local_migrations = ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations_paths).migrations
pending_migrations = local_migrations.reject { |m| remote_migrations.include?(m.version.to_s) }
if pending_migrations.present?
puts 'Pending migrations:'
puts pending_migrations.map &:version
exit false
else
puts 'No pending migrations'
exit true
end
end
+1
+1