fix: make admin-user seeder idempotent

Skip inserting users that already exist in the database to prevent
duplicate key constraint violations on restarts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Dmitri 2026-06-10 20:50:11 +02:00
parent 3725d0603c
commit 376776620e

View File

@ -76,7 +76,17 @@ export default {
},
];
await queryInterface.bulkInsert('users', rows);
// Check which users already exist to make seeder idempotent
const existing = await queryInterface.sequelize.query<{ id: string }>(
`SELECT id FROM users WHERE id IN (:ids)`,
{ replacements: { ids }, type: 'SELECT' },
);
const existingIds = new Set(existing.map((row) => row.id));
const toInsert = rows.filter((row) => !existingIds.has(row.id as string));
if (toInsert.length > 0) {
await queryInterface.bulkInsert('users', toInsert);
}
},
down: async (queryInterface: QueryInterface) => {