0
0
FastAPIframework~5 mins

Alembic migrations in FastAPI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Alembic used for in FastAPI projects?
Alembic helps manage database schema changes by creating and applying migrations. It keeps the database structure in sync with your code changes.
Click to reveal answer
beginner
What command initializes Alembic in your project?
The command alembic init alembic creates the Alembic folder and configuration files needed to start migrations.
Click to reveal answer
beginner
How do you create a new migration script with Alembic?
Use alembic revision -m "message" to create a new migration file where you define schema changes.
Click to reveal answer
beginner
What does the command alembic upgrade head do?
It applies all pending migrations to update the database schema to the latest version.
Click to reveal answer
intermediate
Why is it important to keep migration scripts under version control?
Migration scripts track database changes over time. Keeping them in version control helps teams share and apply consistent database updates safely.
Click to reveal answer
Which Alembic command creates the initial setup files?
Aalembic migrate
Balembic upgrade head
Calembic revision -m "init"
Dalembic init alembic
What does alembic revision -m "add users table" do?
AApplies the migration to the database
BCreates a new migration script with the message
CDeletes old migration scripts
DRolls back the last migration
How do you apply all migrations to update your database?
Aalembic upgrade head
Balembic downgrade base
Calembic create all
Dalembic migrate
Where do Alembic migration scripts live by default?
AIn the root project folder
BIn the database folder
CIn the alembic/versions folder
DIn the migrations folder
Why should you not edit migration scripts after applying them to production?
AIt can cause database inconsistencies
BBecause they are read-only files
CAlembic will delete them automatically
DThey are encrypted
Explain the steps to create and apply a new Alembic migration in a FastAPI project.
Think about setup, writing changes, and applying them.
You got /4 concepts.
    Describe why Alembic migrations are important for managing database changes in web applications.
    Consider teamwork and database consistency.
    You got /4 concepts.