Created
October 16, 2017 17:27
-
-
Save telenieko/5c202460b431c740213939adbc60fcfd to your computer and use it in GitHub Desktop.
Quick hack to run django manage.py migrate on your production app engine without direct access to database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" do_migrations.py run django manage.py migrate on your production app engine without direct access to database | |
License: This code is release to the Public Domain under "CC0 1.0 Universal" License | |
Author: Marc Fargas <[email protected]> | |
Date: 16th October 2017 | |
This simple wsgi app allows you to call "manage.py migrate" | |
(or any other command if you wish) thus you do not need to | |
setup direct access to the database from your local machine. | |
For setup just place this anywhere, configure the DJANGO_SETTINGS_MODULE | |
variable as desired and then add the handler to app.yaml: | |
handlers: | |
- url: /do_migrations/.* | |
script: do_migrations.app | |
login: admin | |
From now on you just need to open that url (as a project admin) | |
everytime you need migrations to happen. | |
""" | |
import webapp2 | |
import sys | |
import os | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "metanube.settings") | |
class MainPage(webapp2.RequestHandler): | |
def get(self): | |
self.response.headers['Content-Type'] = 'text/plain' | |
self.response.write('Running manage.py migrate command') | |
sys.stdout = self.response.out | |
sys.stderr = self.response.out | |
self.response.out.flush = lambda: '' | |
self.do_migrations() | |
def do_migrations(self): | |
from django.core import management | |
import django | |
django.setup() | |
management.call_command("migrate", noinput=True) | |
app = webapp2.WSGIApplication([ | |
('/do_migrations/', MainPage), | |
], debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment