Skip to content

Instantly share code, notes, and snippets.

@mattscilipoti
Created April 29, 2010 19:39
Show Gist options
  • Select an option

  • Save mattscilipoti/384115 to your computer and use it in GitHub Desktop.

Select an option

Save mattscilipoti/384115 to your computer and use it in GitHub Desktop.
if 'SQLite' == ActiveRecord::Base.connection.adapter_name && !defined?(JRUBY_VERSION) #SQLite3 returns SQLite as well.
raise "You have upgraded rails. These monkey patches may no longer be needed. Please remove, if possible." if RAILS_GEM_VERSION != '2.3.5'
ActiveRecord::ConnectionAdapters::SQLiteAdapter.class_eval do
#Fixes issue dumping schema for files with defined primary key.
#see: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1153-make-schemadumper-dump-primary-keys-not-named-id-correctly-in-sqlite3
def pk_and_sequence_for(table_name) #:nodoc:
[primary_key(table_name), nil]
end
end
ActiveRecord::ConnectionAdapters::SQLiteAdapter.class_eval do
# Tables should not 'remember' ids, after truncation
# autoincrement, for sqlite3, does NOT indicate that the key should be incremented
# from: http://www.sqlite.org/faq.html
#Short answer: A column declared INTEGER PRIMARY KEY will autoincrement.
#Here is the long answer: If you declare a column of a table to be INTEGER PRIMARY KEY, then whenever you insert a NULL into that column of the table, the NULL is automatically converted into an integer which is one greater than the largest value of that column over all other rows in the table, or 1 if the table is empty. (If the largest possible integer key, 9223372036854775807, then an unused key value is chosen at random.)
def supports_autoincrement?
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment