Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should not restart if migrate does nothing #5

Open
jqr opened this issue Mar 22, 2010 · 5 comments · May be fixed by #154
Open

Should not restart if migrate does nothing #5

jqr opened this issue Mar 22, 2010 · 5 comments · May be fixed by #154
Labels

Comments

@jqr
Copy link
Owner

jqr commented Mar 22, 2010

No description provided.

@kmayer
Copy link
Contributor

kmayer commented Mar 4, 2012

+1

@fj
Copy link

fj commented Sep 26, 2012

+1 on this too.

@himynameisjonas
Copy link

+1

@lyahdav
Copy link

lyahdav commented Jun 7, 2013

+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

@aaronchi
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants