Re: [SQLObject] Upgrading Existing Instances to New Derived Classes
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Asterio G. <ni...@ya...> - 2005-08-03 07:06:09
|
... > > What puzzles me about the scenario that you've set > up is that any code > that references MyExistingBaseClass will have to > change to reference > MyNewDerived class, which seems painful. > Let me explain better: - The idea is to be able of upgrading ONLY some instances - Existing external application using (a) tables keep working (adding 'child_name' column in (a) when necessary ) - From new python applications you can use additional properties/codes to preforms avanced features using (b) classes, keeping separately data stored in (a) and (b) tables - You can manage as many (b) different classes as you need derived from a single (a). A Simply ALTER TABLE to add new attributes in (a) doesn't work - External application can insert new (a) instances in DB, so I need to check and fire up a function to detect and upgrade this (a) records to appropriate (b) classes Here is an example class basicWorkUnit (InheritableSQLObject): # This is (a) class """Compatible with existing application""" .... class WorkUnit ( basicWorkUnit ): # This is a (b) class """Additional attribute and functions ...""" .... class Meeting ( basicWorkUnit ): # This is other (b) class """Additional attribute and functions ...""" .... > My solution is this: > > 1) Keep track of what schema version is in use > (somewhere in the database) > 2) Change the existing class to match the new > definition > 3) when the program fires up, make sure that the > database schema is in > sync with the code > 4) Write an upgrade script that performs appropriate > alter tables and > selects if the database schema is an older version > than the code > I agree with you upgrading whole DB schema, but SQLObject can do (4) step directly from my class definition, I prefer keep away errors when maintain two 'sources' and write a check code similar to: for intance in basicWorkUnit.select( some_filters AND child_name <> 'WorkUnit'): upgradeInstance(instance,WorkUnit) for intance in basicWorkUnit.select( some_other_filters AND child_name <> 'Meeting'): upgradeInstance(instance,Meeting) Regards, -- Asterio ______________________________________________ Renovamos el Correo Yahoo! 1GB de capacidad, nuevos servicios y más seguridad http://correo.yahoo.es |