1

I am using cockroachDB for my app.

One of schemas have incremental id (from 1). I made sequence for that table and use the sequence for primary key.

The problem is that this sequence does not reset unless I drop database and create it.

So my questions are Is it possible to do reset this sequence everytime I run test? or Is it only possible to do it if I drop and create database everytime I run test?

Thank you in advance.

D.R
  • 829
  • 4
  • 16
  • 30

2 Answers2

1

CockroachDB supports the setval() function to reset the value of a sequence.

But also remember that sequences do not guarantee that there will be no gaps (transactions that roll back can leave gaps in the sequence that were never used), so your application should not assume that values start at 1 without skipping anything. If you don't reset the sequence, it's the same as having a very large gap at the beginning of your test suite.

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
0

I am pretty sure the only way to accomplish that is to indeed "drop and create database everytime I run test"

Here is a reference - How to rollback, reset, or drop Ecto test database?

benco
  • 29
  • 9