diff --git a/packages/apps/job-launcher/server/src/database/database.module.ts b/packages/apps/job-launcher/server/src/database/database.module.ts index 1852f89c0e..9681c21e4c 100644 --- a/packages/apps/job-launcher/server/src/database/database.module.ts +++ b/packages/apps/job-launcher/server/src/database/database.module.ts @@ -69,7 +69,10 @@ import { ConfigNames } from '../common/config'; keepConnectionAlive: configService.get(ConfigNames.NODE_ENV) === 'test', migrationsRun: false, - ssl: configService.get(ConfigNames.POSTGRES_SSL)!.toLowerCase() === 'true', + ssl: + configService + .get(ConfigNames.POSTGRES_SSL)! + .toLowerCase() === 'true', }; }, }), diff --git a/packages/apps/reputation-oracle/server/.env.example b/packages/apps/reputation-oracle/server/.env.example index d6892e55d4..6861b95dbe 100644 --- a/packages/apps/reputation-oracle/server/.env.example +++ b/packages/apps/reputation-oracle/server/.env.example @@ -1,18 +1,18 @@ # General -NODE_ENV= -HOST= -PORT= -FE_URL= -SESSION_SECRET= +NODE_ENV=development +HOST=localhost +PORT=3008 +FE_URL=http://localhost:3009 +SESSION_SECRET=test # Database -DB_TYPE= -POSTGRES_HOST= -POSTGRES_USER= -POSTGRES_PASSWORD= -POSTGRES_DB= -POSTGRES_SYNC= -POSTGRES_PORT= +POSTGRES_HOST=0.0.0.0 +POSTGRES_USER=operator +POSTGRES_PASSWORD=qwerty +POSTGRES_DATABASE=job-launcher +POSTGRES_SYNC=false +POSTGRES_PORT=5432 +POSTGRES_SSL=false # Auth JWT_SECRET= diff --git a/packages/apps/reputation-oracle/server/docker-compose.yml b/packages/apps/reputation-oracle/server/docker-compose.yml index ff8accdcf3..9b4ab519b5 100644 --- a/packages/apps/reputation-oracle/server/docker-compose.yml +++ b/packages/apps/reputation-oracle/server/docker-compose.yml @@ -1,21 +1,21 @@ -version: '3.7' +version: '3.8' services: postgres: image: postgres:latest restart: always environment: - - POSTGRES_HOST=0.0.0.0 - - POSTGRES_USER=operator - - POSTGRES_PASSWORD=qwerty - - POSTGRES_DB=reputation-oracle - - POSTGRES_PORT=5432 - - POSTGRES_SYNC=false + - POSTGRES_HOST=${POSTGRES_HOST} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DATABASE} + - POSTGRES_PORT=${POSTGRES_PORT} + - POSTGRES_SYNC=${POSTGRES_SYNC} logging: options: max-size: 10m max-file: "3" ports: - - '5432:5432' - volumes: - - ./db:/var/lib/postgresql/data \ No newline at end of file + - '${POSTGRES_PORT}:${POSTGRES_PORT}' + # volumes: + # - ./db:/var/lib/postgresql/data \ No newline at end of file diff --git a/packages/apps/reputation-oracle/server/src/common/config/env.ts b/packages/apps/reputation-oracle/server/src/common/config/env.ts index 305f32e089..15e8a71e64 100644 --- a/packages/apps/reputation-oracle/server/src/common/config/env.ts +++ b/packages/apps/reputation-oracle/server/src/common/config/env.ts @@ -9,13 +9,13 @@ export const ConfigNames = { JWT_SECRET: 'JWT_SECRET', JWT_ACCESS_TOKEN_EXPIRES_IN: 'JWT_ACCESS_TOKEN_EXPIRES_IN', JWT_REFRESH_TOKEN_EXPIRES_IN: 'JWT_REFRESH_TOKEN_EXPIRES_IN', - DB_TYPE: 'DB_TYPE', POSTGRES_HOST: 'POSTGRES_HOST', POSTGRES_USER: 'POSTGRES_USER', POSTGRES_PASSWORD: 'POSTGRES_PASSWORD', - POSTGRES_DB: 'POSTGRES_DB', + POSTGRES_DATABASE: 'POSTGRES_DATABASE', POSTGRES_PORT: 'POSTGRES_PORT', POSTGRES_SYNC: 'POSTGRES_SYNC', + POSTGRES_SSL: 'POSTGRES_SSL', WEB3_PRIVATE_KEY: 'WEB3_PRIVATE_KEY', S3_ENDPOINT: 'S3_ENDPOINT', S3_PORT: 'S3_PORT', @@ -39,9 +39,10 @@ export const envValidator = Joi.object({ POSTGRES_HOST: Joi.string().default('127.0.0.1'), POSTGRES_USER: Joi.string().default('operator'), POSTGRES_PASSWORD: Joi.string().default('qwerty'), - POSTGRES_DB: Joi.string().default('reputation-oracle'), + POSTGRES_DATABASE: Joi.string().default('job-launcher'), POSTGRES_PORT: Joi.string().default('5432'), POSTGRES_SYNC: Joi.string().default(false), + POSTGRES_SSL: Joi.string().default(false), // Web3 WEB3_PRIVATE_KEY: Joi.string().required(), // S3 diff --git a/packages/apps/reputation-oracle/server/src/database/database.module.ts b/packages/apps/reputation-oracle/server/src/database/database.module.ts index d47e07d545..29d9a26a68 100644 --- a/packages/apps/reputation-oracle/server/src/database/database.module.ts +++ b/packages/apps/reputation-oracle/server/src/database/database.module.ts @@ -44,11 +44,13 @@ import { ReputationEntity } from '../modules/reputation/reputation.entity'; username: configService.get('POSTGRES_USER', 'operator'), password: configService.get('POSTGRES_PASSWORD', 'qwerty'), database: configService.get( - 'POSTGRES_DB', + 'POSTGRES_DATABASE', 'reputation-oracle', ), keepConnectionAlive: configService.get('NODE_ENV') === 'test', migrationsRun: false, + ssl: + configService.get('POSTGRES_SSL')!.toLowerCase() === 'true', }; }, }), diff --git a/packages/apps/reputation-oracle/server/src/database/migrations/1677845576145-addShema.ts b/packages/apps/reputation-oracle/server/src/database/migrations/1677845576145-addShema.ts deleted file mode 100644 index f1e2ba10e4..0000000000 --- a/packages/apps/reputation-oracle/server/src/database/migrations/1677845576145-addShema.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; -import { NS } from '../../common/constants'; - -export class addShema1677845576145 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.createSchema(NS, true); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropSchema(NS); - } -} diff --git a/packages/apps/reputation-oracle/server/src/database/migrations/1677845804077-installExtension.ts b/packages/apps/reputation-oracle/server/src/database/migrations/1677845804077-installExtension.ts deleted file mode 100644 index d71cc6aa15..0000000000 --- a/packages/apps/reputation-oracle/server/src/database/migrations/1677845804077-installExtension.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class installExtension1677845804077 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`-- do nothing`); - } -} diff --git a/packages/apps/reputation-oracle/server/src/database/migrations/1678011588667-addWebhookIncomingTable.ts b/packages/apps/reputation-oracle/server/src/database/migrations/1678011588667-addWebhookIncomingTable.ts deleted file mode 100644 index 63eb29ca92..0000000000 --- a/packages/apps/reputation-oracle/server/src/database/migrations/1678011588667-addWebhookIncomingTable.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { MigrationInterface, QueryRunner, Table } from 'typeorm'; -import { NS } from '../../common/constants'; - -export class addWebhookIncomingTable1678011588667 - implements MigrationInterface -{ - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE TYPE ${NS}.webhook_incoming_status_enum AS ENUM ( - 'PENDING', - 'PAID', - 'COMPLETED', - 'FAILED' - ); - `); - - const table = new Table({ - name: `${NS}.webhook_incoming`, - columns: [ - { - name: 'id', - type: 'serial', - isPrimary: true, - }, - { - name: 'chain_id', - type: 'int', - }, - { - name: 'escrow_address', - type: 'varchar', - }, - { - name: 'results_url', - type: 'varchar', - isNullable: true, - }, - { - name: 'check_passed', - type: 'boolean', - isNullable: true, - }, - { - name: 'retries_count', - type: 'int', - default: 0, - }, - { - name: 'status', - type: `${NS}.webhook_incoming_status_enum`, - }, - { - name: 'created_at', - type: 'timestamptz', - }, - { - name: 'updated_at', - type: 'timestamptz', - }, - { - name: 'wait_until', - type: 'timestamptz', - }, - ], - }); - - await queryRunner.createTable(table, true); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropTable(`${NS}.webhook_incoming`); - await queryRunner.query(`DROP TYPE ${NS}.webhook_incoming_status_enum;`); - } -} diff --git a/packages/apps/reputation-oracle/server/src/database/migrations/1678094042234-addReputationTable.ts b/packages/apps/reputation-oracle/server/src/database/migrations/1678094042234-addReputationTable.ts deleted file mode 100644 index 94ea5b5fa9..0000000000 --- a/packages/apps/reputation-oracle/server/src/database/migrations/1678094042234-addReputationTable.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { MigrationInterface, QueryRunner, Table } from 'typeorm'; -import { NS } from '../../common/constants'; - -export class addReputationTable1678094042234 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE TYPE ${NS}.reputation_type_enum AS ENUM ( - 'WORKER', - 'JOB_LAUNCHER', - 'EXCHANGE_ORACLE', - 'RECORDING_ORACLE', - 'REPUTATION_ORACLE' - ); - `); - - const table = new Table({ - name: `${NS}.reputation`, - columns: [ - { - name: 'id', - type: 'serial', - isPrimary: true, - }, - { - name: 'chain_id', - type: 'int', - }, - { - name: 'address', - type: 'varchar', - }, - { - name: 'reputation_points', - type: 'int', - }, - { - name: 'type', - type: `${NS}.reputation_type_enum`, - }, - { - name: 'created_at', - type: 'timestamptz', - }, - { - name: 'updated_at', - type: 'timestamptz', - }, - ], - }); - - await queryRunner.createTable(table, true); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropTable(`${NS}.reputation`); - await queryRunner.query(`DROP TYPE ${NS}.reputation_type_enum;`); - } -} diff --git a/packages/apps/reputation-oracle/server/src/database/migrations/1694691302615-InitialMigration.ts b/packages/apps/reputation-oracle/server/src/database/migrations/1694691302615-InitialMigration.ts new file mode 100644 index 0000000000..46edc47a9d --- /dev/null +++ b/packages/apps/reputation-oracle/server/src/database/migrations/1694691302615-InitialMigration.ts @@ -0,0 +1,30 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import { NS } from '../../common/constants'; + +export class InitialMigration1694691302615 implements MigrationInterface { + name = 'InitialMigration1694691302615'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createSchema(NS, true); + await queryRunner.query( + `CREATE TYPE "hmt"."reputation_type_enum" AS ENUM('WORKER', 'JOB_LAUNCHER', 'EXCHANGE_ORACLE', 'RECORDING_ORACLE', 'REPUTATION_ORACLE')`, + ); + await queryRunner.query( + `CREATE TABLE "hmt"."reputation" ("id" SERIAL NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL, "chain_id" integer NOT NULL, "address" character varying NOT NULL, "reputation_points" integer NOT NULL, "type" "hmt"."reputation_type_enum" NOT NULL, CONSTRAINT "PK_640807583e8622e1d9bbe6f1b7b" PRIMARY KEY ("id"))`, + ); + await queryRunner.query( + `CREATE TYPE "hmt"."webhook_incoming_status_enum" AS ENUM('PENDING', 'COMPLETED', 'FAILED', 'PAID')`, + ); + await queryRunner.query( + `CREATE TABLE "hmt"."webhook_incoming" ("id" SERIAL NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL, "chain_id" integer NOT NULL, "oracle_address" character varying, "escrow_address" character varying NOT NULL, "results_url" character varying, "check_passed" boolean, "retries_count" integer NOT NULL, "wait_until" TIMESTAMP WITH TIME ZONE NOT NULL, "status" "hmt"."webhook_incoming_status_enum" NOT NULL, CONSTRAINT "PK_08e16abccb4720323203bf8f7a0" PRIMARY KEY ("id"))`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "hmt"."webhook_incoming"`); + await queryRunner.query(`DROP TYPE "hmt"."webhook_incoming_status_enum"`); + await queryRunner.query(`DROP TABLE "hmt"."reputation"`); + await queryRunner.query(`DROP TYPE "hmt"."reputation_type_enum"`); + await queryRunner.dropSchema(NS); + } +} diff --git a/packages/apps/reputation-oracle/server/typeorm.config.ts b/packages/apps/reputation-oracle/server/typeorm.config.ts index 57ae98cf8f..c8f5021eb9 100644 --- a/packages/apps/reputation-oracle/server/typeorm.config.ts +++ b/packages/apps/reputation-oracle/server/typeorm.config.ts @@ -1,22 +1,25 @@ import { DataSource } from 'typeorm'; -import * as dotenv from "dotenv"; +import { SnakeNamingStrategy } from 'typeorm-naming-strategies'; +import * as dotenv from 'dotenv'; -dotenv.config({ +dotenv.config({ path: process.env.NODE_ENV ? `.env.${process.env.NODE_ENV as string}` - : '.env' + : '.env', }); export default new DataSource({ type: 'postgres', host: process.env.POSTGRES_HOST, - port: Number(process.env.POSTGRES_PORT!), + port: Number(process.env.POSTGRES_PORT), username: process.env.POSTGRES_USER, password: process.env.POSTGRES_PASSWORD, - database: process.env.POSTGRES_DB, + database: process.env.POSTGRES_DATABASE, entities: ['dist/src/**/*.entity{ .ts,.js}'], synchronize: false, migrations: ['dist/src/database/migrations/*{.ts,.js}'], migrationsTableName: 'migrations_typeorm', - migrationsRun: true -}); \ No newline at end of file + migrationsRun: true, + namingStrategy: new SnakeNamingStrategy(), + ssl: process.env.POSTGRES_SSL?.toLowerCase() === 'true', +});