Skip to content

Commit

Permalink
Check for missing migration (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Therrien-Beslogic authored Oct 3, 2024
1 parent 6d87a0a commit be57ef0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
name: canopeum_backend
name: Backend PR validation

on:
push:
branches:
- main
paths:
- "canopeum_backend/**"
- ".github/workflows/canopeum_backend.yml"
- ".github/workflows/canopeum_backend_pr_validation.yml"
pull_request:
branches:
- main
- production
paths:
- "canopeum_backend/**"
- ".github/workflows/canopeum_backend.yml"
- ".github/workflows/canopeum_backend_pr_validation.yml"

env:
# Since the Django mypy extention RUNS the config file, we need a non-empty secret to avoid
# ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
SECRET_KEY_DJANGO_CANOPEUM: mypy-ext

jobs:
django-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: canopeum_backend
steps:
- uses: actions/checkout@v4
- name: Install uv using the standalone installer
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv sync --locked --extra dev
- run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
- name: Run Django Tests
run: python manage.py test
mypy:
runs-on: ubuntu-latest
defaults:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: canopeum_frontend
name: Frontend PR validation

on:
push:
branches:
- main
paths:
- "canopeum_frontend/**"
- ".github/workflows/canopeum_frontend.yml"
- ".github/workflows/canopeum_frontend_pr_validation.yml"
pull_request:
branches:
- main
- production
paths:
- "canopeum_frontend/**"
- ".github/workflows/canopeum_frontend.yml"
- ".github/workflows/canopeum_frontend_pr_validation.yml"

jobs:
Lint:
Expand Down
28 changes: 18 additions & 10 deletions canopeum_backend/canopeum_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
import sys
from datetime import timedelta
from pathlib import Path

Expand Down Expand Up @@ -170,17 +171,24 @@ def get_secret(key: str, default: str):

# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
"default": dj_database_url.parse(
"mysql://canopeum_user:{}@{}:{}/canopeum_db".format(
get_secret("MYSQL_PASSWORD_CANOPEUM", ""),
get_secret("MYSQL_HOST_CANOPEUM", "localhost"),
get_secret("MYSQL_PORT_CANOPEUM", "3308"),
),
conn_max_age=600,
conn_health_checks=True,
)
"default": (
# If running Django tests, use an in-memory database,
# which is faster and requires less setup
# Using conditional instead of TEST dictionary because USER can't be overriden
# https://docs.djangoproject.com/en/5.1/topics/testing/overview/#the-test-database
{"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
if sys.argv[1] == "test"
else dj_database_url.parse(
"mysql://canopeum_user:{}@{}:{}/canopeum_db".format(
get_secret("MYSQL_PASSWORD_CANOPEUM", ""),
get_secret("MYSQL_HOST_CANOPEUM", "localhost"),
get_secret("MYSQL_PORT_CANOPEUM", "3308"),
),
conn_max_age=600,
conn_health_checks=True,
)
),
}

# Password validation
Expand Down
21 changes: 21 additions & 0 deletions canopeum_backend/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This should preferably go in a test folder. But we only have a single test for now
# Tests are auto-discovered as long as they're named test*.py
from io import StringIO

from django.core.management import call_command
from django.test import TestCase as DBTestCase


class PendingMigrationsTests(DBTestCase):
def test_no_pending_migrations(self):
out = StringIO()
try:
# https://docs.djangoproject.com/en/5.1/ref/django-admin/#cmdoption-makemigrations-check
call_command(
"makemigrations",
"--check",
stdout=out,
stderr=StringIO(),
)
except SystemExit:
raise AssertionError("Pending migrations:\n" + out.getvalue()) from None

0 comments on commit be57ef0

Please sign in to comment.