Your blog app launches with no posts, and users leave frustrated. You decide to seed data using the seed.ts script from the lecture. What would happen if you ran this code without modifying it?
seed.ts
const prisma = new PrismaClient(); async function main() { await prisma.post.deleteMany(); await prisma.post.createMany({ data: [ { title: "Welcome", content: "Blog launch!", createdAt: new Date("2025-01-01"), tags: ["intro"] }, { title: "AI Future", content: "Tech is here.", createdAt: new Date("2025-02-15"), tags: ["tech"] }, ], }); }
The app would crash because prisma isn’t defined
prisma
Nothing would happen because the script isn’t linked to the database
The tags field would cause an error if the schema doesn’t have it
All existing posts in the database would be deleted
Two new posts would be added, keeping any existing posts
You’re working on the blog app with a team. You add a tags field to the Post model in schema.prisma. Which approach should you take to update the database safely, and why?
tags
Post
schema.prisma
Run both migrate dev and db push to be extra sure
migrate dev
db push
Do nothing; Prisma updates the database automatically
Run npx prisma migrate dev --name add_tags to track changes
npx prisma migrate dev --name add_tags
Manually edit the database with SQL to add the column
Run npx prisma db push because it’s faster
npx prisma db push
In the blog app, a user wants to filter posts by the tag "travel" using this query after seeding:
const posts = await prisma.post.findMany({ where: { tags: { has: "travel" } } });
Based on the advanced seeding example below, what would happen?
await prisma.post.createMany({ data: [ { title: "Welcome", content: "Blog launch!", createdAt: new Date("2025-01-01"), tags: ["intro", "welcome"] }, { title: "AI Future", content: "Tech is here.", createdAt: new Date("2025-02-15"), tags: ["tech", "innovation"] }, { title: "Mountain Trip", content: "Nature calls.", createdAt: new Date("2025-03-01"), tags: ["travel", "nature"] }, ], });
All three posts would return because they have tags
The query would fail due to a missing tags field
No posts would return because "travel" isn’t seeded
Only "Mountain Trip" would show up
Your blog app is live, and you accidentally run npx prisma db push after removing the content field from schema.prisma. What’s the impact?
content
The content column is dropped, and all post content could be lost
Prisma rolls back the change automatically
Nothing changes; db push only adds fields
Existing posts keep their content, but new posts won’t have it
The app crashes because content is referenced in queries
This content is only available to registered users.Please register at the the home page.