Package: django-migration-zero
Welcome todjango-migration-zero- the holistic implementation of "migration zero" pattern for
Django covering local changes and CI/CD pipeline adjustments.This package implements the "migration zero" pattern to clean up your local migrations and provides convenient
management commands to recreate your migration files and updating your migration history on your environments
(like test or production systems).PyPIGitHubFull documentationCreator & Maintainer:Ambient DigitalFeaturesRemove all existing local migration files and recreate them as initial migrationsConfiguration singleton in Django admin to prepare your clean-up deploymentManagement command for your pipeline to update Django's migration history table to reflect the changed migrationsMotivationWorking with any proper ORM will result in database changes which are reflected in migration files to update your
different environment's database structure. These files are versioned in your repository and if you follow any of the
most popular deployment approaches, they won't be needed when they are deployed on production. This means, they clutter
your repo, might lead to merge conflicts in the future and will slow down your test setup.Django's default way of handling this is called "squashing". This approach is covered broadly in theofficial documentation. The main
drawback here is, that you have to take care of circular dependencies between models. Depending on your project's
size, this can take a fair amount of time.The main benefit of squashing migrations is, that the history stays intact, therefore it can be used for example in
package which can be installed by anybody and you don't have control over their database.If you are working on a "regular" application, you have full control over your data(bases) and once everything has
been applied on the "last" system, typically production, the migrations are obsolete. To avoid spending much time on
fixing squashed migrations you won't need, you can use the "migration zero" pattern. In a nutshell, this means:Delete all your local migration filesRecreate initial migration files containing your current model stateFix the migration history on every of your environmentsInstallationInstall the package via pip:pip install django-migration-zeroor via pipenv:pipenv install django-migration-zeroAdd module toINSTALLED_APPSwithin the main djangosettings.py:INSTALLED_APPS = (
    ...
    'django_migration_zero',
)Apply migrations by running:python ./manage.py migrateAdd this block to your loggers in your main Djangosettings.pyto show
logs in your console."django_migration_zero":{"handlers":["console"],"level":"INFO","propagate":True,},ContributeSetup package for developmentCreate a Python virtualenv and activate itInstall "pip-tools" withpip install -U pip-toolsCompile the requirements withpip-compile --extra dev, -o requirements.txt pyproject.toml --resolver=backtrackingSync the dependencies with your virtualenv withpip-syncAdd functionalityCreate a new branch for your featureChange the dependency in your requirements.txt to a local (editable) one that points to your local file system:-e /Users/workspace/django-migration-zeroor via pippip install -e /Users/workspace/django-migration-zeroEnsure the code passes the testsCreate a pull requestRun testsRun testspytest --ds settings testsCheck coveragecoverage run -m pytest --ds settings tests
coverage report -mGit hooks (via pre-commit)We use pre-push hooks to ensure that only linted code reaches our remote repository and pipelines aren't triggered in
vain.To enable the configured pre-push hooks, you need toinstallpre-commit and run once:pre-commit install -t pre-push -t pre-commit --install-hooksThis will permanently install the git hooks for both, frontend and backend, in your local.git/hooksfolder.
The hooks are configured in the.pre-commit-config.yaml.You can check whether hooks work as intended using theruncommand:pre-commit run [hook-id] [options]Example: run single hookpre-commit run ruff --all-files --hook-stage pushExample: run all hooks of pre-push stagepre-commit run --all-files --hook-stage pushUpdate documentationTo build the documentation run:sphinx-build docs/ docs/_build/html/.Opendocs/_build/html/index.htmlto see the documentation.Translation filesIf you have added custom text, make sure to wrap it in_()where_is
gettext_lazy (from django.utils.translation import gettext_lazy as _).How to create translation file:Navigate todjango-migration-zeropython manage.py makemessages -l deHave a look at the new/changed files withindjango_migration_zero/localeHow to compile translation files:Navigate todjango-migration-zeropython manage.py compilemessagesHave a look at the new/changed files withindjango_migration_zero/localePublish to ReadTheDocs.ioFetch the latest changes in GitHub mirror and push themTrigger new build at ReadTheDocs.io (follow instructions in admin panel at RTD) if the GitHub webhook is not yet set
up.Publish to PyPiUpdate documentation about new/changed functionalityUpdate theChangelogIncrement version in main__init__.pyCreate pull request / merge to masterThis project uses the flit package to publish to PyPI. Thus publishing should be as easy as running:flit publishTo publish to TestPyPI use the following ensure that you have set up your .pypirc as
shownhereand use the following command:flit publish --repository testpypiMaintenancePlease note that this package supports theambient-package-update.
So you don't have to worry about the maintenance of this package. All important configuration and setup files are
being rendered by this updater. It works similar to well-known updaters likepyupgradeordjango-upgrade.To run an update, refer to thedocumentation pageof the "ambient-package-update".