Be Chiller Too
Be Chiller Too

Reputation: 2910

How to debug Alembic migrations inside VS Code?

Say I have a migration script like this one:

# revision identifiers, used by Alembic.
revision = 'b5c9e0aac59b'
down_revision = '4658d3e26bae'
branch_labels = None
depends_on = None

def upgrade():
    print("hello world!")

And I want to place a breakpoint on the line that contains the print statement.

How can I configure VS Code to launch the command alembic -n sandbox upgrade b5c9e0aac59b (or python -m alembic -n sandbox upgrade b5c9e0aac59b), and use VS Code debugging features?

Upvotes: 4

Views: 578

Answers (1)

Alexander Lyapin
Alexander Lyapin

Reputation: 359

You need to create launch.json in .vscode folder and add configuration for executing alembic migration.

For example to upgrade to head:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Alembic upgrade head",
      "type": "debugpy",
      "request": "launch",
      "module": "alembic",
      "args": ["upgrade", "head"]
    }
}

This is the same as run alembic upgrade head in the terminal. You can modify "args" to reflect your particular case.

Upvotes: 0

Related Questions