Skip to content

Commit 801b984

Browse files
committed
feat: implement servie for SQL db
1 parent 809fd99 commit 801b984

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8278
-46
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
NODE_ENV=
2+
APP_PORT=
3+
DBDUMP_GATEWAY_API_KEY=
4+
SWAGGER_HOST=
5+
TYPEORM_TYPE=
6+
TYPEORM_HOST=
7+
TYPEORM_USERNAME=
8+
TYPEORM_PASSWORD=
9+
TYPEORM_DATABASE=
10+
TYPEORM_PORT=
11+
TYPEORM_LOGGING=
12+
TYPEORM_AUTO_LOAD_ENTITIES=
13+
TYPEORM_MIGRATIONS_RUN=
14+
TYPEORM_SYNCHRONIZE=

.gitignore

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ logs
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
117

128
# Runtime data
139
pids
@@ -20,12 +16,11 @@ lib-cov
2016

2117
# Coverage directory used by tools like istanbul
2218
coverage
23-
*.lcov
2419

2520
# nyc test coverage
2621
.nyc_output
2722

28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2924
.grunt
3025

3126
# Bower dependency directory (https://bower.io/)
@@ -44,21 +39,12 @@ jspm_packages/
4439
# TypeScript v1 declaration files
4540
typings/
4641

47-
# TypeScript cache
48-
*.tsbuildinfo
49-
5042
# Optional npm cache directory
5143
.npm
5244

5345
# Optional eslint cache
5446
.eslintcache
5547

56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
6248
# Optional REPL history
6349
.node_repl_history
6450

@@ -70,35 +56,10 @@ typings/
7056

7157
# dotenv environment variables file
7258
.env
73-
.env.test
7459

75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
60+
# next.js build output
7961
.next
8062

81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
63+
dist/
64+
tmp/*
65+
.DS_Store

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This image caches dependencies for other containers
2+
# It allows to install them once and reuse later
3+
FROM node:14 AS node_base
4+
5+
## Install deps
6+
FROM node_base as deps
7+
WORKDIR /usr/app
8+
COPY package.json ./
9+
RUN yarn install --frozen-lockfile && yarn cache clean
10+
11+
## Run app for DEV env
12+
FROM node_base as build
13+
WORKDIR /usr/app
14+
COPY --from=deps /usr/app/node_modules /usr/app/node_modules
15+
COPY . .
16+
CMD yarn start
17+
EXPOSE 3000

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# db-dump-gdpr
2-
Module to get a dump of the database, but with GDPR-proof scrambled data
1+
# DB dump
2+
3+
Run database `docker-compose up -d`
4+
5+
Run - `yarn start:debug`
6+
7+
Create migration - `yarn typeorm migration:create -n <name>`
8+
9+
Service provides an API-KEY-protected endpoint to get a database dump of the needed service with GDPR-proof scrambled data.

config/app.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
nodeEnv: process.env.NODE_ENV || 'development',
3+
port: process.env.APP_PORT || 3000,
4+
gatewayApiKey: process.env.DBDUMP_GATEWAY_API_KEY || 'f06c88b8-bc58-11eb-8529-0242ac130003',
5+
swaggerHost: process.env.SWAGGER_HOST || `http://localhost:3000/`
6+
};

config/database.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default {
2+
name: 'default',
3+
type: process.env.TYPEORM_TYPE || 'mysql',
4+
host: process.env.TYPEORM_HOST || 'localhost',
5+
username: process.env.TYPEORM_USERNAME || 'guest',
6+
password: process.env.TYPEORM_PASSWORD || 'guest',
7+
database: process.env.TYPEORM_DATABASE || 'dbdump',
8+
port: parseInt(process.env.TYPEORM_PORT, 10) || 3306,
9+
logging: process.env.TYPEORM_LOGGING === 'true',
10+
entities: ['**/*.entity.ts'],
11+
migrations: ['migrations/**/*.ts'],
12+
migrationsRun: process.env.TYPEORM_MIGRATIONS_RUN === 'true',
13+
synchronize: process.env.TYPEORM_SYNCHRONIZE === 'true',
14+
cli: {
15+
entitiesDir: 'src',
16+
migrationsDir: 'migrations',
17+
},
18+
};

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3.0"
2+
services:
3+
mysql-db:
4+
image: mariadb:10.4
5+
restart: "no"
6+
volumes:
7+
- dbdump-mysql:/var/lib/mysql
8+
ports:
9+
- 3306:3306
10+
environment:
11+
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
12+
MYSQL_DATABASE: "dbdump"
13+
MYSQL_USER: "guest"
14+
MYSQL_PASSWORD: "guest"
15+
16+
volumes:
17+
dbdump-mysql:

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
collectCoverageFrom: [
3+
"**/*.ts",
4+
"!**/*.entity.ts",
5+
],
6+
coverageDirectory: "../coverage",
7+
moduleFileExtensions: [
8+
"js",
9+
"json",
10+
"ts",
11+
],
12+
rootDir: "src",
13+
testEnvironment: "node",
14+
testRegex: ".spec.ts$",
15+
transform: {
16+
"^.+\\.(t|j)s$": "ts-jest",
17+
},
18+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class createDbConfigsTable1621841206193 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(
6+
`CREATE TABLE IF NOT EXISTS db_configs (
7+
id int NOT NULL AUTO_INCREMENT,
8+
service varchar(255) NOT NULL,
9+
type varchar(255) NOT NULL,
10+
host varchar(255) NOT NULL,
11+
port int NOT NULL,
12+
password varchar(255) NOT NULL,
13+
username varchar(255) NOT NULL,
14+
db varchar(255) NOT NULL,
15+
createdAt timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
16+
updatedAt timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
17+
UNIQUE INDEX\`IDX_64c46ce79eee86ae821782a0ca\`(\`service\`),
18+
PRIMARY KEY(\`id\`)
19+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20+
`);
21+
}
22+
23+
public async down(queryRunner: QueryRunner): Promise<void> {
24+
await queryRunner.query('DROP TABLE `db_configs`');
25+
}
26+
}

0 commit comments

Comments
 (0)