alembic Flashcards

(25 cards)

1
Q

Primary purpose of Alembic

A

Database schema migration and version control

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ORM Alembic is built for

A

SQLAlchemy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Command to initialize a new Alembic environment

A

alembic init <directory_name></directory_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

File containing database connection string (URL)

A

alembic.ini

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Python script that runs the migration environment

A

env.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Command to generate a new migration script

A

alembic revision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Flag to automatically detect schema changes from models

A

–autogenerate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Object in env.py that must be set for autogenerate to work

A

target_metadata

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Command to apply all pending migrations

A

alembic upgrade head

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Command to revert the most recent migration

A

alembic downgrade -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Table Alembic creates in the DB to track versions

A

alembic_version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Term for the very latest version in the migration chain

A

head

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Term for the state before any migrations are applied

A

base

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Function inside a migration script used to apply changes

A

upgrade()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Function inside a migration script used to revert changes

A

downgrade()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Command to view the migration history

A

alembic history

17
Q

Command to show the current database revision

A

alembic current

18
Q

Unique identifier for each migration script

A

Revision ID (hash)

19
Q

Template file used to generate new migration scripts

A

script.py.mako

20
Q

Flag to add a message/comment to a revision

A

-m “message”

21
Q

Typical location of the versions directory

A

Inside the alembic directory (e.g., alembic/versions)

22
Q

Command to generate SQL without executing it

A

alembic upgrade –sql

23
Q

How to resolve multiple heads in migration history

A

Create a merge revision (alembic merge heads)

24
Q

Common cause of ‘Target database is not up to date’ error

A

New migrations exist in the versions folder that haven’t been applied to the DB

25
Safe practice before running upgrade in production
Review the generated migration script manually