Created
February 24, 2014 08:28
-
-
Save seyhunak/9183850 to your computer and use it in GitHub Desktop.
Rails - Reset sequence based on ActiveRecord connection adapter
This file contains 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
# Interest.destroy_all | |
case ActiveRecord::Base.connection.adapter_name | |
when 'SQLite' | |
update_seq_sql = "update sqlite_sequence set seq = 0 where name = 'interests';" | |
ActiveRecord::Base.connection.execute(update_seq_sql) | |
when 'PostgreSQL' | |
ActiveRecord::Base.connection.reset_pk_sequence!('interests') | |
when 'Mysql2' | |
update_seq_sql = "ALTER TABLE interests AUTO_INCREMENT = 1;" | |
ActiveRecord::Base.connection.execute(update_seq_sql) | |
puts "Table 'interests' sequence resetted..." | |
else | |
raise "Task not implemented for this DB adapter" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment