2021-12-13 15:34:37 -03:00
import { PrismaClient } from '@prisma/client'
2021-12-15 14:05:27 -03:00
import { hashSync } from 'bcryptjs'
2021-12-18 00:50:54 -03:00
import cuid from 'cuid'
2021-12-15 14:05:27 -03:00
import dotenv from 'dotenv'
2021-12-13 15:34:37 -03:00
const prisma = new PrismaClient ( )
2021-12-15 14:05:27 -03:00
dotenv . config ( {
path : './.env'
} )
2021-12-13 15:34:37 -03:00
async function main() {
const data = {
settings : {
avatar : '/avatar.jpeg' ,
name : 'John Doe' ,
description :
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod, nisl eget aliquam consectetur, nisl nunc aliquet nunc, euismod aliquam nunc nisl euismod.' ,
2021-12-19 20:03:59 -03:00
font : 'oswald' ,
2021-12-18 22:41:05 -03:00
buttonBorderRadius : '4' ,
2021-12-13 15:34:37 -03:00
colors : {
2021-12-18 22:41:05 -03:00
texts : '#e11d48' ,
icons : '#e11d48' ,
background : '#f8fafc' ,
buttonLabelColor : '#f8fafc' ,
buttonBackgroundColor : '#e11d48' ,
buttonBorderColor : '#e11d48'
2021-12-13 15:34:37 -03:00
}
} ,
2021-12-23 14:51:34 -03:00
socialLinks : {
Facebook : '1' ,
Instagram : '2' ,
Snapchat : '3' ,
Twitter : '4' ,
Messenger : '5' ,
WhatsApp : '' ,
LinkedIn : '' ,
GitHub : '' ,
Dev : '' ,
Medium : '' ,
YouTube : '' ,
Twitch : '' ,
Discord : '' ,
Steam : '' ,
Email : ''
} ,
2021-12-13 15:34:37 -03:00
buttonLinks : [
{
2021-12-18 00:50:54 -03:00
id : cuid ( ) ,
2021-12-13 15:34:37 -03:00
label : 'Home' ,
href : '#'
} ,
{
2021-12-18 00:50:54 -03:00
id : cuid ( ) ,
2021-12-13 15:34:37 -03:00
label : 'About' ,
2021-12-18 00:50:54 -03:00
href : '#'
2021-12-13 15:34:37 -03:00
} ,
{
2021-12-18 00:50:54 -03:00
id : cuid ( ) ,
2021-12-13 15:34:37 -03:00
label : 'Contact' ,
2021-12-18 00:50:54 -03:00
href : '#'
2021-12-13 15:34:37 -03:00
}
]
}
2021-12-15 08:11:58 -03:00
const hasData = await prisma . data . findUnique ( {
2021-12-15 14:05:27 -03:00
where : { id : 1 }
2021-12-15 08:11:58 -03:00
} )
2021-12-13 15:34:37 -03:00
if ( ! hasData ) {
await prisma . data . create ( {
2021-12-15 08:11:58 -03:00
data : {
id : 1 ,
data : JSON.stringify ( data )
}
2021-12-13 15:34:37 -03:00
} )
}
2021-12-15 14:05:27 -03:00
const hasUser = await prisma . user . findFirst ( )
if ( ! hasUser ) {
const { USERNAME , PASSWORD } = process . env
if ( ! USERNAME || ! PASSWORD ) {
throw new Error ( 'USERNAME and PASSWORD env variables are required' )
}
await prisma . user . create ( {
data : {
username : USERNAME ,
password : hashSync ( PASSWORD , 10 ) ,
2021-12-23 14:51:34 -03:00
lang : 'en' ,
2021-12-15 14:05:27 -03:00
role : 'ADMIN'
}
} )
}
2021-12-13 15:34:37 -03:00
}
main ( )
2021-12-23 14:51:34 -03:00
. catch ( err = > {
console . error ( err )
2021-12-13 15:34:37 -03:00
process . exit ( 1 )
} )
. finally ( async ( ) = > {
await prisma . $disconnect ( )
} )