Merge pull request #46 from hugomd/feat/add-database-schema-variable

Add DATABASE_TYPE environment variable
This commit is contained in:
Mike Cao 2020-08-22 19:51:25 -07:00 committed by GitHub
commit bd4d2b1108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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);