Skip to main content

Capture django migration history snapshots

Project description

https://img.shields.io/badge/license-BSD-blue.svg https://readthedocs.org/projects/django-migration-snapshots/badge/?version=stable&style=flat https://img.shields.io/pypi/v/django-migration-snapshots.svg https://img.shields.io/pypi/pyversions/django-migration-snapshots https://img.shields.io/badge/code%20style-black-000000.svg

Capture snapshots of your django project’s migration history. These snapshots are represented as a directed graph using pygraphviz in both textual and graphical formats.

Documentation

The full documentation is at https://django-migration-snapshots.readthedocs.io.

Quickstart

Install Django Migration Snapshots:

pip install django-migration-snapshots

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    "migration_snapshots",
    ...
)

1) Execute management command to create snapshot

# creates snapshot of entire migration history
python manage.py create_snapshot

# filter migrations before applied date (YYYY-MM-DD)
python manage.py create_snapshot --date="2022-10-15"

2) Create object programmatically or from the admin panel

MigrationSnapshot.objects.create(output_format="pdf")

3) Automatically create migration snapshots with the post_migrate signal

from django.apps import AppConfig
from django.db.models.signals import post_migrate

def my_snapshot_callback(sender, **kwargs):
    # Create migration snapshot
    MigrationSnapshot.objects.create(output_format="pdf")

class MyAppConfig(AppConfig):
    ...

    def ready(self):
        # send signal only once after all migrations execute
        post_migrate.connect(my_snapshot_callback, sender=self)

Text Snapshot

digraph {
    "admin/0001_initial" -> "auth/0001_initial"
    "admin/0001_initial" -> "contenttypes/0001_initial"
    "admin/0002_logentry_remove_auto_add" -> "admin/0001_initial"
    "admin/0003_logentry_add_action_flag_choices" -> "admin/0002_logentry_remove_auto_add"
    "auth/0001_initial" -> "contenttypes/0001_initial"
    "auth/0002_alter_permission_name_max_length" -> "auth/0001_initial"
    ...
}

Graphical Snapshot

JPEG visual representation of migration history

Features

  • MigrationSnapshot data model

  • Supported output formats

    • BMP, CGIMAGE, DOT_CANON, DOT, GV, XDOT, XDOT12, XDOT14, EPS, EXR, FIG, GD, GIF, GTK, ICO, CMAP, ISMAP, IMAP, CMAPX, IMAGE_NP, CMAPX_NP, JPG, JPEG, JPE, JPEG_2000, JSON, JSON0, DOT_JSON, XDOT_JSON, PDF, PIC, PICT, APPLE_PICT, PLAIN_TEXT, PLAIN_EXT, PNG, POV_RAY, PS_PDF, PSD, SGI, SVG, SVGZ, TGA, TIF, TIFF, TK, VML, VMLZ, VRML, WBMP, WEBP, XLIB, X11

  • View migration history based on the miigration’s applied timestamp

TODO’s

  • Additional test coverage

  • Setup tox

  • Additional filters in management command (ie; per app, per model, etc.)

Local Development

make install
make test

Deployment

make build
make deploy

License

This project is provided under the BSD License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-migration-snapshots-0.5.1.tar.gz (12.7 kB view details)

Uploaded Source

File details

Details for the file django-migration-snapshots-0.5.1.tar.gz.

File metadata

File hashes

Hashes for django-migration-snapshots-0.5.1.tar.gz
Algorithm Hash digest
SHA256 d7057cc9227a12b8a7333cd5ead3394197edd8190c54192b4c8e25516de2c2cc
MD5 cb861df0a19ee6a0c4aa3efa9b45b887
BLAKE2b-256 5b84cadfe82a024a5fa655456d59bf2ab7a3a995b2969db78092b81eb30f6673

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page