Restart identity not working for me
Closed this issue · 3 comments
joelanman commented
Hi, thanks for this project!
It might be my mistake, but when I use knex-cleaner before each unit test, the tables are getting deleted but the id does not seem to reset. I seed one user in my table (expect id=1) but when I select it from the db in a test, it is 10 or 11. Presumably the other tests are incrementing it.
const knexCleanConfig = {
mode: 'delete',
restartIdentity: true,
ignoreTables: ['knex_migrations', 'knex_migrations_lock']
}
then beforeEach test:
await knexCleaner.clean(knex, knexCleanConfig)
await knex('users').insert([
{
username: 'test',
email: 'test@example.com',
name: 'Test Name'
}
])
the code to create the column:
table.specificType(
'id',
'integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
)
steven-ferguson commented
What database are you using? Currently restartIdentity
is only supported on Postgres.
joelanman commented
Sorry yes Postgres 16
joelanman commented
Not sure what happened but it's not doing it any more, sorry! If it happens again I'll try and make a better test case and reopen. Thanks again!