Skip to content

09. Database migration

kevin-hashimoto edited this page Mar 4, 2024 · 1 revision

The migrate.sh script inside the backend directory is a versatile tool for managing database migrations in this fastapi project. It automates various tasks related to Alembic, including generating new migrations, upgrading and downgrading the database, and managing the virtual environment and dependencies.

Usage

Make Script Executable

chmod +x migrate.sh

Generating Migrations

Generate a new migration with a descriptive message:

./migrate.sh -g "Description of changes"

Upgrading Database

Upgrade the database to a specific revision or to the latest version:

./migrate.sh -u [revision]

Omit [revision] to upgrade to the latest version (head).

Downgrading Database

Downgrade the database to a specific revision or to the base state:

./migrate.sh -d [revision]

Omit [revision] to revert to the base state.

Help Manual

Display the help manual for script usage:

./migrate.sh -h