Alembic is a migration tool for SQLAlchemy. It is a flexible tool for managing database migrations. Below, we’ll walk through the process of setting up Alembic in a project and running your first migration. We’ll start with an example project that has Alembic already set up, and you can follow along with the steps below. Alternatively, you can run these steps in your own project.Documentation Index
Fetch the complete documentation index at: https://thenile.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Running an Example Migration
Create a Migration Script
In the example project, we have a migration script already created.
You can find it in the This will generate a new file:
./alembic/versions directory.Here’s how to create a new migration script:./alembic/versions/13379be60997_create_account_table.py. Now we want to edit the file and add the migration script to it:Connect to Database
To connect Alembic to the right database, create a You can get your connection string from the Nile database home page.
.env file and add the connection string there:Generating Migrations
Alembic can also generate migrations for you. This is useful if you want to create a migration for a new table.Create a new migration
The example project has a
models.py file that defines two models: Todo and Tenant.To generate a migration for these models, you can use the following command: