How to ship migrations in a Django reusable app? - django

I can create migrations for my reusable application from a minimal test project, but that would install the migrations in -
/usr/local/lib/python3.5/dist-packages/django_app-0.1-py3.5.egg/django_app/migrations/0001_initial.py
I wanna ship the migrations with the reusable app, Do I just copy the file or is there any other method?

A couple of options:
1) Add the test project to your reusable app's repo for the purposes of creating migrations and perhaps as a usage example, as django-allauth does.
2) Keep your test project as a separate repo, and symlink the reusable app repo into the test project's directory as a dependency. Create migrations using the test project and the migration files will be created in your reusable app's repo directory, ready to be committed.
Keen to hear what other people are doing!

Related

Handle Production Migrations and Development Migrations in Django

While developing a Django project, all your migrations are stored within each app folder, however, in production I don't want those migrations, I want to keep a Production database, and a Development database:
How do I handle Django migrations in a Production and Development environment?
I'm asking this question because it's been really hard to update my deployed project with new additions in the development one, my ideal scenario would be to keep each set of migrations in a folder outside my source code, just like the databases.
The best idea is to keep production and development migrations the same and while developing you clean migrations before pushing the code and you should push migrations into your Version Control System too.
In development, you might end up deleting a table and re-creating it so make sure you don't push the un-intended migrations. The thing is you should treat migrations as code, not an automated script. I have done a lot of mistakes in the past, so, I came to the conclusion of including migrations in code. and that's effective and gives more control.
Moreover you might have to do data migrations in production, how will you do if you wont push the code?

Struggling with git submodule and django

I have a django project A which contains an app App1. I also have a django project B in which I'd like to have the same App1. Then, when I edit App1 in my project A, I'd like to update App1 and be able to pull changes in project B.
A and B are under separate git repository.
What should be my workflow?
Should I create a submodule and a new git repo for the App1 I want to duplicate? I read a lot about people struggling with submodules and tricking git...
I don't want to break anything...
Cheers
Okay, my question was pretty stupid. I created a separate git repo for App1. I create a new directory on my computer where I copy/paste my App1 then sync it to git. Then, for each of my django project, I created git submodule and here it is!

Best way to (git) clone app into Django project directory

I want to clone (via GIT) an external app into my project directory. Unfortunately there is one folder on top of the project that makes Django not see the cloned folder as an app.
For example see allauth. After cloning the app itself is in allauth/allauth resp. from the project view my_project/allauth/allauth. If just adding allauth to INSTALLED_APPS, the app is not found by the server. I also tried adding allauth.allauth, which also doesn't work.
What is the recommended way to clone an external app into a Django project folder (and manage it as submodule for example)?
you can clone it into a vendor/ directory and then symlink it's app folder into your project, but I'd recommend against that.
A better way would be to use a virtual environment, and install the application as an editable package.
$ pip install -e git+https://github.com.au/person/project#v0.1.1#egg=project
This will clone the repo into the src/ folder in your virualenv and set up the paths correctly such that it can be loaded normally with django.

Same Django project different GIT repositories

Which is the best way to have two different repositories on the same Django project?
I started developing a project months ago and I have the whole folder in the repository. I want to reuse some apps in the project and I would like to create a different repository for them since they will be spin-offs project. But I want to keep it updated.
Which is the best workflow, methodology, etc... to achieve this? Or is it a bad approuch?
Thanks!
Xavi
You can wrap each app as a python package, which has its own GIT repo. And save all your packages in some private (or public?) python packages repository (like Gemfury).
Then, in your projects, just use the app as you install django itself.. pip install myapp
This way the apps a reusable and decoupled from any project.
(This works very well for myself.. perhaps there is a better way)
You can use submodule,
$git submodule add git://github.com/yourusername/project2.git project2
$cat .gitmodules
.gitmodules output:
[submodule "project2"]
path = project2
url = git://github.com/yourusername/project2.git
If you want to Clone some git project like submodule,
git clone git://github.com/yourusername/project2.git
cd project2
git submodule init

Django Deployment Advice

I have a multi-step deployment system setup, where I develop locally, have a staging app with a copy of the production db, and then the production app. I use SVN for version control.
When deploying my production app I have been just moving the urls.py and settings.py files up a directory, deleting my django app directory with rm -rf command and then doing an svn export from the repository which creates a new django app directory with my updated code. I then move my urls.py and settings.py files back into place and everything works great.
My new problem is that I am now storing user uploads in a folder inside of my django app, so I can't just remove the whole app dir anymore or I would loose all of my users files.
What do you think my best approach is now? Would svn export --force work, since it should just be overwriting all of my changed files? Should I take an entirely new approach? I am open to advice?
You may want to watch this presentation by Jacob. It can help you improve your deployment process.
I use Bitbucket as my repo and I can simply perform push on my Dev box and run pull/update on Stage/Prod box. Actually I don't run them manually, I use fabric to do them for me :).
Your could use rsync or something similar to backup your uploaded files and use this backup when you deploy your project.
For deployment you could try to use buildout:
http://www.buildout.org/
http://pypi.python.org/pypi/djangorecipe
http://jacobian.org/writing/django-apps-with-buildout/
For other deployment methods see this question:
Django deployment tools
You can move your files to S3 servers (http://aws.amazon.com/s3/), so you will not ever have to care about moving them with your project.