-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveRecord/sqlite3 truncation strategy & sqlite_sequence #66
Comments
On 7/11/11 11:35 AM, earnold wrote:
|
In short, "SQLite keeps track of the largest ROWID that a table has ever held using the special SQLITE_SEQUENCE table." Therefore, if you have an entity called lawyers and you create a new one, Sqlite gives it a new ID +1 over the number on the sqlite_sequence table. When you truncate this table, it effectively says that no entities have ever been created (which is more or less true, given the total truncation). Full details: http://www.sqlite.org/autoinc.html |
Sorry! Didn't mean to close this! |
I second this! In my apps I have been monkey-patching database_cleaner with the following code to get the expected behavior (i.e. table ids being reset to 1, like MySQL's TRUNCATE command does):
Since SQLite has no TRUNCATE command, the only way to duplicate MySQL's (desirable) behavior is to delete a table's row from sqlite_sequence. I'd be happy to submit a patch, though since it would only be one line, it's probably just as easy for anyone to do it. |
Thanks! |
I'm using sqlite and ActiveRecord and the truncation strategy, and I noticed there was some funny behavior with sqlite_sequence not getting cleared. (I have some seed data with hard coded IDs, thus the problem.) I can't think of any reason why this table shouldn't be cleared, and likewise, it DOES get cleared if you use the transaction strategy. I think these two strategies should have the same effective result.
I created a small work-around for this:
earnold@98d324a
Does it seem appropriate for you?
Thanks,
Evan
The text was updated successfully, but these errors were encountered: