Schema Evolution / Migrations

2 views
Skip to first unread message

Trey Piepmeier

unread,
Jan 7, 2009, 5:12:40 PM1/7/09
to Django Nashville
What are people using these days for schema evolution / migration? I'm
actually working on a project with someone else now, and it would make
things a lot easier to be able to update databases more reliably.

-Trey

Neil Mock

unread,
Jan 7, 2009, 5:15:45 PM1/7/09
to django-n...@googlegroups.com
StudioNow has a hand-rolled update script for executing SQL
migrations. It's good but not very standard and probably wouldn't do
you much good.

If you aren't afraid of a little Ruby and like the syntax of Rails
migrations, check out:

http://github.com/thuss/standalone-migrations/tree/master

Trey Piepmeier

unread,
Jan 7, 2009, 5:19:52 PM1/7/09
to django-n...@googlegroups.com
I've seen that standalone migrations, and it looks pretty cool. I
think I'd be more likely to use it on something that was already more
freeform like a PHP application. I'd hate to have to switch back and
forth from Python to Ruby when things are defined so nicely in the
Python models file. Plus it would be something else for everyone else
who's working on the project to have to install -- whereas with
something like django_evolution, you could just include it in the
project along with the other apps.

Josh

unread,
Jan 7, 2009, 5:36:44 PM1/7/09
to Django Nashville
I am a fan of Django Evolution (http://code.google.com/p/django-
evolution/). It make is very easy to do simple modifications to your
models. For example adding a new column is a piece of cake.

However, there are many limitations when you start doing more complex
modifications. For example ForeignKey fields "will be added, but the
foreignkey constraints are not correctly constructed." (http://django-
evolution.googlecode.com/svn-history/r143/trunk/docs/faq.txt).

For me it a tool worth using.

Joshua Gourneau

On Jan 7, 4:19 pm, "Trey Piepmeier" <tpiepme...@gmail.com> wrote:
> I've seen that standalone migrations, and it looks pretty cool.  I
> think I'd be more likely to use it on something that was already more
> freeform like a PHP application.  I'd hate to have to switch back and
> forth from Python to Ruby when things are defined so nicely in the
> Python models file.  Plus it would be something else for everyone else
> who's working on the project to have to install -- whereas with
> something like django_evolution, you could just include it in the
> project along with the other apps.
>

Trey Piepmeier

unread,
Jan 7, 2009, 5:43:51 PM1/7/09
to Django Nashville
Evolution looks really nice. I'm playing with it right now, and it is
really simple to add a new field.

How do you rename a field, though? The "hinted" evolution won't work,
and I'm not sure how to pass the proper "RenameField" to the evolve
command.

Patrick Altman

unread,
Jan 7, 2009, 5:46:14 PM1/7/09
to django-n...@googlegroups.com
Neil --

I actually think my hand rolled tool rocks the party.

K. Thx. Bye.

---
Patrick Altman
(615) 300-2930

[Sent from my iPhone]

Neil Mock

unread,
Jan 7, 2009, 5:57:45 PM1/7/09
to django-n...@googlegroups.com
Hey, I dig the tool! It does some cool things that I haven't seen
before, like tracking SVN/Git commits across schema evolutions, etc.
I just wouldn't know where to start in terms of getting people up and
running on it.

One area I would like to see Django improve is the testing world. I
feel like there is potential there but I haven't been able to come
across a project like Shoulda (for Rails, http://github.com/thoughtbot/shoulda/tree/master)
. I would love to see some testing macros like that for Django Models
and Views.

Also, something else I've looked into is using Cucumber (http://wiki.github.com/aslakhellesoy/cucumber
) for high-level acceptance testing of Django apps. Just some food
for thought, we could talk about it at the next meetup, which is
scheduled for....

we'll have to nail down the time today or tomorrow hopefully.

Trey Piepmeier

unread,
Jan 7, 2009, 6:25:17 PM1/7/09
to Django Nashville
Now I see how things work with Evolution past the very basic '--hint'
functionality.

You put each evolution/migration file in an evolution/ directory in
your application. Then you tell it what order to do the evolutions by
listing them out in the __init__.py that's inside of the evolution/
directory. I like it.

I still like Rails migrations better (maybe), but this will definitely
do.

On Jan 7, 4:57 pm, Neil Mock <neilm...@gmail.com> wrote:
> Hey, I dig the tool!  It does some cool things that I haven't seen  
> before, like tracking SVN/Git commits across schema evolutions, etc.  
> I just wouldn't know where to start in terms of getting people up and  
> running on it.
>
> One area I would like to see Django improve is the testing world.  I  
> feel like there is potential there but I haven't been able to come  
> across a project like Shoulda (for Rails,http://github.com/thoughtbot/shoulda/tree/master)
> .  I would love to see some testing macros like that for Django Models  
> and Views.
>
> Also, something else I've looked into is using Cucumber (http://wiki.github.com/aslakhellesoy/cucumber
> ) for high-level acceptance testing of Django apps.  Just some food  
> for thought, we could talk about it at the next meetup, which is  
> scheduled for....
>
> we'll have to nail down the time today or tomorrow hopefully.
>
> On Jan 7, 2009, at 4:46 PM, Patrick Altman wrote:
>
>
>
> > Neil --
>
> > I actually think my hand rolled tool rocks the party.
>
> > K. Thx. Bye.
>
> > ---
> > Patrick Altman
> > (615) 300-2930
>
> > [Sent from my iPhone]
>
> > On Jan 7, 2009, at 4:43 PM, Trey Piepmeier <tpiepme...@gmail.com>  

Alex Ezell

unread,
Jan 7, 2009, 11:14:38 PM1/7/09
to django-n...@googlegroups.com
This is maybe a moronic question. However, what's the benefit of
migrations vs. just changing the models and schema manually? Is it the
versioning of those migrations that it gives you? Like, with a
migrations file, there's some record in the repo of what was done and
when?

There's clearly a major piece of this conceptual puzzle that I've just
never understood, even back when I was trying to learn Rails.

/alex

Patrick Altman

unread,
Jan 7, 2009, 11:25:23 PM1/7/09
to django-n...@googlegroups.com
That's the conclusion I came to when throwing together the simple
upgrade.py script we use. It's simply a table in the database that
tracks what sql scripts have been executed and a directory of sql
scripts stored in revision control named YYYYMMDD-##.sql for easy
sorting. The python script simply manages applying in sql scripts
that are not in the database you are upgrading. We just make a habit
to when we make model changes we add a corresponding .sql file with
the commit.

No migrations infrastructure to learn or work around, just type sql
statements. I do carry an interest in the various migration
solutions, but at this point it would take a lot to move us from
something that just works to something else.

Patrick

Trey Piepmeier

unread,
Jan 8, 2009, 12:43:55 AM1/8/09
to django-n...@googlegroups.com
The immediate benefit to me is not having to manually update the
database to update a table that already exists.

Another nice benefit is having an easy to use command to tell my
designer friend to use to update her database.

Patrick Altman

unread,
Jan 8, 2009, 2:16:52 AM1/8/09
to django-n...@googlegroups.com, django-n...@googlegroups.com
Like python upgrade.py --execute? :)

---
Patrick Altman
(615) 300-2930

[Sent from my iPhone]


On Jan 7, 2009, at 11:43 PM, "Trey Piepmeier" <tpiep...@gmail.com>

Trey Piepmeier

unread,
Jan 8, 2009, 9:00:55 AM1/8/09
to django-n...@googlegroups.com
Exactly. Except Evolution is open source! :)

Patrick Altman

unread,
Jan 8, 2009, 9:33:02 AM1/8/09
to django-n...@googlegroups.com
I'll be happy to share. I think I already did somewhere.

---
Patrick Altman
(615) 300-2930

[Sent from my iPhone]


On Jan 8, 2009, at 8:00 AM, "Trey Piepmeier" <tpiep...@gmail.com>
wrote:

Matt

unread,
Jan 8, 2009, 11:25:38 AM1/8/09
to Django Nashville
I thought I would throw this into the fray, a newcomer to the django
migration systems is this project:
http://www.bitbucket.org/DeadWisdom/migratory/wiki/Home

It's been getting some attention on the django-dev, in this thread:
http://groups.google.com/group/django-developers/browse_thread/thread/a4f1040210d5887f/18d949dc6987ed3a?lnk=gst&q=migrations#18d949dc6987ed3a

Also, I am with Alex in not really understanding a lot of the
"benefits" of migrations. I understand that they give you a way to
programatically update the db structure, which can correspond to code
changes. However, in most of the environments that I have worked in,
there has been one or two people who are the gatekeepers for the
database and a pretty static db structure. Does the real advantage
come when you are in an environment when the person wearing the
developer hat is also wearing the db admin hat? I could see if that
was the case, that programatic/version controlled migrations could be
very helpful.

Matt

On Jan 8, 8:33 am, Patrick Altman <palt...@gmail.com> wrote:
> I'll be happy to share. I think I already did somewhere.
>
> ---
> Patrick Altman
> (615) 300-2930
>
> [Sent from my iPhone]
>
> On Jan 8, 2009, at 8:00 AM, "Trey Piepmeier" <tpiepme...@gmail.com>  
> wrote:
>
>
>
> > Exactly.  Except Evolution is open source! :)
>
> > On Thu, Jan 8, 2009 at 1:16 AM, Patrick Altman <palt...@gmail.com>  
> > wrote:
>
> >> Like python upgrade.py --execute?  :)
>
> >> ---
> >> Patrick Altman
> >> (615) 300-2930
>
> >> [Sent from my iPhone]
>
> >> On Jan 7, 2009, at 11:43 PM, "Trey Piepmeier" <tpiepme...@gmail.com>
> >> wrote:
>
> >>> The immediate benefit to me is not having to manually update the
> >>> database to update a table that already exists.
>
> >>> Another nice benefit is having an easy to use command to tell my
> >>> designer friend to use to update her database.
>
> >>> On Wed, Jan 7, 2009 at 10:25 PM, Patrick Altman <palt...@gmail.com>
Reply all
Reply to author
Forward
0 new messages