From 269bf1838134b694cc49b1786018a57d7d5211d5 Mon Sep 17 00:00:00 2001 From: Vitalik Date: Mon, 7 Nov 2022 20:41:22 +0200 Subject: [PATCH] FEATURE | Old database seed --- docker-compose.yml | 11 ++++++++++ src/app.module.ts | 6 ++++++ src/config/index.ts | 16 ++++++++++++++ .../old-database-seed.module.ts | 14 +++++++++++++ .../old-database-seed/services/index.ts | 2 ++ .../services/taxonomies.service.ts | 21 +++++++++++++++++++ .../services/test.service.ts | 18 ++++++++++++++++ .../typing/interfaces/index.ts | 1 + .../interfaces/old-taxonomies.interfaces.ts | 11 ++++++++++ src/libs/database/database.module.ts | 2 +- 10 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/domain/old-database-seed/old-database-seed.module.ts create mode 100644 src/domain/old-database-seed/services/index.ts create mode 100644 src/domain/old-database-seed/services/taxonomies.service.ts create mode 100644 src/domain/old-database-seed/services/test.service.ts create mode 100644 src/domain/old-database-seed/typing/interfaces/index.ts create mode 100644 src/domain/old-database-seed/typing/interfaces/old-taxonomies.interfaces.ts diff --git a/docker-compose.yml b/docker-compose.yml index 69b85a1..3d3e8c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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} diff --git a/src/app.module.ts b/src/app.module.ts index d7c6791..df98c7b 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -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 = [ ActivitiesModule.forRoot(), ChatsModule.forRoot({ messagesCryptSalt: getEnv('CHAT_MESSAGES_CRYPT_SALT') }), VersionsModule.forRoot(), + OldDatabaseSeedModule.forRoot(), + ...getRestModules(), ] diff --git a/src/config/index.ts b/src/config/index.ts index bae1277..9170659 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -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 => { @@ -24,6 +25,20 @@ const getDatabaseConfig = (): Parameters => { ] } +const getOldDatabaseConfig = (): Partial => { + 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 = { getMailerConfig, getPushNotificationsConfig, getLinkToWeb, + getOldDatabaseConfig, } diff --git a/src/domain/old-database-seed/old-database-seed.module.ts b/src/domain/old-database-seed/old-database-seed.module.ts new file mode 100644 index 0000000..c7b1486 --- /dev/null +++ b/src/domain/old-database-seed/old-database-seed.module.ts @@ -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], + } + } +} diff --git a/src/domain/old-database-seed/services/index.ts b/src/domain/old-database-seed/services/index.ts new file mode 100644 index 0000000..5b5ee78 --- /dev/null +++ b/src/domain/old-database-seed/services/index.ts @@ -0,0 +1,2 @@ +export * from './taxonomies.service' +export * from './test.service' diff --git a/src/domain/old-database-seed/services/taxonomies.service.ts b/src/domain/old-database-seed/services/taxonomies.service.ts new file mode 100644 index 0000000..e542e28 --- /dev/null +++ b/src/domain/old-database-seed/services/taxonomies.service.ts @@ -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 { + const result = await this.connection.query( + ` + SELECT * FROM taxonomy + + `, + [], + ) + console.log(result) + return result + } +} diff --git a/src/domain/old-database-seed/services/test.service.ts b/src/domain/old-database-seed/services/test.service.ts new file mode 100644 index 0000000..4f8a05f --- /dev/null +++ b/src/domain/old-database-seed/services/test.service.ts @@ -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' + + // `) + // } +} diff --git a/src/domain/old-database-seed/typing/interfaces/index.ts b/src/domain/old-database-seed/typing/interfaces/index.ts new file mode 100644 index 0000000..2c02667 --- /dev/null +++ b/src/domain/old-database-seed/typing/interfaces/index.ts @@ -0,0 +1 @@ +export * from './old-taxonomies.interfaces' diff --git a/src/domain/old-database-seed/typing/interfaces/old-taxonomies.interfaces.ts b/src/domain/old-database-seed/typing/interfaces/old-taxonomies.interfaces.ts new file mode 100644 index 0000000..f155726 --- /dev/null +++ b/src/domain/old-database-seed/typing/interfaces/old-taxonomies.interfaces.ts @@ -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 +} diff --git a/src/libs/database/database.module.ts b/src/libs/database/database.module.ts index d3c5706..f914af9 100755 --- a/src/libs/database/database.module.ts +++ b/src/libs/database/database.module.ts @@ -8,7 +8,7 @@ export class DatabaseModule { static forRoot(options: Partial, entities: any[]): DynamicModule { return { module: DatabaseModule, - imports: [TypeOrmModule.forRoot({ ...options, entities })], + imports: [TypeOrmModule.forRoot({ ...options, entities, name: 'default' })], } } }