Add DATABASE_TYPE environment variable

Determines which Prisma schema to use
This commit is contained in:
Hugo Müller-Downing 2020-08-22 22:39:01 +10:00
parent 05dc77ca35
commit 73ea516a7a
3 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,9 @@
FROM node:12.18-alpine 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 COPY . /app
WORKDIR /app WORKDIR /app

View File

@ -7,6 +7,7 @@ services:
- "3000:3000" - "3000:3000"
environment: environment:
DATABASE_URL: postgresql://umami:umami@db:5432/umami DATABASE_URL: postgresql://umami:umami@db:5432/umami
DATABASE_TYPE: postgresql
HASH_SALT: replace-me-with-a-random-string HASH_SALT: replace-me-with-a-random-string
depends_on: depends_on:
- db - db

View File

@ -2,15 +2,15 @@ require('dotenv').config();
const fs = require('fs'); const fs = require('fs');
const path = require('path'); 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) { if (!databaseType) {
throw new Error('Database not specified'); 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'); const dest = path.resolve(__dirname, '../prisma/schema.prisma');
fs.copyFileSync(src, dest); fs.copyFileSync(src, dest);