function tweet_feed_update_7109 in Tweet Feed 7
Add a field to hold our tweet id's and remove the meaningless tid.
File
- ./
tweet_feed.install, line 163
Code
function tweet_feed_update_7109() {
$schema = tweet_feed_schema();
if (db_field_exists('tweet_feed', 'tid')) {
db_add_index('tweet_feed', 'tid', array(
'tid',
));
db_drop_primary_key('tweet_feed');
db_drop_field('tweet_feed', 'tid');
}
if (!db_field_exists('tweet_feed', 'tweet_id')) {
$id = 1;
db_add_field('tweet_feed', 'tweet_id', $schema['tweet_feed']['fields']['tweet_id']);
$result = db_query('SELECT created_at, user_id FROM {tweet_feed}');
while ($data = $result
->fetchObject()) {
db_update('tweet_feed')
->fields(array(
'tweet_id' => $id++,
))
->condition('created_at', $data->created_at, '=')
->condition('user_id', $data->user_id, '=')
->execute();
}
db_add_primary_key('tweet_feed', array(
'tweet_id',
));
}
}