{"id":13771942,"url":"https://github.com/businho/django-migrations-ci","last_synced_at":"2026-02-28T22:11:07.858Z","repository":{"id":61781848,"uuid":"554843579","full_name":"businho/django-migrations-ci","owner":"businho","description":"Cached migrations on CI (and local) for faster migrations ","archived":false,"fork":false,"pushed_at":"2025-09-09T09:43:12.000Z","size":174,"stargazers_count":32,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-15T04:18:28.641Z","etag":null,"topics":["database","django","migrations","mysql","postgres","python","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/businho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-10-20T13:47:42.000Z","updated_at":"2025-12-03T10:12:59.000Z","dependencies_parsed_at":"2022-10-21T04:00:34.737Z","dependency_job_id":"f487b447-a320-4c35-958a-47830c7aec9e","html_url":"https://github.com/businho/django-migrations-ci","commit_stats":{"total_commits":148,"total_committers":3,"mean_commits":"49.333333333333336","dds":"0.027027027027026973","last_synced_commit":"bc19219611031a8967423367a345b931423fe516"},"previous_names":["businho/django-migrations-ci","buserbrasil/django-migrations-ci","iurisilvio/django-migrations-ci"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/businho/django-migrations-ci","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/businho%2Fdjango-migrations-ci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/businho%2Fdjango-migrations-ci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/businho%2Fdjango-migrations-ci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/businho%2Fdjango-migrations-ci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/businho","download_url":"https://codeload.github.com/businho/django-migrations-ci/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/businho%2Fdjango-migrations-ci/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29953212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T18:42:55.706Z","status":"ssl_error","status_checked_at":"2026-02-28T18:42:48.811Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","django","migrations","mysql","postgres","python","sqlite3"],"created_at":"2024-08-03T17:00:57.885Z","updated_at":"2026-02-28T22:11:07.824Z","avatar_url":"https://github.com/businho.png","language":"Python","funding_links":[],"categories":["Plugins"],"sub_categories":[],"readme":"# django-migrations-ci\n\nReuse database state on CI. Run migrations on CI tests only for changes.\n\nMigrations are slow, but you have to run it on CI for testing reasons, so avoid\nto run them when the database state was already tested.\n\n## Install\n\nInstall the package with pip:\n\n```shell\npip install django-migrations-ci\n```\n\nAdd `django_migrations_ci` to Django settings `INSTALLED_APPS`.\n\n```python\nINSTALLED_APPS = [\n    ...,  # other packages\n    \"django_migrations_ci\",\n]\n```\n\n## How to use\n\nThe command `migrateci` execute all migrations and save dump files `migrateci-*`.\n\nIf these files already exist on disk, they are used to prepare the database\nwithout running all migrations again.\n\n## Workflow\n\nThis is how the \"run test\" CI job should work.\n\n```shell\n./manage.py migrateci\n./manage.py test --keepdb\n```\n\nIt works with `pytest-django` too as a plugin:\n\n```shell\npytest --migrateci --reuse-db\n```\n\nThe recommended way to work with it is configuring default [pytest `addopts`](https://docs.pytest.org/en/7.1.x/example/simple.html#how-to-change-command-line-options-defaults) with `--migrateci --reuse-db` to run without recreating database. When you want to recreate, run pytest with `--create-db` that has precedence over `--reuse-db`.\n\n\n## Parallel tests\n\n```shell\n./manage.py migrateci --parallel $(nproc)\n./manage.py test --keepdb --parallel $(nproc)\n```\n\n### Parallel tests with pytest-django\n\n```shell\npytest --migrateci --reuse-db --parallel $(nproc)\n```\n\nAlso check [database names for parallel tests](#database-names-for-parallel-tests).\n\n## Settings\n\n##### `MIGRATECI_STORAGE=\"django.core.files.storage.FileSystemStorage\"`\n\nFile storage class. The [django-storages](https://pypi.org/project/django-storages/) package has many backends implemented.\n\nSaving cache files to an external storage allow the lib to reuse partial migrations.\nWhen you write a new migration, it will try to get a cache without this\nlast migration and load from it, running only the new migrations.\n\nAn S3 example,, but it works with any custom backend:\n\n```python\nfrom storages.backends.s3boto3 import S3Boto3Storage\n\nclass MigrateCIStorage(S3Boto3Storage):\n    bucket_name = \"mybucket-migrateci-cache\"\n    region_name = \"us-east-1\"\n    object_parameters = {\n        \"StorageClass\": \"REDUCED_REDUNDANCY\",\n    }\n```\n\n##### `MIGRATECI_LOCATION=\"\"`\n\n[File storage API](https://docs.djangoproject.com/en/4.1/ref/files/storage/#the-filesystemstorage-class) has a location arg that all backend use in some way.\n\nIf no storage is defined, it defaults to `~/.migrateci` to make it easy to work local.\n\n##### `MIGRATECI_PYTEST=False`\n\nThe [`pytest-django`](https://pypi.org/project/pytest-django) package use custom test database names.\n\nIf you use it and don´t change their default fixtures, just use `MIGRATECI_PYTEST=True`.\n\n\n#### `MIGRATECI_PARALLEL=None`\n\nBefore tests, Django execute all migrations in one database and clone it to be able to run parallel tests.\nUse `MIGRATECI_PARALLEL=\"auto\"` to create one database per process or define the exact number of processes with `MIGRATECI_PARALLEL=4`.\n\nIt supports how Django test and how [pytest-xdist](https://pypi.org/project/pytest-xdist) works.\n\n#### `MIGRATECI_DEPTH=1`\n\nThis is how we decide which migration cache to use.\n\nFirst, it'll try to find a cache with all migration files, but in some cases it's not possible,\nlike when you just pushed a new migration.\n\nFor `MIGRATECI_DEPTH=1`, it'll remove one migration a time for each Django app installed and check if some cached migration exists. It support the most common use case and it's reasonably fast.\n\nBigger values cause a cost operation, it'll remove N migrations a time and check if some cached migration exists. It's a combination of every Django app. E.g. for 10 apps, it'll take at most 10^N checks, with some hashing operations.\n\n### Command line settings\n\nAll below settings can be defined through command line args.\n\n```\nmanage.py migrateci [-h] [-n PARALLEL] [--storage STORAGE_CLASS] [--location LOCATION]\n[--pytest] [--depth DEPTH] [-v {0,1,2,3}]\n\noptions:\n  -h, --help            show this help message and exit\n  -n PARALLEL, --parallel PARALLEL\n  --storage STORAGE_CLASS\n  --location LOCATION\n  --pytest\n  --depth DEPTH\n  --checksum            Prints the current checksum and exits.\n  -v {0,1,2,3}\n```\n\n## Local migration caching\n\nAs a stretch of this package, it's possible to use the same strategy during local\ndevelopment. It'll by default cache files at `~/.migrateci`.\n\n```shell\n./manage.py migrateci --parallel $(nproc)\n./manage.py test --keepdb --parallel $(nproc)\n```\n\n## Why migrations are slow?\n\nDjango migrations are slow because of state recreation for every migration and other internal Django magic.\n\nIn the past, I tried to optimize that on Django core, but learnt it's a [running issue](https://code.djangoproject.com/ticket/29898).\n\n## Supported databases\n\n* mysql\n* postgresql\n* sqlite3\n\nDjango default run sqlite3 tests as in memory database and does not work because\n`migrateci` runs in a different process. Add a test database name to settings,\nlike [sqlite test settings](django_migrations_ci/tests/testapp/settings_sqlite.py).\n\nDjango supports oracle, but the dump function is not implemented here.\n\n## Database names for parallel tests\n\nDjango test framework has a `--parallel N` flag to test with N parallel processes,\nnaming databases from 1 to N.\n\n* On sqlite3, a `db.sqlite3` generate `db_N.sqlite3` files.\n* On other databases, a `db` generate `test_db_N`.\n\nPytest `pytest-django` use `pytest-xdist` for parallel support, naming databases\nfrom 0 to N-1.\n\n* On sqlite3, a `db.sqlite3` generate `db.sqlite3_gwN` files.\n* On other databases, a `db` generate `test_db_gwN`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbusinho%2Fdjango-migrations-ci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbusinho%2Fdjango-migrations-ci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbusinho%2Fdjango-migrations-ci/lists"}