Skip to content

Latest commit

 

History

History
35 lines (18 loc) · 1.49 KB

README.md

File metadata and controls

35 lines (18 loc) · 1.49 KB

Migrations

We use Alembic to create and run incremental database migrations when we change the Arlo data model.

The Alembic docs have great info on the ins and outs of creating and running migrations, but here's a sample workflow:

Create a migration script

First, make sure the database is in the existing, unmigrated state. Two options:

  • Check out the last commit, then run:

    make resetdb
    
  • Restore from a database backup

Then, use Alembic to autogenerate a migration script:

poetry run alembic revision --autogenerate -m "Some description of the migration"

The resulting migration script will be in migrations/versions.

Edit the migration script

The autogeneration capabilities of Alembic will only get you so far, so you always need to go manually check and edit the script. For example, Alembic won't autogenerate updates to primary key constraints. Read the docs for specific info about the autogeneration capabilities.

Note that we don't support reverse migrations (alembic downgrade) because we don't think it's worth the effort to implement them. So you should comment out the autogenerated downgrade code and replace it with pass.

Test the migration script

Populate your local database with some data (e.g. restored from a backup), then run:

poetry run alembic upgrade head

...and see if it works!