From aa07ef2231c2d2309f62823f7f4b9d565205f589 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 12 Oct 2021 01:26:47 +0200 Subject: [PATCH] errors on failed connection to help debugging, entities from database project in typeorm connection --- backend/src/typeorm/connection.ts | 9 ++++++--- database/entity/index.ts | 19 +++++++++++++++++++ database/src/typeorm/connection.ts | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 database/entity/index.ts diff --git a/backend/src/typeorm/connection.ts b/backend/src/typeorm/connection.ts index 0fcd6aac3..5709c29b6 100644 --- a/backend/src/typeorm/connection.ts +++ b/backend/src/typeorm/connection.ts @@ -1,6 +1,6 @@ import { createConnection, Connection } from 'typeorm' import CONFIG from '../config' -import path from 'path' +import { entities } from '@entity/index' const connection = async (): Promise => { let con = null @@ -13,10 +13,13 @@ const connection = async (): Promise => { username: CONFIG.DB_USER, password: CONFIG.DB_PASSWORD, database: CONFIG.DB_DATABASE, - entities: [path.join(__dirname, 'entity', '*.{ts,js}')], + entities, synchronize: false, }) - } catch (error) {} + } catch (error) { + // eslint-disable-next-line no-console + console.log(error) + } return con } diff --git a/database/entity/index.ts b/database/entity/index.ts new file mode 100644 index 000000000..e18757ab8 --- /dev/null +++ b/database/entity/index.ts @@ -0,0 +1,19 @@ +import { Balance } from './Balance' +import { Migration } from './Migration' +import { Transaction } from './Transaction' +import { TransactionCreation } from './TransactionCreation' +import { TransactionSendCoin } from './TransactionSendCoin' +import { User } from './User' +import { UserSetting } from './UserSetting' +import { UserTransaction } from './UserTransaction' + +export const entities = [ + Balance, + Migration, + Transaction, + TransactionCreation, + TransactionSendCoin, + User, + UserSetting, + UserTransaction, +] diff --git a/database/src/typeorm/connection.ts b/database/src/typeorm/connection.ts index 26aafc102..6e8bd5c09 100644 --- a/database/src/typeorm/connection.ts +++ b/database/src/typeorm/connection.ts @@ -1,6 +1,6 @@ import { createConnection, Connection } from 'typeorm' import CONFIG from '../config' -import path from 'path' +import { entities } from '../../entity/index' const connection = async (): Promise => { let con = null @@ -13,7 +13,7 @@ const connection = async (): Promise => { username: CONFIG.DB_USER, password: CONFIG.DB_PASSWORD, database: CONFIG.DB_DATABASE, - entities: [path.join(__dirname, '..', '..', 'entity', '*.{ts,js}')], + entities, synchronize: false, }) } catch (error) {}