--- facebook_status-DRUPAL-6--3/facebook_status.install 2011-02-06 23:52:54.000000000 +0000 +++ facebook_status/facebook_status.install 2011-02-07 10:59:00.000000000 +0000 @@ -32,7 +32,7 @@ function facebook_status_schema() { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, - 'description' => 'The ID of the entity that received the status message..', + 'description' => 'The ID of the entity that received the status message.', ), 'type' => array( 'type' => 'varchar', @@ -61,6 +61,16 @@ function facebook_status_schema() { ), 'primary key' => array('sid'), ); + $contexts = _facebook_status_create_contexts_schema(); + $schema['facebook_status_contexts'] = $contexts['facebook_status_contexts']; + return $schema; +} + +/** + * Helper to create the contexts table in different situations. + */ +function _facebook_status_contexts_schema() { + $schema = array(); $schema['facebook_status_contexts'] = array( 'description' => 'Stores stream context configurations.', 'fields' => array( @@ -108,7 +118,7 @@ function facebook_status_install() { /** * Implementation of hook_update_N(). - * + */ function facebook_status_update_6300() { //Remove old variables. variable_del('facebook_status_default_text'); @@ -127,15 +137,31 @@ function facebook_status_update_6300() { variable_del('facebook_status_size'); variable_del('facebook_status_type'); - //@todo: Update DB schema. - //Rename uid to recipient - //Add sender, fill with recipient - //Add type, fill with 'user' - //Rename status_time to created - //Rename status to message - //Replace indices - //Add new {facebook_status_contexts} table - + // Drop current indexes. + db_drop_index($ret, 'facebook_status', 'uid'); + db_drop_index($ret, 'facebook_status', 'pid'); + db_drop_index($ret, 'facebook_status', 'status_time'); + + // Rename fields and add 'type'. + db_change_field($ret, 'facebook_status', 'uid', 'recipient', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'The ID of the entity that received the status message.')); + db_change_field($ret, 'facebook_status', 'pid', 'sender', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'The User ID of the user who created the status message.')); + db_change_field($ret, 'facebook_status', 'status_time', 'created', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'The time the status message was saved.')); + db_change_field($ret, 'facebook_status', 'status', 'message', array('type' => 'text', 'not null' => TRUE, 'description' => 'The status message.')); + db_add_field($ret, 'facebook_status', 'type', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The stream context type.')); + + // Add indexes again. + db_add_index($ret, 'facebook_status', 'recipient', array('recipient')); + db_add_index($ret, 'facebook_status', 'sender', array('sender')); + db_add_index($ret, 'facebook_status', 'created', array('created')); + db_add_index($ret, 'facebook_status', 'type', array('type')); + + // Update the type field in existing records. + $ret[] = update_sql("UPDATE {facebook_status} SET type = 'user'"); + + // Create the contexts table. + db_create_table($ret, 'facebook_status_contexts', _facebook_status_contexts_schema()); + + return $ret; } /** @@ -143,6 +169,7 @@ function facebook_status_update_6300() { */ function facebook_status_uninstall() { drupal_uninstall_schema('facebook_status'); + drupal_uninstall_schema('facebook_status_contexts'); variable_del('facebook_status_default_text'); variable_del('facebook_status_block_view'); variable_del('facebook_status_reply_type');