Code Monkey home page Code Monkey logo

Comments (6)

bmabey avatar bmabey commented on May 20, 2024

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:

earnold@98d324a

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.

earnold avatar earnold commented on May 20, 2024

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.

earnold avatar earnold commented on May 20, 2024

Sorry! Didn't mean to close this!

from database_cleaner.

jhollinger avatar jhollinger commented on May 20, 2024

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.

sobrinho avatar sobrinho commented on May 20, 2024

@bmabey this issue can be closed due to #84 ;)

from database_cleaner.

bmabey avatar bmabey commented on May 20, 2024

Thanks!

from database_cleaner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.