-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f540fbd
commit 6ea356c
Showing
46 changed files
with
1,716 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
services: | ||
db: | ||
container_name: nestjs-turbo-postgres | ||
image: postgres:17 | ||
restart: always | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_DB: nestjs_turbo | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
TZ: "UTC" | ||
ports: | ||
- "25432:5432" | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
redis: | ||
image: redis/redis-stack:latest | ||
restart: always | ||
ports: | ||
- "6379:6379" | ||
- "8001:8001" | ||
volumes: | ||
- redis_data:/data | ||
healthcheck: | ||
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] | ||
environment: | ||
REDIS_ARGS: "--requirepass redispass" | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
maildev: | ||
build: | ||
context: . | ||
dockerfile: maildev.Dockerfile | ||
ports: | ||
- ${MAIL_CLIENT_PORT}:1080 | ||
- ${MAIL_PORT}:1025 | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
pgadmin: | ||
container_name: pgadmin | ||
image: dpage/pgadmin4 | ||
ports: | ||
- "18080:80" | ||
volumes: | ||
- pgadmin_data:/root/.pgadmin | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: [email protected] | ||
PGADMIN_DEFAULT_PASSWORD: 12345678 | ||
PGADMIN_CONFIG_WTF_CSRF_ENABLED: "False" | ||
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION: "False" | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
volumes: | ||
postgres_data: | ||
pgadmin_data: | ||
redis_data: | ||
|
||
networks: | ||
nestjs-turbo-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
services: | ||
db: | ||
container_name: nestjs-turbo-mysql | ||
image: mysql | ||
restart: always | ||
volumes: | ||
- mysql_data:/var/lib/mysql | ||
environment: | ||
MYSQL_DATABASE: realworld_api | ||
MYSQL_ROOT_PASSWORD: 12345678 | ||
ports: | ||
- "13306:3306" | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
redis: | ||
image: redis/redis-stack:latest | ||
restart: always | ||
ports: | ||
- "6379:6379" | ||
- "8001:8001" | ||
volumes: | ||
- redis_data:/data | ||
healthcheck: | ||
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] | ||
environment: | ||
REDIS_ARGS: "--requirepass redispass" | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
maildev: | ||
build: | ||
context: . | ||
dockerfile: maildev.Dockerfile | ||
ports: | ||
- ${MAIL_CLIENT_PORT}:1080 | ||
- ${MAIL_PORT}:1025 | ||
networks: | ||
- nestjs-turbo-network | ||
|
||
volumes: | ||
mysql_data: | ||
redis_data: | ||
|
||
networks: | ||
nestjs-turbo-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/realworld-api/src/database/mysql-typeorm-config.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { AllConfigType } from '@/config/config.type'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm'; | ||
import { join } from 'path'; | ||
|
||
@Injectable() | ||
export class TypeOrmConfigService implements TypeOrmOptionsFactory { | ||
constructor(private configService: ConfigService<AllConfigType>) {} | ||
|
||
createTypeOrmOptions(): TypeOrmModuleOptions { | ||
const modulePath = require.resolve('@repo/mysql-typeorm'); | ||
const nodeModulesDir = join(modulePath, '..', '..'); | ||
|
||
return { | ||
type: this.configService.get('database.type', { infer: true }), | ||
host: this.configService.get('database.host', { infer: true }), | ||
port: this.configService.get('database.port', { infer: true }), | ||
username: this.configService.get('database.username', { infer: true }), | ||
password: this.configService.get('database.password', { infer: true }), | ||
database: this.configService.get('database.name', { infer: true }), | ||
synchronize: this.configService.get('database.synchronize', { | ||
infer: true, | ||
}), | ||
dropSchema: false, | ||
keepConnectionAlive: true, | ||
logger: 'debug', | ||
entities: [join(nodeModulesDir, 'dist', '**', '*.entity.{ts,js}')], | ||
poolSize: this.configService.get('database.maxConnections', { | ||
infer: true, | ||
}), | ||
ssl: this.configService.get('database.sslEnabled', { infer: true }) | ||
? { | ||
rejectUnauthorized: this.configService.get( | ||
'database.rejectUnauthorized', | ||
{ infer: true }, | ||
), | ||
ca: | ||
this.configService.get('database.ca', { infer: true }) ?? | ||
undefined, | ||
key: | ||
this.configService.get('database.key', { infer: true }) ?? | ||
undefined, | ||
cert: | ||
this.configService.get('database.cert', { infer: true }) ?? | ||
undefined, | ||
} | ||
: undefined, | ||
} as TypeOrmModuleOptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
##== Environment | ||
NODE_ENV=development | ||
|
||
##== Database | ||
DATABASE_TYPE=mysql | ||
DATABASE_HOST=localhost | ||
DATABASE_PORT=3306 | ||
DATABASE_USERNAME=root | ||
DATABASE_PASSWORD=12345678 | ||
DATABASE_LOGGING=true | ||
DATABASE_SYNCHRONIZE=false | ||
DATABASE_MAX_CONNECTIONS=100 | ||
DATABASE_SSL_ENABLED=false | ||
DATABASE_REJECT_UNAUTHORIZED=false | ||
DATABASE_CA= | ||
DATABASE_KEY= | ||
DATABASE_CERT= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import prettier from '@repo/eslint-config/prettier-base.config.mjs'; | ||
|
||
export default { ...prettier }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import nest from '@repo/eslint-config/eslint-nest.config.mjs'; | ||
|
||
export default [...nest]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "@repo/mysql-typeorm", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"dev": "pnpm build --watch", | ||
"build": "tsc -b -v", | ||
"lint": "eslint \"{src,test}/**/*.ts\"", | ||
"typeorm": "pnpm clean && env-cmd typeorm-ts-node-commonjs -d src/data-source.ts", | ||
"migration:up": "pnpm typeorm migration:run", | ||
"migration:down": "pnpm typeorm migration:revert", | ||
"migration:show": "pnpm typeorm migration:show", | ||
"migration:create": "typeorm migration:create", | ||
"migration:generate": "pnpm typeorm migration:generate --pretty", | ||
"typeorm-ex": "pnpm clean && pnpm build && env-cmd typeorm-extension", | ||
"db:create": "pnpm typeorm-ex db:create", | ||
"db:drop": "pnpm typeorm-ex db:drop", | ||
"seed:run": "pnpm typeorm-ex seed:run", | ||
"seed:create": "pnpm typeorm-ex seed:create" | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"./dist/**", | ||
"!./dist/factories", | ||
"!./dist/migrations", | ||
"!./dist/seeds" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"./*": { | ||
"types": "./dist/*.d.ts", | ||
"default": "./dist/*.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"@nestjs/config": "^3.3.0", | ||
"@nestjs/mapped-types": "*", | ||
"@repo/nest-common": "workspace:*", | ||
"class-transformer": "^0.5.1", | ||
"class-validator": "^0.14.1", | ||
"env-cmd": "^10.1.0", | ||
"pg": "^8.13.1", | ||
"typeorm": "^0.3.20", | ||
"typeorm-extension": "^3.6.3" | ||
}, | ||
"devDependencies": { | ||
"@repo/eslint-config": "workspace:*", | ||
"@repo/typescript-config": "workspace:*", | ||
"@types/node": "^20.17.2", | ||
"ts-loader": "^9.5.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.6.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export type DatabaseConfig = { | ||
type: string; | ||
host: string; | ||
port: number; | ||
password: string; | ||
name: string; | ||
username: string; | ||
logging: boolean; | ||
synchronize: boolean; | ||
maxConnections: number; | ||
sslEnabled: boolean; | ||
rejectUnauthorized: boolean; | ||
ca?: string; | ||
key?: string; | ||
cert?: string; | ||
}; |
Oops, something went wrong.