Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reputation Oracle - database improvements #891

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ import { ConfigNames } from '../common/config';
keepConnectionAlive:
configService.get<string>(ConfigNames.NODE_ENV) === 'test',
migrationsRun: false,
ssl: configService.get<string>(ConfigNames.POSTGRES_SSL)!.toLowerCase() === 'true',
ssl:
configService
.get<string>(ConfigNames.POSTGRES_SSL)!
.toLowerCase() === 'true',
};
},
}),
Expand Down
24 changes: 12 additions & 12 deletions packages/apps/reputation-oracle/server/.env.example
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
20 changes: 10 additions & 10 deletions packages/apps/reputation-oracle/server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
- '${POSTGRES_PORT}:${POSTGRES_PORT}'
# volumes:
# - ./db:/var/lib/postgresql/data
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ import { ReputationEntity } from '../modules/reputation/reputation.entity';
username: configService.get<string>('POSTGRES_USER', 'operator'),
password: configService.get<string>('POSTGRES_PASSWORD', 'qwerty'),
database: configService.get<string>(
'POSTGRES_DB',
'POSTGRES_DATABASE',
'reputation-oracle',
),
keepConnectionAlive: configService.get<string>('NODE_ENV') === 'test',
migrationsRun: false,
ssl:
configService.get<string>('POSTGRES_SSL')!.toLowerCase() === 'true',
};
},
}),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
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);
}
}
17 changes: 10 additions & 7 deletions packages/apps/reputation-oracle/server/typeorm.config.ts
Original file line number Diff line number Diff line change
@@ -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
});
migrationsRun: true,
namingStrategy: new SnakeNamingStrategy(),
ssl: process.env.POSTGRES_SSL?.toLowerCase() === 'true',
});
Loading