From 73ea516a7abc5e7018c9311f3c832ba6ee91c76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20M=C3=BCller-Downing?= Date: Sat, 22 Aug 2020 22:39:01 +1000 Subject: [PATCH] Add DATABASE_TYPE environment variable Determines which Prisma schema to use --- Dockerfile | 5 ++++- docker-compose.yml | 1 + scripts/copy-db-schema.js | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4625124c..871b8a87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ FROM node:12.18-alpine -ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" +ARG DATABASE_TYPE + +ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \ + DATABASE_TYPE=$DATABASE_TYPE COPY . /app WORKDIR /app diff --git a/docker-compose.yml b/docker-compose.yml index f9560dd9..7f1b42ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: - "3000:3000" environment: DATABASE_URL: postgresql://umami:umami@db:5432/umami + DATABASE_TYPE: postgresql HASH_SALT: replace-me-with-a-random-string depends_on: - db diff --git a/scripts/copy-db-schema.js b/scripts/copy-db-schema.js index 60c39598..5dda2215 100644 --- a/scripts/copy-db-schema.js +++ b/scripts/copy-db-schema.js @@ -2,15 +2,15 @@ require('dotenv').config(); const fs = require('fs'); const path = require('path'); -const db = process.env.DATABASE_URL.split(':')[0]; +const databaseType = process.env.DATABASE_TYPE || process.env.DATABASE_URL.split(':')[0]; -if (!db) { - throw new Error('Database not specified'); +if (!databaseType) { + throw new Error('Database schema not specified'); } -console.log(`Database detected: ${db}`); +console.log(`Database schema detected: ${databaseType}`); -const src = path.resolve(__dirname, `../prisma/schema.${db}.prisma`); +const src = path.resolve(__dirname, `../prisma/schema.${databaseType}.prisma`); const dest = path.resolve(__dirname, '../prisma/schema.prisma'); fs.copyFileSync(src, dest);