2020-08-21 10:45:44 +02:00
|
|
|
require('dotenv').config();
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2020-09-04 20:06:32 +02:00
|
|
|
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();
|
2020-08-21 10:45:44 +02:00
|
|
|
|
2020-08-31 00:29:31 +02:00
|
|
|
if (!databaseType || !['mysql', 'postgresql'].includes(databaseType)) {
|
|
|
|
throw new Error('Missing or invalid database');
|
2020-08-21 10:45:44 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 20:06:32 +02:00
|
|
|
console.log(`Database type detected: ${databaseType}`);
|
2020-08-21 11:04:28 +02:00
|
|
|
|
2020-08-22 14:39:01 +02:00
|
|
|
const src = path.resolve(__dirname, `../prisma/schema.${databaseType}.prisma`);
|
2020-08-21 10:45:44 +02:00
|
|
|
const dest = path.resolve(__dirname, '../prisma/schema.prisma');
|
|
|
|
|
|
|
|
fs.copyFileSync(src, dest);
|
2020-08-21 11:04:28 +02:00
|
|
|
|
|
|
|
console.log(`Copied ${src} to ${dest}`);
|