public function up() { $conn = Doctrine_Manager::connection(); $export = $conn->export; $export->alterTable('community_topic_comment', array('remove' => array('updated_at' => array()))); $export->alterTable('community_topic', array('add' => array('topic_updated_at' => array('type' => 'timestamp', 'notnull' => false)))); $export->alterTable('community_topic_comment', array('change' => array('member_id' => array('definition' => array('type' => 'integer', 'notnull' => false))))); $export->alterTable('community_topic', array('change' => array('member_id' => array('definition' => array('type' => 'integer', 'notnull' => false))))); $export->dropForeignKey('community_topic_comment', 'community_topic_comment_FK_2'); $export->dropForeignKey('community_topic', 'community_topic_FK_2'); $export->createForeignKey('community_topic_comment', array('name' => 'community_topic_comment_FK_2', 'local' => 'member_id', 'foreign' => 'id', 'foreignTable' => 'member', 'onDelete' => 'SET NULL')); $export->createForeignKey('community_topic', array('name' => 'community_topic_FK_2', 'local' => 'member_id', 'foreign' => 'id', 'foreignTable' => 'member', 'onDelete' => 'SET NULL')); $communityTopics = CommunityTopicPeer::doSelect(new Criteria()); foreach ($communityTopics as $communityTopic) { $communityTopic->setTopicUpdatedAt($communityTopic->getUpdatedAt()); $communityTopic->save(); } }
public function up() { $conn = Doctrine_Manager::connection(); $export = $conn->export; $export->alterTable('community_topic_comment', array('add' => array('number' => array('type' => 'integer', 'default' => 0, 'notnull' => true)))); $communityTopics = CommunityTopicPeer::doSelect(new Criteria()); foreach ($communityTopics as $communityTopic) { $criteria = new Criteria(); $criteria->add(CommunityTopicCommentPeer::COMMUNITY_TOPIC_ID, $communityTopic->getId()); $criteria->addAscendingOrderByColumn(CommunityTopicCommentPeer::CREATED_AT); $communityTopicComments = CommunityTopicCommentPeer::doSelect($criteria); $i = 0; foreach ($communityTopicComments as $communityTopicComment) { $i++; $communityTopicComment->setNumber($i); $communityTopicComment->save(); } } $export->alterTable('community_topic_comment', array('change' => array('number' => array('definition' => array('type' => 'integer', 'notnull' => true))))); }