Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django on GAE - How to automatically 'migrate' on deploy?

Django v1.11

Postgresql v9.6

Currently, I use 2 Google CloudSQL databases, one for development and one for production. Whenever I make changes to my models, I run python manage.py migrate to update the tables in the development database. This migration does not affect the production database, however.

Now, whenever I git push changes to my Django project, TravisCI automatically runs tests and deploys the code to Google App Engine. Currently, it runs on GAE flexible environment (so I can use Python 3.5)

What I want to have is for Travis or GAE to automatically run python manage.py migrate on the production database before runserver. However, I can't figure out how to run custom commands during a deploy.

I've tried looking around GAE and Travis documentation and adding scripts to .travis.yml and app.yaml, but to no avail.

As of now, anytime there is a model change, I have to migrate the production database locally in a very hacky way. Ideally, GAE will migrate at the beginning of every deploy.

like image 220
Boberoni Avatar asked Mar 14 '18 00:03

Boberoni


People also ask

What is the difference between Makemigrations and migrate in Django?

migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.

What is manage PY migrate in Django?

migrate executes those SQL commands in the database file. So after executing migrate all the tables of your installed apps are created in your database file.


1 Answers

Not sure if you have seen this:

Travis CI Script Deployment

A reference from a similar issue:

How can I run a script as part of a Travis CI build?

Also, consider a database migration tool embedded with your source code, Postgresql is supported (something similar to FlywayDB migration ):

Yoyo database migrations¶

like image 162
TechFree Avatar answered Sep 18 '22 17:09

TechFree