Skip to content

Commit

Permalink
Detect when postgres is used instead of postgresql.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Sep 4, 2020
1 parent 0db2971 commit 6833a5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { subMinutes } from 'date-fns';
import { MYSQL, POSTGRESQL, MYSQL_DATE_FORMATS, POSTGRESQL_DATE_FORMATS } from 'lib/constants';

export function getDatabase() {
return (
const type =
process.env.DATABASE_TYPE ||
(process.env.DATABASE_URL && process.env.DATABASE_URL.split(':')[0])
);
(process.env.DATABASE_URL && process.env.DATABASE_URL.split(':')[0]);

if (type === 'postgres') {
return 'postgresql';
}

return type;
}

export function getDateQuery(db, field, unit, timezone) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umami",
"version": "0.22.0",
"version": "0.23.0",
"description": "A simple, fast, website analytics alternative to Google Analytics. ",
"author": "Mike Cao <[email protected]>",
"license": "MIT",
Expand Down
17 changes: 14 additions & 3 deletions scripts/copy-db-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@ require('dotenv').config();
const fs = require('fs');
const path = require('path');

const databaseType =
process.env.DATABASE_TYPE || (process.env.DATABASE_URL && process.env.DATABASE_URL.split(':')[0]);
function getDatabase() {
const type =
process.env.DATABASE_TYPE ||
(process.env.DATABASE_URL && process.env.DATABASE_URL.split(':')[0]);

if (type === 'postgres') {
return 'postgresql';
}

return type;
}

const databaseType = getDatabase();

if (!databaseType || !['mysql', 'postgresql'].includes(databaseType)) {
throw new Error('Missing or invalid database');
}

console.log(`Database schema detected: ${databaseType}`);
console.log(`Database type detected: ${databaseType}`);

const src = path.resolve(__dirname, `../prisma/schema.${databaseType}.prisma`);
const dest = path.resolve(__dirname, '../prisma/schema.prisma');
Expand Down

0 comments on commit 6833a5b

Please sign in to comment.