Skip to content

Instantly share code, notes, and snippets.

@wireframe
Created January 6, 2014 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wireframe/8286268 to your computer and use it in GitHub Desktop.
Save wireframe/8286268 to your computer and use it in GitHub Desktop.
detect inconsistencies between migrations in codebase and database
db_versions = ActiveRecord::Base.connection.execute('select * from schema_migrations').map {|r| r['version']}
migrations = Dir.glob('db/migrate/*').map {|f| File.basename(f).split('_').first }
unrun_migrations = migrations.reject {|m| db_versions.include?(m) }
unreverted_migrations = db_versions.reject {|v| migrations.include?(v) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment