2020-11-27 17:28:42 +00:00
|
|
|
import { createConnection } from "typeorm";
|
2020-12-11 18:29:23 +00:00
|
|
|
import { runSeeder } from 'typeorm-seeding';
|
|
|
|
import { User } from '../models/entities/User';
|
|
|
|
import SeedUsers from '../seeds/SeedUsers';
|
2020-12-05 18:09:08 +00:00
|
|
|
/**
|
|
|
|
* Loader for the database that creates the database connection and initializes the database tabels.
|
2020-12-20 18:01:03 +00:00
|
|
|
* It also triggers the seeding process if no users got detected in the database.
|
2020-12-05 18:09:08 +00:00
|
|
|
*/
|
2020-11-27 17:28:42 +00:00
|
|
|
export default async () => {
|
2020-11-25 17:51:48 +00:00
|
|
|
const connection = await createConnection();
|
2020-12-11 18:29:23 +00:00
|
|
|
await connection.synchronize();
|
|
|
|
if (await connection.getRepository(User).count() === 0) {
|
|
|
|
await runSeeder(SeedUsers);
|
|
|
|
}
|
2020-11-25 17:51:48 +00:00
|
|
|
return connection;
|
2020-11-25 17:31:06 +00:00
|
|
|
};
|