Adding a Category Attribute

The installer needs to be run as the Mage_Catalog_Model_Resource_Setup class:

$this->removeAttribute('catalog_category', 'brand');

$this->addAttribute('catalog_category', 'brand', array(
    'group'         => 'General Information',
    'input'         => 'select',
    'type'          => 'int',
    'label'         => 'Brand Link',
    'backend'       => 'eav/entity_attribute_backend_array',
    'source'        => 'rayware/attribute_source_brand',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'used_in_product_listing' => true, // Use this for the attribute to be added to the category flat table!
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,

Note: It would be nice to be able to reindex after adding the category attribute so that it propagates to the catalog_category_flat_store table, however it would appear that just running the catalog_category_flat indexer is not sufficient from the installer. Unless all indexers are run, which could be a really slow process, the attribute does not appear to be added to the flat table.