mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-12 23:35:50 +00:00
database version check backend,
connect "singleton" for mysql docker-compose backend depends on mariadb and restarts till the correct database version is found
This commit is contained in:
parent
8cf8cc0751
commit
65fdc75a1f
18
backend/src/database/connection.ts
Normal file
18
backend/src/database/connection.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { createConnection, Connection } from 'mysql2/promise'
|
||||||
|
import CONFIG from '../config'
|
||||||
|
|
||||||
|
const connection = async (): Promise<Connection> => {
|
||||||
|
const con = await createConnection({
|
||||||
|
host: CONFIG.DB_HOST,
|
||||||
|
port: CONFIG.DB_PORT,
|
||||||
|
user: CONFIG.DB_USER,
|
||||||
|
password: CONFIG.DB_PASSWORD,
|
||||||
|
database: CONFIG.DB_DATABASE,
|
||||||
|
})
|
||||||
|
|
||||||
|
await con.connect()
|
||||||
|
|
||||||
|
return con
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connection
|
||||||
@ -2,7 +2,9 @@ import 'reflect-metadata'
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { buildSchema } from 'type-graphql'
|
import { buildSchema } from 'type-graphql'
|
||||||
import { ApolloServer } from 'apollo-server-express'
|
import { ApolloServer } from 'apollo-server-express'
|
||||||
// import { createConnection } from 'typeorm'
|
import { RowDataPacket } from 'mysql2/promise'
|
||||||
|
|
||||||
|
import connection from './database/connection'
|
||||||
import CONFIG from './config'
|
import CONFIG from './config'
|
||||||
|
|
||||||
// TODO move to extern
|
// TODO move to extern
|
||||||
@ -15,7 +17,19 @@ import { TransactionResolver } from './graphql/resolvers/TransactionResolver'
|
|||||||
// TODO implement
|
// TODO implement
|
||||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||||
|
|
||||||
|
const DB_VERSION = '0001-init_db'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
// check for correct database version
|
||||||
|
const con = await connection()
|
||||||
|
const [rows] = await con.query(`SELECT fileName FROM migrations ORDER BY version DESC LIMIT 1;`)
|
||||||
|
if (
|
||||||
|
(<RowDataPacket>rows).length === 0 ||
|
||||||
|
(<RowDataPacket>rows)[0].fileName.indexOf(DB_VERSION) === -1
|
||||||
|
) {
|
||||||
|
throw new Error(`Wrong database version - the backend requires '${DB_VERSION}'`)
|
||||||
|
}
|
||||||
|
|
||||||
// const connection = await createConnection()
|
// const connection = await createConnection()
|
||||||
const schema = await buildSchema({
|
const schema = await buildSchema({
|
||||||
resolvers: [UserResolver, BalanceResolver, TransactionResolver, GdtResolver],
|
resolvers: [UserResolver, BalanceResolver, TransactionResolver, GdtResolver],
|
||||||
@ -45,4 +59,8 @@ async function main() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main().catch((e) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(e)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
|||||||
@ -61,6 +61,9 @@ services:
|
|||||||
- internal-net
|
- internal-net
|
||||||
ports:
|
ports:
|
||||||
- 4000:4000
|
- 4000:4000
|
||||||
|
depends_on:
|
||||||
|
- mariadb
|
||||||
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
# Envs used in Dockerfile
|
# Envs used in Dockerfile
|
||||||
# - DOCKER_WORKDIR="/app"
|
# - DOCKER_WORKDIR="/app"
|
||||||
@ -69,6 +72,7 @@ services:
|
|||||||
- BUILD_VERSION
|
- BUILD_VERSION
|
||||||
- BUILD_COMMIT
|
- BUILD_COMMIT
|
||||||
- NODE_ENV="production"
|
- NODE_ENV="production"
|
||||||
|
- DB_HOST=mariadb
|
||||||
# Application only envs
|
# Application only envs
|
||||||
#env_file:
|
#env_file:
|
||||||
# - ./frontend/.env
|
# - ./frontend/.env
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user