From beee1f8a3b4f09b158d480054fd528f6bc181d2b Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Wed, 23 Aug 2023 10:36:49 -0400 Subject: [PATCH] Add github workflow for analytics migrations --- .github/workflows/analytics_migrations.yml | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/analytics_migrations.yml diff --git a/.github/workflows/analytics_migrations.yml b/.github/workflows/analytics_migrations.yml new file mode 100644 index 000000000..fbaadec8f --- /dev/null +++ b/.github/workflows/analytics_migrations.yml @@ -0,0 +1,33 @@ +name: Check and Run Analytics Migrations + +on: + pull_request: + paths: + - analytics/analytics + push: + paths: + - analytics/analytics/migrations + branches: + - main + +jobs: + check-and-run-migrations: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + # If models have been changed and thus `makemigrations` must be run, this check fails + # This runs on pull requests and thus blocks until any necessary migrations have been created + - name: Check for Migrations + run: ./analytics/manage.py makemigrations --check --dry-run + + # If changes pushed to analytics/analytics on main, run any necessary migrations + - name: Run Migrations + if: ${{ github.event_name == 'push' }} + run: ./analytics/manage.py migrate + env: + DB_HOST: ${{ secrets.ANALYTICS_DB_HOST }} + DB_NAME: ${{ secrets.ANALYTICS_DB_NAME }} + DB_USER: ${{ secrets.ANALYTICS_DB_USER }} + DB_PASS: ${{ secrets.ANALYTICS_DB_PASS }}