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 <noreply@anthropic.com>
This commit is contained in:
parent
394f9bdfe4
commit
2c8d80e4a1
@ -59,4 +59,8 @@ urlpatterns = [
|
|||||||
# === TEMPORARY: Import production data from browser ===
|
# === TEMPORARY: Import production data from browser ===
|
||||||
# Visit /import-data/ once to populate the database. Remove after use.
|
# Visit /import-data/ once to populate the database. Remove after use.
|
||||||
path('import-data/', views.import_data, name='import_data'),
|
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'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -2116,3 +2116,39 @@ def import_data(request):
|
|||||||
'</body></html>',
|
'</body></html>',
|
||||||
status=500,
|
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', '<br>')
|
||||||
|
return HttpResponse(
|
||||||
|
'<html><body style="font-family: monospace; padding: 20px;">'
|
||||||
|
'<h2>Migrations Complete!</h2>'
|
||||||
|
'<div>' + lines + '</div>'
|
||||||
|
'<br><br>'
|
||||||
|
'<a href="/">Go to Dashboard</a> | '
|
||||||
|
'<a href="/payroll/">Go to Payroll Dashboard</a>'
|
||||||
|
'</body></html>'
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return HttpResponse(
|
||||||
|
'<html><body style="font-family: monospace; padding: 20px; color: red;">'
|
||||||
|
'<h2>Migration Error</h2>'
|
||||||
|
'<pre>' + str(e) + '</pre>'
|
||||||
|
'</body></html>',
|
||||||
|
status=500,
|
||||||
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user