Skip to content

Commit

Permalink
[DB MIGRATION REQ'D] Add first_seen to follows table
Browse files Browse the repository at this point in the history
* Will enable future 'new follows' data listings
  • Loading branch information
ginatrapani committed Aug 30, 2011
1 parent ba1bca6 commit b1c59ea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
16 changes: 8 additions & 8 deletions webapp/_lib/model/class.FollowMySQLDAO.php
Expand Up @@ -61,8 +61,8 @@ public function followExists($user_id, $follower_id, $network, $is_active=false)

public function update($user_id, $follower_id, $network, $debug_api_call = '') {
$q = " UPDATE #prefix#follows ";
$q .= " SET last_seen=NOW(), debug_api_call = :debug";
$q .= " WHERE user_id = :userid AND follower_id = :followerid AND network = :network ;";
$q .= "SET last_seen=NOW(), debug_api_call = :debug ";
$q .= "WHERE user_id = :userid AND follower_id = :followerid AND network = :network;";
$vars = array(
':userid'=>$user_id,
':followerid'=>$follower_id,
Expand All @@ -76,9 +76,9 @@ public function update($user_id, $follower_id, $network, $debug_api_call = '') {
}

public function deactivate($user_id, $follower_id, $network, $debug_api_call = '') {
$q = " UPDATE #prefix#follows ";
$q .= " SET active = 0 , debug_api_call = :debug ";
$q .= " WHERE user_id = :userid AND follower_id = :followerid AND network = :network ;";
$q = "UPDATE #prefix#follows ";
$q .= "SET active = 0 , debug_api_call = :debug ";
$q .= "WHERE user_id = :userid AND follower_id = :followerid AND network = :network;";
$vars = array(
':userid'=>$user_id,
':followerid'=>$follower_id,
Expand All @@ -92,9 +92,9 @@ public function deactivate($user_id, $follower_id, $network, $debug_api_call = '
}

public function insert($user_id, $follower_id, $network, $debug_api_call = '') {
$q = " INSERT INTO #prefix#follows ";
$q .= " (user_id, follower_id, last_seen, debug_api_call, network) ";
$q .= " VALUES ( :userid, :followerid, NOW(), :debug, :network );";
$q = "INSERT INTO #prefix#follows ";
$q .= "(user_id, follower_id, first_seen, last_seen, debug_api_call, network) ";
$q .= "VALUES ( :userid, :followerid, NOW(), NOW(), :debug, :network );";
$vars = array(
':userid'=>$user_id,
':followerid'=>$follower_id,
Expand Down
17 changes: 9 additions & 8 deletions webapp/install/sql/build-db_mysql.sql
Expand Up @@ -50,16 +50,17 @@ CREATE TABLE tu_follower_count (
--

CREATE TABLE tu_follows (
user_id bigint(11) NOT NULL,
follower_id bigint(11) NOT NULL,
last_seen timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
active int(11) NOT NULL DEFAULT '1',
network varchar(20) NOT NULL DEFAULT 'twitter',
debug_api_call varchar(255) NOT NULL,
user_id bigint(11) NOT NULL COMMENT 'User ID on a particular service who has been followed.',
follower_id bigint(11) NOT NULL COMMENT 'User ID on a particular service who has followed user_id.',
last_seen timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last time this relationship was seen on the originating network.',
first_seen timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'First time this relationship was seen on the originating network.',
active int(11) NOT NULL DEFAULT '1' COMMENT 'Whether or not the relationship is active (1 if so, 0 if not.)',
network varchar(20) NOT NULL DEFAULT 'twitter' COMMENT 'Originating network in lower case, i.e., twitter or facebook.',
debug_api_call varchar(255) NOT NULL COMMENT 'Developer-only field for storing the API URL source of this data point.',
UNIQUE KEY user_id (network,follower_id,user_id),
KEY active (network,active,last_seen),
KEY network (network,last_seen)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Service user follow and friend relationships.';

--
-- Table structure for table tu_hashtags
Expand Down Expand Up @@ -424,7 +425,7 @@ CREATE TABLE tu_users (
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Service user details.';


-- Dump completed on 2011-08-30 11:56:12
-- Dump completed on 2011-08-30 12:08:55

--
-- Insert DB Version
Expand Down
@@ -0,0 +1,24 @@
-- Add first_seen field to tu_follows
-- While we're in there, comment all the fields of the new table

CREATE TABLE tu_follows_b15 (
user_id bigint(11) NOT NULL COMMENT 'User ID on a particular service who has been followed.',
follower_id bigint(11) NOT NULL COMMENT 'User ID on a particular service who has followed user_id.',
last_seen timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last time this relationship was seen on the originating network.',
first_seen timestamp NOT NULL COMMENT 'First time this relationship was seen on the originating network.',
active int(11) NOT NULL DEFAULT '1' COMMENT 'Whether or not the relationship is active (1 if so, 0 if not.)',
network varchar(20) NOT NULL DEFAULT 'twitter' COMMENT 'Originating network in lower case, i.e., twitter or facebook.',
debug_api_call varchar(255) NOT NULL COMMENT 'Developer-only field for storing the API URL source of this data point.',
UNIQUE KEY user_id (network,follower_id,user_id),
KEY active (network,active,last_seen),
KEY network (network,last_seen)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Service user follow and friend relationships.';

INSERT INTO tu_follows_b15 (SELECT user_id, follower_id, last_seen, last_seen, active, network, debug_api_call FROM tu_follows);

RENAME TABLE tu_follows TO tu_follows_b14;

RENAME TABLE tu_follows_b15 TO tu_follows;

DROP TABLE tu_follows_b14;

0 comments on commit b1c59ea

Please sign in to comment.