diff --git a/backend/src/db/seeders/20200430130759-admin-user.ts b/backend/src/db/seeders/20200430130759-admin-user.ts index f794318..4c8b16e 100644 --- a/backend/src/db/seeders/20200430130759-admin-user.ts +++ b/backend/src/db/seeders/20200430130759-admin-user.ts @@ -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) => {