From 2c8d80e4a17c88eab16fad526f89b4080a52532b Mon Sep 17 00:00:00 2001 From: Konrad du Plessis Date: Tue, 24 Mar 2026 21:19:55 +0200 Subject: [PATCH] Add /run-migrate/ endpoint for browser-based migration Flatlogic's "Pull Latest" doesn't always run migrations automatically. This endpoint lets you visit /run-migrate/ to apply pending migrations to the production MySQL database from the browser. Co-Authored-By: Claude Opus 4.6 --- core/urls.py | 4 ++++ core/views.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/core/urls.py b/core/urls.py index 15c413b..658d909 100644 --- a/core/urls.py +++ b/core/urls.py @@ -59,4 +59,8 @@ urlpatterns = [ # === TEMPORARY: Import production data from browser === # Visit /import-data/ once to populate the database. Remove after use. path('import-data/', views.import_data, name='import_data'), + + # === TEMPORARY: Run migrations from browser === + # Visit /run-migrate/ to apply pending database migrations on production. + path('run-migrate/', views.run_migrate, name='run_migrate'), ] diff --git a/core/views.py b/core/views.py index 1a584dc..60fa514 100644 --- a/core/views.py +++ b/core/views.py @@ -2116,3 +2116,39 @@ def import_data(request): '', status=500, ) + + +# ============================================================================= +# === RUN MIGRATIONS === +# Runs pending database migrations from the browser. Useful when Flatlogic's +# "Pull Latest" doesn't automatically run migrations after a code update. +# Visit /run-migrate/ to apply any pending migrations to the production DB. +# ============================================================================= + +def run_migrate(request): + """Runs Django migrate from the browser to apply pending migrations.""" + from django.core.management import call_command + from io import StringIO + + output = StringIO() + try: + call_command('migrate', stdout=output) + result = output.getvalue() + lines = result.replace('\n', '
') + return HttpResponse( + '' + '

Migrations Complete!

' + '
' + lines + '
' + '

' + 'Go to Dashboard | ' + 'Go to Payroll Dashboard' + '' + ) + except Exception as e: + return HttpResponse( + '' + '

Migration Error

' + '
' + str(e) + '
' + '', + status=500, + )