2022-10-29 22:21:24 +02:00
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
|
|
|
import chalk from 'chalk'
|
|
|
|
import { banner } from '../../../scripts/banner.mjs'
|
|
|
|
import dotenv from 'dotenv'
|
|
|
|
dotenv.config()
|
|
|
|
|
|
|
|
const newDb = () => {
|
|
|
|
// Say hi
|
|
|
|
console.log(banner + '\n')
|
2022-11-12 20:36:47 +01:00
|
|
|
const db = process.env.BACKEND_DB_URL.slice(6)
|
2022-10-29 22:21:24 +02:00
|
|
|
console.log(db)
|
|
|
|
const schema = path.resolve('./prisma/schema.sqlite')
|
|
|
|
try {
|
|
|
|
if (fs.existsSync(db)) {
|
|
|
|
console.log(` ⛔ Database detected - Not proceeding`)
|
|
|
|
console.log(` If you want to create a new database, remove this file: ${chalk.cyan(db)}`)
|
2022-11-12 20:36:47 +01:00
|
|
|
} else {
|
2022-10-29 22:21:24 +02:00
|
|
|
console.log(` 🚨 Going to create a database at ${chalk.cyan(db)}`)
|
2022-11-12 20:36:47 +01:00
|
|
|
fs.copyFile(schema, db, (err) => {
|
2022-10-29 22:21:24 +02:00
|
|
|
if (err) console.log(` ⚠️ ${chalk.red(err)}: Unable to create database file`, err)
|
|
|
|
else {
|
|
|
|
console.log(` ${chalk.green('Database created')}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-11-12 20:36:47 +01:00
|
|
|
} catch (err) {
|
2022-10-29 22:21:24 +02:00
|
|
|
console.log(` ERROR: Unable to detect database file at ${db}`, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newDb()
|