heroku_san icon indicating copy to clipboard operation
heroku_san copied to clipboard

Should not restart if migrate does nothing

Open jqr opened this issue 15 years ago • 5 comments
trafficstars

jqr avatar Mar 22 '10 19:03 jqr

+1

kmayer avatar Mar 04 '12 04:03 kmayer

+1 on this too.

fj avatar Sep 26 '12 01:09 fj

+1

himynameisjonas avatar Oct 24 '12 19:10 himynameisjonas

+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

lyahdav avatar Jun 07 '13 23:06 lyahdav

+1

aaronchi avatar Jun 29 '13 07:06 aaronchi