How to perform Django migrations during the deployment phase of Google App Engine

I have a Django application running on the Google App Engine. I know how to perform migrations using the cloud proxy or by setting the DATABASES value, but I would like to automate the migration by performing it at the deployment stage. However, there seems to be no way to run a custom script before or after deployment.

The only way I came across is to do this in the entrypoint command, which you can set in app.yaml :

 entrypoint: bash -c 'python3 manage.py migrate --noinput && gunicorn -b :$PORT app.wsgi' 

It is very much like doing it wrong. Many of Google did not give a better answer.

+5
source share
1 answer

Defining the python3 manage.py migrate command in the app.yaml file will make it work every time a new instance spawns and sets to serve traffic. Although technically this may not be a problem (migration will not happen if the database schema has not changed), this is not a good place to declare it.

You want this command to run once each time you click on the new version code. This is ideal for a CI / CD approach. There are several guides to Google Cloud online documentation using Bitbucket piping or Travis CI , but you can use many other CI / CD solutions.

+1
source

Source: https://habr.com/ru/post/1276010/


All Articles