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, + )