Django migrations checker

A GitHub Action for checking Django migrations


This repository contains a Github Action that checks Django migrations against known issues when running with Postgres in a high-load environment or using rolling deploys. It assumes that migrations are run before new versions of your code starts rolling out.

The current checkers are based on our experience at Oda and looks for paterns we know can be problematic.


NOTE: This is currently unfinished, it will not post any comments yet

NOTE: This should never be used against a production database

The action requires you to install Python 3.9+ and your project’s dependencies. It has no additional requirements beyond the Python standard libary. When the action runs it will apply and check all migrations that are unapplied.

Example workflow

This is an example workflow that checks any migrations that are added in a branch.

name: Linting

# The main value of this check is to post a comment on the pull request, so
# only run on pull requests. You can also run on pushes and output to the
# console, but that is not very visible to developers.
on: [pull_request]

# Limit to one concurrent job and cancel previous runs if a new one is started.
# Because the action posts a comment on the pull request allowing concurrent
# workflows can cause duplicate comments.
  group: check-migrations-${{ github.head_ref }}
  cancel-in-progress: true

    runs-on: ubuntu-latest

        image: postgres:latest
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
          POSTGRES_DB: my_database
          POSTGRES_USER: my_user
          POSTGRES_PASSWORD: my_password

      - uses: actions/[email protected]
          python-version: '3.9'

      # Check out the main branch and apply migrations
      - name: Check out main branch
        uses: actions/[email protected]
          ref: main
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Apply migrations
        run: ./manage.py migrate

      # Check out the current branch and install dependencies
      - name: Check out current branch
        uses: actions/[email protected]
      - name: Install dependencies
        run: pip install -r requirements.txt

      # Check migrations. This will check any unapplied migrations. Because
      # we applied all migrations in the main branch this means that only new
      # migrations in this branch will be checked.
      - name: Check migrations
        uses: kolonialno/[email protected]
          django-settings-module: my_project.settings
          github-token: ${{ secrets.GITHUB_TOKEN }}


Add index

Checks if the migration contains an AddIndex operation and suggests using AddIndexConcurrently instead. This is safer as it doesn’t take a lock on the table for the duration it takes to build the index.


View Github