chore: don't seed user if already seeded

This commit is contained in:
Ali BARIN
2022-09-05 00:00:03 +02:00
parent 10dcccf99f
commit a5b3a68588

View File

@@ -12,8 +12,14 @@ export async function createUser(email = 'user@automatisch.io', password = 'samp
}; };
try { try {
const userCount = await User.query().resultSize();
if (userCount === 0) {
const user = await User.query().insertAndFetch(userParams); const user = await User.query().insertAndFetch(userParams);
logger.info(`User has been saved: ${user.email}`); logger.info(`User has been saved: ${user.email}`);
} else {
logger.info('No need to seed a user.');
}
} catch (err) { } catch (err) {
if ((err as any).nativeError.code !== UNIQUE_VIOLATION_CODE) { if ((err as any).nativeError.code !== UNIQUE_VIOLATION_CODE) {
throw err; throw err;