Sequence problem with drizzle-seed

I'm experiencing an issue where after seeding data into a PostgreSQL table with Drizzle ORM, the sequence (users_id_seq) doesn't update to reflect the highest id inserted. Here are the details: Schema:
export const users = pgTable("users", {
id: serial().primaryKey(),
// ... other fields
});
export const users = pgTable("users", {
id: serial().primaryKey(),
// ... other fields
});
Seeding Script:
async function seedDatabase() {
await reset(db, schema);
await seed(db, schema).refine((f) => {
// Seeding 10 users without manually setting id
});
}
async function seedDatabase() {
await reset(db, schema);
await seed(db, schema).refine((f) => {
// Seeding 10 users without manually setting id
});
}
Problem: I am not be able to insert 11th user manually. After seeding 10 users, SELECT last_value, is_called FROM users_id_seq; shows last_value as 1, not 10 or higher as expected. This causes the duplocated Id issue. Expected Behavior: The sequence should have been updated to the last inserted id after seeding. Current Workaround: I manually reset the sequence with SELECT setval('users_id_seq', (SELECT MAX(id) FROM users));post-seeding to fix the issue. Is there a known issue with how Drizzle handles sequences during bulk seeding, or am I missing something in my setup or seeding approach? Any advice or insights would be greatly appreciated.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server