ArTruncator
Now you can do tablename.truncate. This was not incorporated into AR as a patch because SQLite does not support truncate statements. See this pull request for more detail:
https://github.com/rails/rails/issues/5510
I'm releasing this as a gem, so I don't have to add it to my config/initializers.
This has so far only been tested for mysql2 adapater/MySQL DB.
Why truncate versus delete * ? Its more performant and it resets the primary key ID to 1. Useful when you're re-seeding/testing.
Installation
Add this line to your application's Gemfile:
gem 'ar_truncator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ar_truncator
Usage
If you have a model called Dummy, to truncate it do:
Dummy.truncate
This will execute the following sql:
"Truncate tabel Dummies".
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request