chore: don't seed user if already seeded
This commit is contained in:
@@ -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;
|
||||||
|
Reference in New Issue
Block a user