Skip to content

Instantly share code, notes, and snippets.

@marianposaceanu
Last active December 17, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marianposaceanu/5649505 to your computer and use it in GitHub Desktop.
Save marianposaceanu/5649505 to your computer and use it in GitHub Desktop.
Rails tips

Rails tips

Session count

f = ActiveRecord::Base.connection.execute("SELECT COUNT(id) FROM db_sessions")
f.each { |ff| p ff }

Recreate schema_migrations table

Dir.open('db/migrate').each do |fname|
  i = fname.split('_').first.to_i
  next if i == 0
  ActiveRecord::Base.connection.execute("INSERT INTO schema_migrations (version) VALUES(#{i})")
end

Small tips related to migrate

I always forget the db:migrate API.

rake db:migrate:redo VERSION=my_version
db:migrate:up VERSION=my_version
db:migrate:down VERSION=my_version  

Credits

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