Repository for managing changes to the database schema using alembic.
alembic.ini
: Alembic configuration filealembic/versions
: Alembic migration scriptsmodels.py
: SQLAlchemy declarative models for tables to create the initial/baseline version for the database.
Change directroy to the proper location, e.g. if migriaon is to be applied to the aiven database, change directory to aiven
:
alembic_src/aiven_postgres
Create new migration scripts by running the following command (see here):
alembic revision -m "Some message"
populate the upgrade
and downgrade
functions in the newly created migration script.
To apply the migration scripts to the database, run:
alembic upgrade head
To apply a migration script relative to the current revision, run:
alembic upgrade +1
To stamp the database version (i.e. set the version of databse manually), run:
alemibc stamp <revision>
<reviison>
can be found at the beggining of each migration script or on the name of the migration script file.
To downgrade the database to a specific version, run:
alembic downgrade <revision>
<reviison>
can be found at the beggining of each migration script or on the name of the migration script file.
To create a table in models.py
(i.e. create the initial version of the database), run:
alembic revision --autogenerate
This repo manages migration files for multiple databases (e.g. postgres hosted on aiven, neon, etc.). Each database has its own directory under alembic_src
. Each directory has the following structure:
alembic.ini
: Alembic configuration filealembic/versions
: Alembic migration scriptsmodels.py
: SQLAlchemy declarative models for tables to create the initial/baseline version for the database.