Skip to content

ResetAsync doens't reset IDENTITY on Postgres #141

@snebjorn

Description

@snebjorn

In postgres TRUNCATE TABLE doesn't reset the identity by default.

When running respawn.ResetAsync(conn) this sql is executed:

truncate table <list of tables> cascade;

builder.AppendLine($"truncate table {string.Join(",", allTables)} cascade;");

To make it reset the identity this needs to be executed:

truncate table <list of tables> restart identity cascade;

Here's a workaround for anyone else stumbling over this:

// workaround for Respawn not resetting identity 
// await _respawner.ResetAsync(connection);
var sql = _respawner.DeleteSql?.Replace("cascade", "restart identity cascade");
var cmd = connection.CreateCommand();
cmd.CommandText = sql;
await cmd.ExecuteNonQueryAsync();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions