diff --git a/packages/server/modules/core/migrations/20240710154658_user_emails_backfill.ts b/packages/server/modules/core/migrations/20240710154658_user_emails_backfill.ts index a29d97572..22bbba222 100644 --- a/packages/server/modules/core/migrations/20240710154658_user_emails_backfill.ts +++ b/packages/server/modules/core/migrations/20240710154658_user_emails_backfill.ts @@ -9,18 +9,20 @@ export async function up(knex: Knex): Promise { tableName: 'users', batchSize })) { - await knex('user_emails') - .insert( - rows.map((user) => ({ - id: crs({ length: 10 }), - userId: user.id, - email: user.email, - verified: user.verified, - primary: true - })) - ) - .onConflict(['userId', 'email']) - .ignore() + if (rows.length) { + await knex('user_emails') + .insert( + rows.map((user) => ({ + id: crs({ length: 10 }), + userId: user.id, + email: user.email, + verified: user.verified, + primary: true + })) + ) + .onConflict(['userId', 'email']) + .ignore() + } } } diff --git a/packages/server/modules/core/tests/integration/scanTable.spec.ts b/packages/server/modules/core/tests/integration/scanTable.spec.ts index 3e422cde6..914db0034 100644 --- a/packages/server/modules/core/tests/integration/scanTable.spec.ts +++ b/packages/server/modules/core/tests/integration/scanTable.spec.ts @@ -13,6 +13,10 @@ import { const scanTable = scanTableFactory({ db }) describe('Helpers scanTable @core', () => { + before(async () => { + await db(Users.name).delete() + }) + it('should scan table', async () => { const users = Array.from(Array(10)).map(() => ({ id: crs({ length: 6 }),