Ticket #2119 (closed defect: fixed)
upgrade-master sets auto-increment counters for id fields incorrectly in postgresql
| Reported by: | szager | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 0.8.6 |
| Version: | 0.8.4p1 | Keywords: | database |
| Cc: |
Description
When upgrading master database from 0.7.12 to 0.8.4p1, and creating the new database in postgresql, some of the tables have an 'id' field that uses an auto-increment counter to get a value for newly-added rows; something like this:
CREATE TABLE changes (
changeid PRIMARY KEY DEFAULT nextval('changes_changeid_seq'), ...
);
The problem is that the state of the counter is set incorrectly after the upgrade. For example, I upgraded a database that had 775 change records. The imported change records had the expected sequential changeid values 1-775, but the 'last_value' field of the changes_changeid_seq counter was 20, rather than the expected 775.
I have seen this in the changes.changeid field and the build.id field.
Change History
comment:1 Changed 20 months ago by dustin
- Keywords database added
- Milestone changed from undecided to 0.8.6
comment:2 Changed 16 months ago by dustin
On second thought, I totally see why it would happen -- since all of the inserts into changes specify a changeid, the sequence isn't consulted, nextval is never called, and .. it stays at 1.
So, this should have a testcase, and a solution. Both will need to be conditioned on Postgres, since this is a unique case.
comment:3 Changed 15 months ago by Dustin J. Mitchell
- Status changed from new to closed
- Resolution set to fixed
Set postgres sequence values to allow inserts
This fixes #2119, where the explicit inserts done as Buildbot imports changes from pickles skip the call to nextval('changes_changeid_seq'), and thus leave that sequence value out of sync with the table contents.
Changeset: 0a3c28399e4c74e0d34cc33d8df66c435b991a28
![[Buildbot Logo]](/chrome/site/header-text-transparent.png)
It would be great to have a test that can reproduce this. Off the top of my head, I can't see why this would happen.