Skip to content

Reset sequences before loading fixtures (maybe) #34

@davars

Description

@davars

Currently the only time sequences are modified is after fixtures are loaded. I propose that, in addition to the current behavior, to set sequences to 1 before loading fixtures.

When omitting the serial columns from the fixture files, subsequent test runs result in fixture records with serial values greater than ResetSequencesTo. Thus when the sequences are reset, it is reset to a value before the fixture records.

That was confusing to type. Example, run 1:

  id   |       name        
-------+-------------------
     1 | 1) fixture
 10000 | 2) from test
 10001 | 3) also from test

Run 2:

  id   |       name        
-------+-------------------
 10002 | 1) fixture
 10000 | 2) from test
 10001 | 3) also from test

As soon as you increase the number of rows generated by a given run, conflict.

I've worked around this by specifying ids in the fixture files. This is probably a good practice anyway, and the current behavior acts as a reasonable forcing function. An alternative fix for this issue might be simply documenting a best practice of specifying values for serial columns.

A robust fix would be to take the max of the serial columns, though that's a bit more involved. The query in this question would be a good starting point though: https://dba.stackexchange.com/questions/47098/how-do-i-determine-if-a-column-is-defined-as-a-serial-data-type-instead-of-an-in

TLDR, please do one of:

  1. Reset sequences to 1 before loading fixtures then to ResetSequencesTo afterwards.
  2. Update docs to recommend that all serial columns have values and that they be less than ResetSequencesTo
  3. At least in the case of postgres, set ResetSequencesTo automatically using the result of select max(<serial column>)+1 from <schema>.<table>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions