Reputation: 528
We have a continuous integration environment with git for a django application.
Sometimes we need to make modifications to our models and migrate the changes in the db (pre/pro).
In our hook we do:
python manage.py migrate
Which gets the migrations previously created in our local development environment and apply them. But I've notice that sometimes migrate asks for user interaction. I.E.:
makemigrations (local development)
(project-name-develop)lostcitizen@project-name:~/dev/project-name/project-name.git$ ./manage.py makemigrations
Did you rename publication.writer to publication.author (a ForeignKey)? [y/N] y
Migrations for 'publications':
0017_auto_20151117_1050.py:
- Rename field writer on publication to author
migrate (remote)
(project-name-develop)lostcitizen@project-name:~/dev/project-name/project-name.git$ ./manage.py migrate
Skipping creation of NoticeTypes as notification app not found
Operations to perform:
Synchronize unmigrated apps: landing, about, publications, [...]
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying publications.0016_auto_20151116_1650... OK
Applying publications.0017_auto_20151117_1050... OK
The following content types are stale and need to be deleted:
publications | hashtag
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
My question is how to handle this to be "safe" for automated deployment? I can do it manually, but I wanted to abstract this from the rest of the developers workflow.
I think it is not possible to ask for user interaction in a git hook, so I though on using this:
yes | python manage.py migrate
But I don't think it's safe to use it. What do you think?
Regards,
Upvotes: 5
Views: 2431