Adds default database seeds
This commit is contained in:
@@ -5,18 +5,38 @@ const dotenv = require('dotenv')
|
|||||||
dotenv.config()
|
dotenv.config()
|
||||||
const db = new PrismaClient()
|
const db = new PrismaClient()
|
||||||
|
|
||||||
async function main() {
|
const POSTS = [
|
||||||
// Seed data is database data that needs to exist for your app to run.
|
{
|
||||||
// Ideally this file should be idempotent: running it multiple times
|
title: 'Welcome to the blog!',
|
||||||
// will result in the same database state (usually by checking for the
|
body:
|
||||||
// existence of a record before trying to create it). For example:
|
"I'm baby single- origin coffee kickstarter lo - fi paleo skateboard.Tumblr hashtag austin whatever DIY plaid knausgaard fanny pack messenger bag blog next level woke.Ethical bitters fixie freegan,helvetica pitchfork 90's tbh chillwave mustache godard subway tile ramps art party. Hammock sustainable twee yr bushwick disrupt unicorn, before they sold out direct trade chicharrones etsy polaroid hoodie. Gentrify offal hoodie fingerstache.",
|
||||||
//
|
},
|
||||||
// const existing = await db.user.findMany({ where: { email: 'admin@email.com' }})
|
{
|
||||||
// if (!existing.length) {
|
title: 'A little more about me',
|
||||||
// await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }})
|
body:
|
||||||
// }
|
"Raclette shoreditch before they sold out lyft. Ethical bicycle rights meh prism twee. Tote bag ennui vice, slow-carb taiyaki crucifix whatever you probably haven't heard of them jianbing raw denim DIY hot chicken. Chillwave blog succulents freegan synth af ramps poutine wayfarers yr seitan roof party squid. Jianbing flexitarian gentrify hexagon portland single-origin coffee raclette gluten-free. Coloring book cloud bread street art kitsch lumbersexual af distillery ethical ugh thundercats roof party poke chillwave. 90's palo santo green juice subway tile, prism viral butcher selvage etsy pitchfork sriracha tumeric bushwick.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'What is the meaning of life?',
|
||||||
|
body:
|
||||||
|
'Meh waistcoat succulents umami asymmetrical, hoodie post-ironic paleo chillwave tote bag. Trust fund kitsch waistcoat vape, cray offal gochujang food truck cloud bread enamel pin forage. Roof party chambray ugh occupy fam stumptown. Dreamcatcher tousled snackwave, typewriter lyft unicorn pabst portland blue bottle locavore squid PBR&B tattooed.',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
console.info('No data to seed. See api/prisma/seeds.js for info.')
|
const asyncForEach = async (array, callback) => {
|
||||||
|
for (let index = 0; index < array.length; index++) {
|
||||||
|
await callback(array[index], index, array)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const existing = await db.post.findMany()
|
||||||
|
|
||||||
|
asyncForEach(POSTS, async (post) => {
|
||||||
|
if (!existing.find((ex) => ex.title === post.title)) {
|
||||||
|
await db.post.create({ data: post })
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user