umami/scripts/copy-db-files.js

33 lines
782 B
JavaScript
Raw Normal View History

2022-11-04 05:33:37 +01:00
/* eslint-disable no-console */
2020-08-21 10:45:44 +02:00
require('dotenv').config();
2022-06-12 08:38:58 +02:00
const fse = require('fs-extra');
2020-08-21 10:45:44 +02:00
const path = require('path');
const del = require('del');
2020-08-21 10:45:44 +02:00
2022-08-28 06:38:35 +02:00
function getDatabaseType(url = process.env.DATABASE_URL) {
const type = process.env.DATABASE_TYPE || (url && url.split(':')[0]);
if (type === 'postgres') {
return 'postgresql';
}
return type;
}
2022-06-22 10:50:33 +02:00
const databaseType = getDatabaseType();
2020-08-21 10:45:44 +02:00
if (!databaseType || !['mysql', 'postgresql'].includes(databaseType)) {
throw new Error('Missing or invalid database');
2020-08-21 10:45:44 +02:00
}
console.log(`Database type detected: ${databaseType}`);
2020-08-21 11:04:28 +02:00
2022-06-19 09:07:01 +02:00
const src = path.resolve(__dirname, `../db/${databaseType}`);
const dest = path.resolve(__dirname, '../prisma');
2020-08-21 10:45:44 +02:00
del.sync(dest);
2022-06-19 09:07:01 +02:00
fse.copySync(src, dest);
2020-08-21 11:04:28 +02:00
console.log(`Copied ${src} to ${dest}`);