Skip to content

Commit

Permalink
feat: run schema generator on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Frost committed May 6, 2024
1 parent 8437cce commit 9fc9c53
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"db:sync": "mikro-orm schema:update --run"
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@mikro-orm/cli": "^6.2.5",
"@mikro-orm/core": "^6.2.5",
"@mikro-orm/nestjs": "^5.2.3",
"@mikro-orm/postgresql": "^6.2.5",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.2.0",
"@nestjs/mapped-types": "*",
Expand Down Expand Up @@ -77,12 +77,5 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"mikro-orm": {
"useTsNode": true,
"configPaths": [
"./src/mikro-orm.config.ts",
"./dist/mikro-orm.config.js"
]
}
}
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { MikroORM } from '@mikro-orm/core';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module } from '@nestjs/common';
import { PostgreSqlDriver } from '@mikro-orm/postgresql';
import { Module, OnApplicationBootstrap } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { AuthModule } from './auth/auth.module';
Expand All @@ -8,12 +11,32 @@ import { UsersModule } from './users/users.module';
@Module({
imports: [
AuthModule,
MikroOrmModule.forRoot(),
ConfigModule.forRoot(),
MikroOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
entities: ['dist/**/*.entity.js'],
entitiesTs: ['src/**/*.entity.ts'],
host: configService.get('DB_HOST'),
dbName: 'postgres',
user: 'postgres',
password: 'postgres',
driver: PostgreSqlDriver,
}),
inject: [ConfigService],
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'uploads'),
serveRoot: '/uploads',
}),
UsersModule,
],
})
export class AppModule {}
export class AppModule implements OnApplicationBootstrap {
constructor(private orm: MikroORM) {}

async onApplicationBootstrap() {
const generator = this.orm.getSchemaGenerator();
await generator.updateSchema();
}
}
11 changes: 0 additions & 11 deletions src/mikro-orm.config.ts

This file was deleted.

0 comments on commit 9fc9c53

Please sign in to comment.