djaodjin / djaodjin-saas

Django application for software-as-service and subscription businesses
Other
564 stars 124 forks source link

Added migrations #108

Closed ourcach closed 8 years ago

ourcach commented 8 years ago

Because the project requires django 1.7, we can use migrations to create the database, instead of the syncdb command. This will facilitate the upgrade if there are schema changes in the future and current users can fake the initial migration.

smirolo commented 8 years ago

Hi @ourcach! My personal take is that migrations introduce more problems that they are trying to solve, especially when you are trying to deploy updates to production.

None-the-less, there is enough value to do things like every other Django 1.7+ project. I will merge this pull request. If you could only update the setup.py such that the migrations module gets installed as part of running

$ python setup.py install

Thank you.

ourcach commented 8 years ago

Hi @smirolo, nice to hear from you.

The migrations module was added to django core in django 1.7

I installed the package in a clean django (tested in django 1.7 and 1.10) installation with migrations and everything ran smoothly:

$ ./manage.py migrate Operations to perform: Apply all migrations: admin, contenttypes, saas, auth, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying saas.0001_initial... OK Applying sessions.0001_initial... OK

smirolo commented 8 years ago

commit ec95295 is what I had in mind. Here the test commands to make sure installation is done correctly:

$ virtualenv-2.7 ~/build/djaodjin-saas
$ source ~/build/djaodjin-saas/bin/activate
$ mkdir -p ~/build/djaodjin-saas/reps
$ cd ~/build/djaodjin-saas/reps
$ git clone git@github.com:djaodjin/djaodjin-saas.git
$ cd djaodjin-saas
$ pip install -r testsite/requirements.txt
$ python setup.py install
$ rm -rf saas
$ make initdb
$ python manage.py runserver
$ curl http://localhost:8020/
200 OK

The problem with migrations the way they are currently implemented in Django is that it seems now impossible to customized the type of the extra fields through saas.settings.EXTRA_FIELD to django.contrib.postgres.fields.jsonb.JSONField for example, or had you taken the extra definitions out of the 0001_initial.py manually for that specific reason?

I am really interested to learn how to customize fields and get migrations working. Thank you.