def genericset_added(genericset, event):
    """A new GenericSet was added. Create the setobject type for it.
    """
 
    plan_identifier = genericset.plan_identifier
    table_identifier = genericset.table_identifier
    
    # update the genericset index
    catalog = getUtility(ICatalog)
    catalog.updateIndex(catalog['plan_identifier'])
    
    if not table_exists(table_identifier): 
        # Create SA table type
        table_type = Table(
            table_identifier,
            metadata,
            Column(genericset.table_key_field, String(10), primary_key=True, autoincrement=False),
            mysql_engine='InnoDB'
        )    
    
        # Register table type
        setobject_table_registry.register_type(genericset.klass,
                                               table_identifier,
                                               table_type)
        
        # Even if the user gives a specialized class and module we create a 
        # generic klass first, because the specialized class definition will not exist until the
        # user defines it in the source code and restarts the server.
        setobject_type = create_basemodel_type(genericset.klass, table_identifier)
        
        # DDL
        table_type.create()
def register_remaining_tables(registered):
    res = select_tables()
    for rec in res:
        table_identifier = str(rec.table)
        class_name = str(rec.klass)
        if not class_name in registered:
            # There's no sa table type for this table yet. Create one and map to a generic ModelBase.
            registered.append(table_identifier)
            # Create SA table type
            table_type = Table(table_identifier, metadata, autoload=True)
            # Register table type
            setobject_table_registry.register_type(class_name, table_identifier, table_type)
            # Create a new setobject orm type
            setobject_type = create_basemodel_type(class_name, table_identifier, do_mapping=False)
    res.close()