1
0
Fork 0
freesewing/sites/backend/scripts/newdb.mjs

33 lines
986 B
JavaScript
Raw Normal View History

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)
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 {
console.log(` 🚨 Going to create a database at ${chalk.cyan(db)}`)
2022-11-12 20:36:47 +01:00
fs.copyFile(schema, db, (err) => {
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) {
console.log(` ERROR: Unable to detect database file at ${db}`, err)
}
}
newDb()