Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 217

Show
Ignore:
Timestamp:
06/13/06 21:20:26
Author:
fumanchu
Message:

Added schema.assert_version method.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/schemas.py

    r216 r217  
    1616 
    1717class Schema(object): 
     18    """Schema versioning tool for Dejavu Units. 
     19     
     20    Make a subclass of this base class to manage changes to your model layer 
     21    (Units and UnitProperties) as your application grows. Each time you make 
     22    a change to your model, add a new upgrade_to_X method to your subclass, 
     23    and increment the "latest" attribute to match: 
     24     
     25    class MySchema(dejavu.Schema): 
     26         
     27        latest = 1 
     28         
     29        def upgrade_to_1(self): 
     30            # Remove Employee.ZipCode and add .StartDate 
     31            self.arena.drop_property(Employee, "ZipCode") 
     32            self.arena.add_property(Employee, "StartDate") 
     33     
     34    Then, in your deployment scripts, you can choose how much you want to 
     35    automate control of the schema. 
     36     
     37        schema = MySchema(myarena) 
     38         
     39        if cmd == 'upgrade': 
     40            schema.upgrade() 
     41        elif cmd == 'install': 
     42            schema.assert_storage() 
     43        else: 
     44            schema.assert_version() 
     45    """ 
    1846     
    1947    guid = "" 
     
    114142            if not self.arena.has_storage(cls): 
    115143                self.arena.create_storage(cls) 
     144     
     145    def assert_version(self): 
     146        """Die if schema version is missing or out of sync.""" 
     147        msg = None 
     148        if not self.versioned: 
     149            msg = ("This application now uses a versioned schema, but the " 
     150                   "installed version could not be determined. You must " 
     151                   "either install the application or manually set the " 
     152                   "version number.") 
     153        if self.deployed > self.latest: 
     154            msg = "Deployed version is greater than the latest version!?!" 
     155        if self.deployed < self.latest: 
     156            msg = ("Deployed version is less than the latest version. " 
     157                   "You must upgrade before proceeding.") 
     158        if msg: 
     159            raise errors.DejavuError(msg) 
     160