From 2883f1dacfb8474e221b3c7088b7981069abebf9 Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Thu, 27 Feb 2020 19:03:54 +0100 Subject: [PATCH] :sparkles: Add database check in init-tests --- package.json | 4 ++-- src/helpers/mysql.ts | 2 +- src/init-tests.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index fa9759a9c..abf82a8bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@staart/manager", - "version": "1.3.15", + "version": "1.3.16", "main": "index.js", "repository": "git@github.com:staart/api.git", "author": "Anand Chowdhary ", @@ -125,5 +125,5 @@ "setup" ], "snyk": true, - "staart-version": "1.3.15" + "staart-version": "1.3.16" } \ No newline at end of file diff --git a/src/helpers/mysql.ts b/src/helpers/mysql.ts index 16c7b32ea..41f1b2ffa 100644 --- a/src/helpers/mysql.ts +++ b/src/helpers/mysql.ts @@ -39,7 +39,7 @@ export const pool = createPool({ export const query = ( queryString: string, values?: (string | number | boolean | Date | undefined)[] -): InsertResult | any => +): Promise => new Promise((resolve, reject) => { pool.getConnection((error, connection) => { if (error) return reject(error); diff --git a/src/init-tests.ts b/src/init-tests.ts index f359b8bcf..855b0388f 100644 --- a/src/init-tests.ts +++ b/src/init-tests.ts @@ -4,15 +4,19 @@ import { sendMail, setupTransporter } from "@staart/mail"; import systemInfo from "systeminformation"; import pkg from "../package.json"; import redis from "@staart/redis"; +import { query } from "./helpers/mysql"; redis .set(pkg.name, systemInfo.time().current) .then(() => redis.del(pkg.name)) - .then(() => success("Redis is listening")) + .then(() => success("Redis is up and listening")) .catch(() => logError("Redis", "Unable to connect")); -setupTransporter(); +query("SHOW tables") + .then(() => success("Database connection is working")) + .catch(() => logError("Database", "Unable to run query `SHOW tables`")); +setupTransporter(); if (process.env.NODE_ENV === "production") sendMail({ to: TEST_EMAIL,