Skip to content

Commit

Permalink
feat(core): allow custom SQLite db directory
Browse files Browse the repository at this point in the history
A custom path to Garden's SQLite DB can now be set via the
GARDEN_DB_DIR variable.
  • Loading branch information
thsig authored and edvald committed Jun 24, 2020
1 parent c84564e commit ede0b69
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions garden-service/src/db/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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],
Expand Down

0 comments on commit ede0b69

Please sign in to comment.