Add a description field.
[invirt/packages/invirt-database.git] / sipb_xen_database / models.py
index 3f54821..9fbf4dc 100644 (file)
@@ -28,6 +28,7 @@ ctx = SessionContext(create_session)
 machine_table = Table('machines', meta,
        Column('machine_id', Integer, primary_key=True, nullable=False),
        Column('name', String, nullable=False),
+       Column('description', String, nullable=False),
        Column('memory', Integer, nullable=False),
        Column('owner', String, nullable=False),
        Column('contact', String, nullable=False),
@@ -69,7 +70,7 @@ autoinstalls_table = Table('autoinstalls', meta,
 machine_access_table = Table('machine_access', meta,
        Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=False, index=True),
        Column('user', String, nullable=False, index=True),
-       PrimaryKeyConstraint('machine_id', 'user'))
+       PrimaryKeyConstraint('machine_id', 'user', ondelete='CASCADE'))
 
 class Machine(object):
     def __repr__(self):
@@ -100,10 +101,10 @@ class Autoinstall(object):
         return "<Autoinstall %s: %s (%s)>" % (self.autoinstall_id, self.description, self.type.type_id)
 
 assign_mapper(ctx, Machine, machine_table,
-              properties={'nics': relation(NIC, backref="machine"),
-                          'disks': relation(Disk, backref="machine"),
-                          'type': relation(Type),
-                          'acl': relation(MachineAccess, backref="machine")});
+              properties={'nics': relation(NIC, backref="machine", lazy=False),
+                          'disks': relation(Disk, backref="machine", lazy=False),
+                          'type': relation(Type, lazy=False),
+                          'acl': relation(MachineAccess, backref="machine", lazy=False, passive_deletes=True, cascade="all, delete-orphan")});
 assign_mapper(ctx, MachineAccess, machine_access_table)
 assign_mapper(ctx, NIC, nic_table)
 assign_mapper(ctx, Disk, disk_table)