Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6588 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] add AUTOINCREMENT to primary keys in sqlite migrations

Reported by: careo Assigned to: David
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: 1.1.6
Severity: normal Keywords: sqlite autoincrement
Cc: bitsweat

Description

Primary keys created with migrations in Sqlite do not include AUTOINCREMENT. Without it, sqlite uses the highest value + 1 for the new primary key, which can lead to some unfortunate conditions if you've deleted records from the end of a table.

For more information see http://www.sqlite.org/faq.html#q1

Attachments

sqlite_autoincrement.diff (0.8 kB) - added by careo on 11/09/06 17:55:15.

Change History

(follow-up: ↓ 3 ) 11/09/06 07:05:51 changed by bitsweat

  • cc set to bitsweat.
  • keywords set to sqlite autoincrement.

Good point. The changelog shows AUTOINCREMENT keyword support in >= 3.1.0; when/was it added to 2.x?

11/09/06 17:53:15 changed by careo

  • summary changed from [PATHCH] add AUTOINCREMENT to primary keys in sqlite migrations to [PATCH] add AUTOINCREMENT to primary keys in sqlite migrations.

(in reply to: ↑ 1 ) 11/09/06 17:54:29 changed by careo

Replying to bitsweat:

Good point. The changelog shows AUTOINCREMENT keyword support in >= 3.1.0; when/was it added to 2.x?

Doesn't look like it was added. It throws a syntax error in sqlite2 2.8.17.

I've corrected my patch for this.

11/09/06 17:55:15 changed by careo

  • attachment sqlite_autoincrement.diff added.

(follow-up: ↓ 6 ) 11/09/06 20:20:47 changed by bitsweat

I get one test failure since this leads to the creation of a sqlite_sequence table which should be skipped by the schema dumper.

11/09/06 21:17:44 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [5477]) SQLite: use AUTOINCREMENT primary key in >= 3.1.0. Closes #6588.

(in reply to: ↑ 4 ) 11/14/06 01:28:49 changed by lukfugl

Replying to bitsweat:

I get one test failure since this leads to the creation of a sqlite_sequence table which should be skipped by the schema dumper.

I ran into this issue independently running on edge today. I could not "rake test:units" in my project because it generated an SQL error when trying to recreate the sqlite_sequence table. I've created a patch for this: #6616.