Simplify seed script
This commit is contained in:
@@ -1,44 +1,31 @@
|
|||||||
import { db } from '$api/src/lib/db'
|
import { db } from 'api/src/lib/db'
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
try {
|
const POSTS = [
|
||||||
//
|
{
|
||||||
// Manually seed via `yarn rw prisma db seed`
|
title: 'Welcome to the blog!',
|
||||||
// Seeds automatically with `yarn rw prisma migrate dev` and `yarn rw prisma migrate reset`
|
body:
|
||||||
//
|
"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.",
|
||||||
// Update "const data = []" to match your data model and seeding needs
|
},
|
||||||
//
|
{
|
||||||
const POSTS = [
|
title: 'A little more about me',
|
||||||
{
|
body:
|
||||||
title: 'Welcome to the blog!',
|
"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.",
|
||||||
body: "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.",
|
},
|
||||||
},
|
{
|
||||||
{
|
title: 'What is the meaning of life?',
|
||||||
title: 'A little more about me',
|
body:
|
||||||
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.",
|
'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.',
|
||||||
},
|
},
|
||||||
{
|
]
|
||||||
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.',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
// Note: if using PostgreSQL, using `createMany` to insert multiple records is much faster
|
for (const post of POSTS) {
|
||||||
// @see: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#createmany
|
await db.post.upsert({
|
||||||
Promise.all(
|
where: { title: post.title },
|
||||||
//
|
create: { title: post.title, body: post.body },
|
||||||
// Change to match your data model and seeding needs
|
update: {},
|
||||||
//
|
})
|
||||||
POSTS.map(async (post) => {
|
|
||||||
const record = await db.post.create({
|
|
||||||
data: { title: post.title, body: post.body },
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(record)
|
console.log(`Added ${post.title}`)
|
||||||
})
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Please define your seed data.')
|
|
||||||
console.error(error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user