Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResetAsync doens't reset IDENTITY on Postgres #141

Open
snebjorn opened this issue Jul 19, 2024 · 0 comments
Open

ResetAsync doens't reset IDENTITY on Postgres #141

snebjorn opened this issue Jul 19, 2024 · 0 comments

Comments

@snebjorn
Copy link

snebjorn commented Jul 19, 2024

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant