Comments (6)
On 7/11/11 11:35 AM, earnold wrote:
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:
Does it seem appropriate for you?
Thanks,
Evan
I'm not too familiar with sqlite.. what is special about the
sqlite_sequence table?
from database_cleaner.
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
from database_cleaner.
Sorry! Didn't mean to close this!
from database_cleaner.
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):
class DataMapper::Adapters::SqliteAdapter
alias_method :broken_truncate_table, :truncate_table
def truncate_table(table_name)
broken_truncate_table(table_name)
execute("DELETE FROM sqlite_sequence") # Reset the table's ids
end
end
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.
from database_cleaner.
@bmabey this issue can be closed due to #84 ;)
from database_cleaner.
Thanks!
from database_cleaner.
Related Issues (20)
- Ruby 3 compatibility HOT 9
- Deprecation Warning on 2.7 HOT 4
- Poor strategy class lookup HOT 1
- DatabaseCleaner triggering `before` hook while threads are still running HOT 2
- url_allowlist only works against DATABASE_URL HOT 1
- Data
- uninitialized constant ActiveRecord::DatabaseConfigurations::ConnectionUrlResolver::URI HOT 2
- Remote database is wiped out HOT 2
- API documentation is empty HOT 1
- YAML aliases with Ruby 3.1 HOT 8
- Hand soap HOT 1
- NoMethodError: undefined method 'state' for nil:NilClass HOT 7
- Change strategy for specific test
- 0.0.0.0 doesn't count as a local host HOT 2
- Rspec tests freeze as soon as DatabaseCleaner begins to work HOT 1
- Feature spec should complete after showing the result
- Prevent cleaning of development database HOT 1
- Highly variable duration of truncations (not a database_cleaner issue)
- Deprecation warning on: DatabaseCleaner.clean_with(:truncation) HOT 1
- Reading Database config from database.yml HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from database_cleaner.