-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds some basic tests to ensure our migrations run successfully and yield the same resulting db schema as our models. How we do it: - Create an initial migration from the empty database to the database before our current first migration - Leverage pytest-alembic, a plugin that runs these basic tests for you
- Loading branch information
1 parent
c6a4c7f
commit 1f24228
Showing
12 changed files
with
597 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Migrations | ||
|
||
We use [Alembic](https://alembic.sqlalchemy.org/en/latest/) 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 (e.g. by checking out the last commit and running `make resetdb`, or restoring from a database backup). | ||
|
||
Then, use Alembic to autogenerate a migration script: | ||
|
||
pipenv 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](https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect) 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: | ||
|
||
pipenv run alembic upgrade head | ||
|
||
...and see if it works! |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.