No project description provided
Project description
Django application providing database migration tooling to automate their deployment.
Inspired by a 2015 post from Ludwig Hähne and experience dealing with migration at Zapier.
Installation
pip install django-syzygy
Usage
Add 'syzygy' to your INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
...
'syzygy',
...
]
Setup you deployment pipeline to run migrate --pre-deploy before rolling out your code changes and migrate afterwards to apply the postponed migrations.
Concept
Syzygy introduces a notion of prerequisite and postponed migrations with regards to deployment.
A migration is assumed to be a prerequisite to deployment unless it contains a destructive operation or the migration has its stage class attribute set to Stage.POST_DEPLOY. When this attribute is defined it will bypass operations based heuristics.
e.g. this migration would be considered a prerequisite
class Migration(migrations.Migration):
operations = [
AddField('model', 'field', models.IntegerField(null=True))
]
while the following migrations would be postponed
class Migration(migrations.Migration):
operations = [
RemoveField('model', 'field'),
]
from syzygy import Stage
class Migration(migrations.Migration):
stage = Stage.POST_DEPLOY
operations = [
RunSQL(...),
]
In order to prevent the creation of migrations mixing operations of different stages this package registers system checks. These checks will generate an error for every migration with an ambiguous stage.
e.g. this migration would result in a check error
class Migration(migrations.Migration):
operations = [
AddField('model', 'other_field', models.IntegerField(null=True)),
RemoveField('model', 'field'),
]
Migration revert are also supported and result in inverting the nature of migrations. A migration that is normally considered a prerequisite would then be postponed when reverted.
With this new notion of migration stage it’s possible for the migrate command to target only migrations meant to be run before a deployment using the –pre-deploy flag or error out in the case on an ambiguous plan.
Third-party migrations
As long as the adoption of migration stages concept not generalized your project might depend on third-party apps containing migrations with an ambiguous sequence of operations.
Since an explicit stage cannot be explicitly assigned by editing these migrations a fallback or an override stage can be specified through the respective MIGRATION_STAGES_FALLBACK and MIGRATION_STAGES_OVERRIDE settings.
By default third-party app migrations with an ambiguous sequence of operations will fallback to Stage.PRE_DEPLOY but this behavior can be changed by setting MIGRATION_THIRD_PARTY_STAGES_FALLBACK to Stage.POST_DEPLOY or disabled by setting it to None.
Development
Make your changes, and then run tests via tox:
tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-syzygy-0.1.0a4.tar.gz
.
File metadata
- Download URL: django-syzygy-0.1.0a4.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fec6f384080c79813c3c73fd3b88407b63d666402abcf2f8a6f2b85dc0e03c0a |
|
MD5 | 580c67e708fc6592aeefba43ec221636 |
|
BLAKE2b-256 | 52a0835ad642cd803f85dcaea0f63ac9fa86b8eee10f7056207a6fa14cb204ea |
File details
Details for the file django_syzygy-0.1.0a4-py2.py3-none-any.whl
.
File metadata
- Download URL: django_syzygy-0.1.0a4-py2.py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8a76b79bbd13c1c99fbb711ef606e321d12147dac4f65e2535abc99ceb0d73 |
|
MD5 | eb968d3ec6d87b6fbe9bf700bf0ab125 |
|
BLAKE2b-256 | bad157992cb5ef66276d18ff66133df19e477508a84c5bb861d41ccca120e191 |