Compare commits
No commits in common. "7429407843e370fd2577e93278d5235dbb3ccd13" and "1e625b07757a0229014010f4048d6c143332d5e3" have entirely different histories.
7429407843
...
1e625b0775
25
ormconfig.ts
25
ormconfig.ts
@ -1,13 +1,12 @@
|
|||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
config();
|
config();
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
type: process.env.DB_TYPE,
|
type: process.env.DB_TYPE,
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
port: process.env.DB_PORT,
|
port: process.env.DB_PORT,
|
||||||
username: process.env.DB_USER,
|
username: process.env.DB_USER,
|
||||||
password: process.env.DB_PASSWORD,
|
password: process.env.DB_PASSWORD,
|
||||||
database: process.env.DB_NAME,
|
database: process.env.DB_NAME,
|
||||||
entities: ["src/models/entities/*.ts"],
|
entities: ["src/models/entities/*.ts"]
|
||||||
seeds: ['src/seeds/*.ts'],
|
};
|
||||||
};
|
|
||||||
|
@ -42,7 +42,6 @@
|
|||||||
"swagger-ui-express": "^4.1.5",
|
"swagger-ui-express": "^4.1.5",
|
||||||
"typeorm": "^0.2.29",
|
"typeorm": "^0.2.29",
|
||||||
"typeorm-routing-controllers-extensions": "^0.2.0",
|
"typeorm-routing-controllers-extensions": "^0.2.0",
|
||||||
"typeorm-seeding": "^1.6.1",
|
|
||||||
"uuid": "^8.3.1"
|
"uuid": "^8.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -72,8 +71,7 @@
|
|||||||
"docs": "typedoc --out docs src",
|
"docs": "typedoc --out docs src",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watchAll",
|
"test:watch": "jest --watchAll",
|
||||||
"test:ci": "start-server-and-test dev http://localhost:4010/api/openapi.json test",
|
"test:ci": "start-server-and-test dev http://localhost:4010/api/openapi.json test"
|
||||||
"seed": "ts-node ./node_modules/typeorm/cli.js schema:sync && ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"
|
|
||||||
},
|
},
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
import { createConnection } from "typeorm";
|
import { createConnection } from "typeorm";
|
||||||
import { runSeeder } from 'typeorm-seeding';
|
|
||||||
import { User } from '../models/entities/User';
|
|
||||||
import SeedUsers from '../seeds/SeedUsers';
|
|
||||||
/**
|
/**
|
||||||
* Loader for the database that creates the database connection and initializes the database tabels.
|
* Loader for the database that creates the database connection and initializes the database tabels.
|
||||||
*/
|
*/
|
||||||
export default async () => {
|
export default async () => {
|
||||||
const connection = await createConnection();
|
const connection = await createConnection();
|
||||||
await connection.synchronize();
|
connection.synchronize();
|
||||||
if (await connection.getRepository(User).count() === 0) {
|
|
||||||
await runSeeder(SeedUsers);
|
|
||||||
}
|
|
||||||
return connection;
|
return connection;
|
||||||
};
|
};
|
@ -1,20 +0,0 @@
|
|||||||
import { Connection } from 'typeorm';
|
|
||||||
import { Factory, Seeder } from 'typeorm-seeding';
|
|
||||||
import { CreateUser } from '../models/actions/CreateUser';
|
|
||||||
import { User } from '../models/entities/User';
|
|
||||||
|
|
||||||
export default class SeedUsers implements Seeder {
|
|
||||||
public async run(factory: Factory, connection: Connection): Promise<any> {
|
|
||||||
let initialUser = new CreateUser();
|
|
||||||
initialUser.firstname = "demo";
|
|
||||||
initialUser.lastname = "demo";
|
|
||||||
initialUser.username = "demo";
|
|
||||||
initialUser.password = "demo";
|
|
||||||
await connection
|
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(User)
|
|
||||||
.values([await initialUser.toUser()])
|
|
||||||
.execute()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user