Alembic Migrations — Evolving the Schema Safely — Concept Check
Questions on Alembic Migrations — Evolving the Schema Safely. Alembic versions your schema like git versions code: autogenerate diffs models against the DB, you review the script, alembic upgrade head applies it — and create_all never touches production.
Questions in this quiz
7 questions on Alembic Migrations — Evolving the Schema Safely — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have added a new column to your model, but it doesn't appear in production. What might be the reason?
- ABase.metadata.create_all() doesn't alter existing tables.
- BThe database is in read-only mode.
- CThe column was added directly to the database.
- DAlembic upgrade head wasn't run.
2.During a migration, you renamed a column from 'cgpa' to 'gpa'. After autogenerating, what should you do?
- ARun alembic upgrade head immediately.
- BDelete the autogenerated script and start over.
- CManually alter the column name in the script.
- DRevert the model changes.
3.What is a key step before deploying new code that relies on a schema change?
- AEdit the migration script after deployment.
- BDeploy new code before running migrations.
- CRun alembic upgrade head before serving traffic.
- DDirectly alter the database schema in production.
4.You need to add an index to a busy Postgres table. What should you do?
- ARun alembic revision without reviewing the script.
- BUse a simple CREATE INDEX command.
- CUse CREATE INDEX CONCURRENTLY with op.execute.
- DAdd the index directly in the model and run create_all().
5.Why is it important to review autogenerated migration scripts?
- AScripts are always perfect without review.
- BScripts can't be committed without review.
- CAutogenerate can misinterpret schema changes like renames.
- DReviewing scripts is optional and only for learning.
6.In a migration, you need to backfill data for a new NOT NULL column. What should you do?
- AAdd the column without a default and backfill later.
- BIgnore backfilling as it's not necessary.
- CAdd a server default and backfill data in batches.
- DDirectly update all rows in a single transaction.
7.What happens if you edit a migration script after it has run on a shared database?
- AIt updates the schema automatically.
- BIt can cause inconsistencies and should be avoided.
- CIt has no effect as the script is already executed.
- DIt is necessary for schema corrections.