Skip to content

Commit

Permalink
Added migrations check to pre-commit config.
Browse files Browse the repository at this point in the history
Added `make dbrun` to run postgres container
Generated missing migrations and ran `make db-setup` to prove migrations still run on a fresh database.
  • Loading branch information
Del Hyman-Jones committed Aug 30, 2024
1 parent a75f6cb commit 6048b77
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ repos:
- id: no-commit-to-branch
args: [--branch=master]
- id: trailing-whitespace

- repo: local
hooks:
- id: check-migrations
name: Check for missing migrations
entry: bash -c "poetry run python manage.py makemigrations --check --dry-run"
language: system
types: [python]
always_run: true
pass_filenames: false
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ deps:
poetry env use 3.9
poetry install

# Clears out all of the tables in the database
.PHONY: db-clean
db-clean:
psql -U postgres -d postgres -c "DROP SCHEMA IF EXISTS public CASCADE;"
psql -U postgres -d postgres -c "CREATE SCHEMA public;"

# The following command ensures that the migrations are run in the correct order.
# It seems that even Django 4.2 ignored dependency ordering specified in the migration
# files which causes errors to occur and the database tables are not created properly.
.PHONY: db-setup
db-setup: db-clean
# Run the following to clean out the database and run the migrations from scratch to
# prove that they run properly.
.PHONY: migrate
migrate:
poetry run django-admin migrate
poetry run ./manage.py showmigrations --plan


.PHONY: db-setup
db-setup: db-clean migrate


.PHONY: dbrun
dbrun:
docker compose up


.PHONY: tests
tests: deps
poetry run tox $(pytest_args)
Expand Down
52 changes: 52 additions & 0 deletions drf_integrations/migrations/0008_auto_20240830_0902.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 3.2.19 on 2024-08-30 09:02

import oauth2_provider.generators
import oauth2_provider.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('drf_integrations', '0007_oauth_provider_150_upgrade'),
]

operations = [
migrations.AddField(
model_name='application',
name='allowed_origins',
field=models.TextField(
blank=True,
default='',
help_text='Allowed origins list to enable CORS, space separated',
),
),
migrations.AddField(
model_name='application',
name='hash_client_secret',
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name='application',
name='post_logout_redirect_uris',
field=models.TextField(
blank=True, default='', help_text='Allowed Post Logout URIs list, space separated'
),
),
migrations.AlterField(
model_name='accesstoken',
name='token',
field=models.CharField(db_index=True, max_length=255, unique=True),
),
migrations.AlterField(
model_name='application',
name='client_secret',
field=oauth2_provider.models.ClientSecretField(
blank=True,
db_index=True,
default=oauth2_provider.generators.generate_client_secret,
help_text='Hashed on Save. Copy it now if this is a new secret.',
max_length=255,
),
),
]
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Django's command-line utility for administrative tasks."""
import os
import sys
Expand Down

0 comments on commit 6048b77

Please sign in to comment.