From ede0b69ff98797b31c9b3202984b1e16a3942360 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Tue, 9 Jun 2020 19:06:39 +0200 Subject: [PATCH] feat(core): allow custom SQLite db directory A custom path to Garden's SQLite DB can now be set via the GARDEN_DB_DIR variable. --- garden-service/src/db/connection.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/garden-service/src/db/connection.ts b/garden-service/src/db/connection.ts index 65575dae37..9bbedf1e62 100644 --- a/garden-service/src/db/connection.ts +++ b/garden-service/src/db/connection.ts @@ -6,12 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { Connection, getConnectionManager, ConnectionOptions } from "typeorm" import { join } from "path" +import { Connection, getConnectionManager, ConnectionOptions } from "typeorm" import { GARDEN_GLOBAL_PATH } from "../constants" let connection: Connection +const databasePath = join(process.env.GARDEN_DB_DIR || GARDEN_GLOBAL_PATH, "db") + // Note: This function needs to be synchronous to work with the typeorm Active Record pattern (see ./base-entity.ts) export function getConnection(): Connection { if (!connection) { @@ -20,7 +22,7 @@ export function getConnection(): Connection { // Prepare the connection (the ormconfig.json in the static dir is only used for the typeorm CLI during dev) const options: ConnectionOptions = { type: "sqlite", - database: join(GARDEN_GLOBAL_PATH, "db"), + database: databasePath, // IMPORTANT: All entities and migrations need to be manually referenced here because of how we // package the garden binary entities: [LocalAddress, ClientAuthToken],