Created
November 16, 2016 20:20
-
-
Save joshmvandercom/fff8f00362c21d520aec4abc04ddd06b to your computer and use it in GitHub Desktop.
Fixing out of sync postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :sync_tables => :environment do | |
ActiveRecord::Base.connection.tables.each do |table| | |
unless ['schema_migrations', 'ar_internal_metadata'].include?(table) | |
sql = "SELECT setval('#{table}_id_seq', COALESCE((SELECT MAX(id)+1 FROM #{table}), 1), false);" | |
ActiveRecord::Base.connection.execute(sql) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment