Routemaster uses alembic for its migrations, and supports
Postgres for its data storage.
-
Create a database for Routemaster to use.
Note: if you already have a local PostgreSQL database server configured, then you may be able to just run the
scripts/database/create_databases.shscript. -
Set up access credentials for the database in your environment variables.
You'll probably want to set
DB_USER(defaults toroutemaster) andDB_PASSfor running, though you also need to setPG_USERandPG_PASSfor the tests to use.A convenient way to do this is to add these to a
.envfile in the root of the repo and then source that file as part ofpostactivatein your virtualenv. -
Run
alembic upgrade head
Run alembic upgrade head. This is equivalent it manage.py migrate in
Django.
- Run
alembic revision --autogenerate -m "<message>" - Edit the file it just created, to sanity check and tidy it up.
alembic upgrade headto apply it.
If you are familiar with Django migrations there are a few differences to
makemigrations to note:
- The revision message is not an optional feature
- Due to the greater flexibility SQLAlchemy has compared with the Django ORM, migration systems have a much harder time reliably detecting changes and generating DDL. This means you always need to check and revise what Alembic generates in its migrations.
- The revision IDs are not, in general, date-ordered or sequential: the IDs
are random and the sequencing is declared programmatically in the migrations.
You can get the "sensible" history with
alembic history.