0
0
Flaskframework~20 mins

Database migration in deployment in Flask - 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!
🧠 Conceptual
intermediate
2:00remaining
Understanding Flask-Migrate's role in deployment

What is the primary purpose of Flask-Migrate during the deployment of a Flask application?

ATo automatically update the database schema to match the current models without losing data
BTo create a backup of the database before deployment
CTo optimize SQL queries for faster performance
DTo generate HTML forms for database models
Attempts:
2 left
💡 Hint

Think about how your database structure changes when you update your code models.

component_behavior
intermediate
2:00remaining
Behavior of migration commands in Flask

What happens when you run flask db migrate followed by flask db upgrade during deployment?

A<code>flask db migrate</code> applies migrations; <code>flask db upgrade</code> rolls back changes
B<code>flask db migrate</code> generates migration scripts; <code>flask db upgrade</code> applies them to the database
C<code>flask db migrate</code> deletes old migrations; <code>flask db upgrade</code> creates new tables
D<code>flask db migrate</code> backs up the database; <code>flask db upgrade</code> restores it
Attempts:
2 left
💡 Hint

One command prepares changes, the other applies them.

🔧 Debug
advanced
3:00remaining
Fixing migration script conflicts

You deployed a Flask app and ran migrations. Later, a teammate also created migrations on their branch. When merging, you get a conflict in migration scripts. What is the best way to resolve this?

AIgnore the conflict and run <code>flask db upgrade</code> anyway
BDelete all migration files and recreate them from scratch
CManually merge the conflicting migration files and then run <code>flask db upgrade</code>
DRevert the database to the previous state and avoid merging branches
Attempts:
2 left
💡 Hint

Migration files are code and can be merged carefully.

state_output
advanced
2:30remaining
Database state after partial migration

After running flask db migrate and partially applying flask db upgrade, the deployment crashes. What is the likely state of the database?

AThe database schema is partially updated, causing inconsistencies and errors
BThe database schema is fully updated and consistent
CThe database schema remains unchanged from before migration
DThe database is completely reset to an empty state
Attempts:
2 left
💡 Hint

Think about what happens if migration scripts are interrupted.

📝 Syntax
expert
3:00remaining
Correct Alembic migration script snippet

Which option shows the correct way to add a new column age of type Integer to the users table in an Alembic migration script?

Aop.add_column('users', Column('age', Integer))
Bop.add_column('users', sa.Column('age', sa.Int(), nullable=True))
Cadd_column('users', sa.Column('age', Integer, nullable=False))
Dop.add_column('users', sa.Column('age', sa.Integer(), nullable=True))
Attempts:
2 left
💡 Hint

Remember to use the correct Alembic and SQLAlchemy syntax with proper imports.