Hi,

I'm using the multi-db branch to do schema-evolution. I'm bringing
this up to see if it is worth pursuing or if there is some better idea
somewhere...

The basic idea is, have a v1 and a v2 database, with the v1 models in
the first and the v2 models in the latter, and create a v1_to_v2
evolution script. This allows for freely tweaking v2 until you are
satisfied with the new design, as you can constantly import the data
from v1 if you keep the v1_to_v2 script up-to-date. Once you're done,
keep that script, set the version to v2 in your settingsfile, and run
with that. A new evolution would be called v3, etc. This way you can
always upgrade old installations from v1 to v3 or v17 even. Downgrade
v2_to_v1 scripts are possible too of course, or copy_v1live_to_v1dev
scripts even (no evolution, but useful nonetheless :-))...

Ok, some (pseudo-)code:

--------------------
settings.py:

OTHER_DATABASES = { 'v1': {...}, 'v2': {...} }
CURRENT_DB_VERSION = 'v1'

DATABASE_ENGINE = \
  OTHER_DATABASES[CURRENT_DB_VERSION]['DATABASE_ENGINE']
DATABASE_NAME = \
  OTHER_DATABASES[CURRENT_DB_VERSION]['DATABASE_NAME']
...

--------------------
app.models.py:

from models_v1 import User, DB_VERSION

--------------------
app.models_v1.py:

from django.db import models
from django.db import connections
DB_VERSION = 'v1'

class User(models.Model):
    name = models.CharField(maxlength=255)

User.objects.db = connections[DB_VERSION]

--------------------
app.models_v2.py:

from django.db import models
from django.db import connections
DB_VERSION = 'v2'

class User(models.Model):
    name = models.CharField(maxlength=255)
    email = models.CharField(maxlength=255)

User.objects.db = connections[DB_VERSION]

--------------------
utils.model_v1_to_v2.py: # run standalone

import sys
import os
sys.path.append('/path/to/my/site')
os.environ['DJANGO_SETTINGS_MODULE'] = 'www.settings'
import www.app.models_v1 as v1
import www.app.models_v2 as v2

def user_v1_to_v2(user1):
   return v2.User(name=user1.name, email=user1.name+'@company.com')

v2.User.objects.all().delete()
for user1 in v1.User.objects.all():
    user2 = user_v1_to_v2(user1)
    user2.save()

--------------------
And that's the basic setup, and it's working for this simple setup,
I'll look into the foreignkeys and many-to-many relationships.

Any thoughts?

Ciao, Marc.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to