Configuration¶
delembic.ini¶
Delembic reads configuration from delembic.ini. It walks up from the current directory, so you can run delembic commands from any subdirectory of your project.
Full example¶
[delembic]
script_location = delembic
sqlalchemy.url = postgresql+psycopg://user:pass@localhost/mydb
alembic_config = alembic.ini
Options¶
script_locationPath to the folder containing
versions/. Relative to the location ofdelembic.ini. Default:delembicsqlalchemy.urlSQLAlchemy database URL. Required. Examples:
postgresql+psycopg://user:pass@localhost/mydb postgresql+psycopg2://user:pass@localhost/mydb sqlite:///data.db sqlite:///:memory:
alembic_configPath to your
alembic.ini. Relative todelembic.ini. Optional — only needed if you use Alembic integration. When set,delembic revisionwill auto-capture current Alembic heads intodepends_on.
Custom Folder Name¶
delembic init data-migrations
delembic.ini is updated automatically:
[delembic]
script_location = data-migrations
Environment Variables¶
Delembic does not read environment variables directly. Use env.py (generated by delembic init) to inject them:
# delembic/env.py
import os
from sqlalchemy import create_engine
DATABASE_URL = os.environ["DATABASE_URL"]
def get_engine():
return create_engine(DATABASE_URL)
Then reference it from your migrations if needed, or configure sqlalchemy.url to read from env using a wrapper.
Metadata Tables¶
Delembic automatically creates two tables on first run:
delembic_version¶
Current status per revision. One row per revision, replaced on retry.
Column |
Type |
Description |
|---|---|---|
|
TEXT |
Revision ID (e.g. |
|
TEXT |
|
|
DATETIME |
When this run started |
|
FLOAT |
How long the migration took |
|
TEXT |
OS user who ran the migration |
|
TEXT |
Hostname where migration ran |
delembic_run_history¶
Full append-only audit log. Every run appended, never deleted.
Column |
Type |
Description |
|---|---|---|
|
INTEGER |
Auto-increment primary key |
|
TEXT |
Revision ID |
|
TEXT |
|
|
DATETIME |
Run start time |
|
DATETIME |
Run end time |
|
FLOAT |
Duration |
|
TEXT |
Full traceback (failures only) |
|
TEXT |
OS user |
|
TEXT |
Hostname |
Note
Failed migration work is rolled back. The failure record is always committed on a separate connection — the audit trail survives transaction failures.