Browse Source

FEATURE | Old database seed

merge-requests/217/merge
Vitalik 2 years ago
parent
commit
269bf18381
  1. 11
      docker-compose.yml
  2. 6
      src/app.module.ts
  3. 16
      src/config/index.ts
  4. 14
      src/domain/old-database-seed/old-database-seed.module.ts
  5. 2
      src/domain/old-database-seed/services/index.ts
  6. 21
      src/domain/old-database-seed/services/taxonomies.service.ts
  7. 18
      src/domain/old-database-seed/services/test.service.ts
  8. 1
      src/domain/old-database-seed/typing/interfaces/index.ts
  9. 11
      src/domain/old-database-seed/typing/interfaces/old-taxonomies.interfaces.ts
  10. 2
      src/libs/database/database.module.ts

11
docker-compose.yml

@ -76,3 +76,14 @@ services: @@ -76,3 +76,14 @@ services:
IMGPROXY_KEY: ${IMGPROXY_KEY}
IMGPROXY_SALT: ${IMGPROXY_SALT}
IMGPROXY_MAX_SRC_FILE_SIZE: 10485760
taskme-postgres-old:
image: postgres:11
restart: always
ports:
- 3307:5432
environment:
POSTGRES_PASSWORD: ${OLD_DATABASE_PASS}
POSTGRES_USER: ${OLD_DATABASE_USER}
POSTGRES_DB: ${OLD_DATABASE_DB}

6
src/app.module.ts

@ -29,11 +29,15 @@ import { @@ -29,11 +29,15 @@ import {
import { getEnv, stringToBoolean } from './shared'
import { getRestModules } from './rest'
import { ScheduleModule } from '@nestjs/schedule'
import { TypeOrmModule } from '@nestjs/typeorm'
import { OldDatabaseSeedModule } from './domain/old-database-seed/old-database-seed.module'
const imports = [
EventEmitterModule.forRoot(),
JwtModule.forRoot($config.getJwtConfig()),
DatabaseModule.forRoot(...$config.getDatabaseConfig()),
TypeOrmModule.forRoot($config.getOldDatabaseConfig()),
RedisModule.forRoot($config.getRedisConfig()),
RealTimeModule.forRoot(),
PushNotificationsModule.forRoot($config.getPushNotificationsConfig()),
@ -54,6 +58,8 @@ const imports = [ @@ -54,6 +58,8 @@ const imports = [
ActivitiesModule.forRoot(),
ChatsModule.forRoot({ messagesCryptSalt: getEnv('CHAT_MESSAGES_CRYPT_SALT') }),
VersionsModule.forRoot(),
OldDatabaseSeedModule.forRoot(),
...getRestModules(),
]

16
src/config/index.ts

@ -7,6 +7,7 @@ import { @@ -7,6 +7,7 @@ import {
} from 'src/libs/push-notifications/interfaces'
import { IRedisModuleOptions } from 'src/libs/redis/interfaces'
import { getEnv, stringToBoolean } from 'src/shared'
import { ConnectionOptions } from 'typeorm'
import { ENTITIES } from './entities.config'
const getDatabaseConfig = (): Parameters<typeof DatabaseModule['forRoot']> => {
@ -24,6 +25,20 @@ const getDatabaseConfig = (): Parameters<typeof DatabaseModule['forRoot']> => { @@ -24,6 +25,20 @@ const getDatabaseConfig = (): Parameters<typeof DatabaseModule['forRoot']> => {
]
}
const getOldDatabaseConfig = (): Partial<ConnectionOptions> => {
return {
name: 'old',
type: 'postgres',
host: process.env.OLD_DATABASE_HOST,
port: Number(process.env.OLD_DATABASE_PORT),
username: process.env.OLD_DATABASE_USER,
password: process.env.OLD_DATABASE_PASS,
database: process.env.OLD_DATABASE_DB,
synchronize: false,
entities: [],
}
}
const getJwtConfig = () => {
return { jwtKey: getEnv('JWT_KEY'), paylodKey: getEnv('JWT_PAYLOAD_KEY') }
}
@ -80,4 +95,5 @@ export const $config = { @@ -80,4 +95,5 @@ export const $config = {
getMailerConfig,
getPushNotificationsConfig,
getLinkToWeb,
getOldDatabaseConfig,
}

14
src/domain/old-database-seed/old-database-seed.module.ts

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
import { DynamicModule, Module } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { OldDBTaxonomiesService, OldDBTestService } from './services'
@Module({})
export class OldDatabaseSeedModule {
static forRoot(): DynamicModule {
return {
module: OldDatabaseSeedModule,
imports: [TypeOrmModule.forFeature([], 'old')],
providers: [OldDBTestService, OldDBTaxonomiesService],
}
}
}

2
src/domain/old-database-seed/services/index.ts

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
export * from './taxonomies.service'
export * from './test.service'

21
src/domain/old-database-seed/services/taxonomies.service.ts

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
import { Injectable } from '@nestjs/common'
import { InjectConnection } from '@nestjs/typeorm'
import { Connection } from 'typeorm'
import { IOldTaxonomy } from '../typing/interfaces'
@Injectable()
export class OldDBTaxonomiesService {
constructor(@InjectConnection('old') private readonly connection: Connection) {}
private async getTaxonomies(): Promise<IOldTaxonomy[]> {
const result = await this.connection.query(
`
SELECT * FROM taxonomy
`,
[],
)
console.log(result)
return result
}
}

18
src/domain/old-database-seed/services/test.service.ts

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
import { Injectable } from '@nestjs/common'
import { InjectConnection } from '@nestjs/typeorm'
import { Connection } from 'typeorm'
@Injectable()
export class OldDBTestService {
constructor(@InjectConnection('old') private readonly connection: Connection) {}
// async onModuleInit() {
// const result = await this.connection.query(`
// SELECT TABLE_NAME
// FROM INFORMATION_SCHEMA.TABLES
// WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG='tasks'
// `)
// }
}

1
src/domain/old-database-seed/typing/interfaces/index.ts

@ -0,0 +1 @@ @@ -0,0 +1 @@
export * from './old-taxonomies.interfaces'

11
src/domain/old-database-seed/typing/interfaces/old-taxonomies.interfaces.ts

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
export interface IOldTaxonomy {
id: number
name: string
parent_id: number
type: 'reasons_task' | 'task'
created_at: number
updated_at: number
icon: string
is_deleted: boolean
is_default: boolean
}

2
src/libs/database/database.module.ts

@ -8,7 +8,7 @@ export class DatabaseModule { @@ -8,7 +8,7 @@ export class DatabaseModule {
static forRoot(options: Partial<ConnectionOptions>, entities: any[]): DynamicModule {
return {
module: DatabaseModule,
imports: [TypeOrmModule.forRoot({ ...options, entities })],
imports: [TypeOrmModule.forRoot({ ...options, entities, name: 'default' })],
}
}
}

Loading…
Cancel
Save