0
0
NextJSframework~20 mins

Database migrations in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Database Migration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding migration effect on Next.js app

You have a Next.js app using Prisma for database migrations. After running prisma migrate dev, what happens to your database schema?

AThe Prisma schema file is overwritten with the current database schema.
BThe database schema resets to an empty state, deleting all data.
CNothing changes until you restart the Next.js server.
DThe database schema updates to match the Prisma schema, and a new migration file is created.
Attempts:
2 left
💡 Hint

Think about what prisma migrate dev does to keep your database and Prisma schema in sync.

📝 Syntax
intermediate
2:00remaining
Identify the correct migration script syntax

Which of the following Prisma migration schema snippets correctly adds a new email field to a User model?

Amodel User { id Int @id @default(autoincrement()) email String? }
Bmodel User { id Int @id @default(autoincrement()) email Boolean }
Cmodel User { id Int @id @default(autoincrement()) email String }
Dmodel User { id Int @id @default(autoincrement()) email Int }
Attempts:
2 left
💡 Hint

Consider the data type for an email address and whether it should be optional.

🔧 Debug
advanced
2:00remaining
Fix migration error due to conflicting schema changes

You run prisma migrate dev but get an error about conflicting migrations. What is the likely cause?

AYou have two migration files that change the same table in incompatible ways.
BYour Prisma client is outdated and needs to be reinstalled.
CYou forgot to restart the Next.js server after schema changes.
DYour database connection string is missing in the .env file.
Attempts:
2 left
💡 Hint

Think about what happens when multiple migrations try to change the same part of the database.

state_output
advanced
2:00remaining
Result of migration rollback in Next.js Prisma setup

After applying several migrations, you run prisma migrate reset. What is the state of your database?

AOnly the last migration is undone, keeping previous migrations intact.
BThe database is dropped, recreated, and all migrations are reapplied from scratch.
CThe database schema stays the same but all data is deleted.
DNothing happens unless you manually delete migration files.
Attempts:
2 left
💡 Hint

Consider what prisma migrate reset does to the database and migrations.

🧠 Conceptual
expert
2:00remaining
Choosing migration strategy for production Next.js app

You want to deploy a Next.js app with Prisma to production. Which migration strategy ensures safe schema updates without data loss?

AUse <code>prisma migrate deploy</code> to apply tested migration files without resetting the database.
BRun <code>prisma migrate reset</code> on production to ensure a clean schema.
CManually edit the database schema and skip Prisma migrations.
DDelete all migration files and generate new ones on production.
Attempts:
2 left
💡 Hint

Think about how to safely update a live database without losing data.