From 6048b77bcd262e315745d174492ccade24a6e69b Mon Sep 17 00:00:00 2001 From: Del Hyman-Jones Date: Fri, 30 Aug 2024 10:10:11 +0100 Subject: [PATCH] Added migrations check to pre-commit config. Added `make dbrun` to run postgres container Generated missing migrations and ran `make db-setup` to prove migrations still run on a fresh database. --- .pre-commit-config.yaml | 10 ++++ Makefile | 20 +++++-- .../migrations/0008_auto_20240830_0902.py | 52 +++++++++++++++++++ manage.py | 2 +- 4 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 drf_integrations/migrations/0008_auto_20240830_0902.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c539d8f..b9fa322 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/Makefile b/Makefile index 38a54d9..bdb7238 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/drf_integrations/migrations/0008_auto_20240830_0902.py b/drf_integrations/migrations/0008_auto_20240830_0902.py new file mode 100644 index 0000000..62524ef --- /dev/null +++ b/drf_integrations/migrations/0008_auto_20240830_0902.py @@ -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, + ), + ), + ] diff --git a/manage.py b/manage.py index 2b02446..099c65b 100755 --- a/manage.py +++ b/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """Django's command-line utility for administrative tasks.""" import os import sys