Hi!

On Mon, Apr 26, 2010 at 09:13:01PM +0300, Imri Goldberg wrote:
> I am considering switching to your way of doing schema changes.
> I would very much appreciate more information regarding the process you use
> to do these things.
> 
> For instance, given that I have a working MyThing class, to which I'd like
> to add a field my_field - would you write the upgrade script first, and then
> copy the field definitions to the MyThing class? Would you do it the other
> way around?
> Once both are updated, do you have a special order of doing things when
> moving it to production?

   I use SQLObject in commercial programs that my company sells to
customers. So I have to distribute new class descriptions; so new tables
and columns are added to the code before upgrade scripts.
   Also I write upgrade scripts in such a way they can be run safely many
times. When I announce new build in the internal mailing list and at the
corporation's wiki I notify support department there is a new upgrade
script. I don't expect support persons remember what upgrade scripts had
been run for a particular customer; so when installing a new version a
support person can run all upgrade scripts in order.
   Because of this an upgrade script always looks into the real database to
see if it needs to do its job. For a new tables it's quite simple:

    from Database.Requests import RequestIDs

    if not RequestIDs.tableExists():
        RequestIDs.createTable()

   I.e., the script imports the class declaration from the Database modules,
tests if the table exists and creates the table.

   For a new column it's a bit harder - I have to investigate the DB
deeper. Sometimes I simply create a second class declaration and connect it
to the same table:

    class OldRequestIDs(Base):
        class sqlmeta:
            table = 'request_i_ds' # connect the table to the real table
        status = StringCol(length=255, default=None)
    OldRequestIDs.sqlmeta.delColumn("status", changeSchema=True)

   Sometimes I draw the table declaration from the DB:

    class Plate(SQLObject):
        class sqlmeta:
            fromDatabase = True
    if 'idPl' not in Plate.sqlmeta.columns:
        Plate.sqlmeta.addColumn(IntCol("IDpl", default=None, dbName="id_pl"),
            changeSchema=True)

    (Wow, three different ways of naming 'id_pl' column, damn!)

Oleg.
-- 
     Oleg Broytman            http://phd.pp.ru/            p...@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to