@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Give the session table a normal `id` column as a primary key

Summary:
Ref T4310. Ref T3720. Two major things are going on here:

- I'm making this table work more like a standard table, which, e.g., makes `delete()` simpler to implement.
- Currently, the primary key is `(userPHID, type)`. I want to get rid of this, issue unlimited sessions, and GC old sessions. This means we can't have a unique key on `(userPHID, type)` anymore. This removes it as the primary key and adds it as a normal key instead. There's no functional change -- the code to generate sessions guarantees that it will never write duplicate rows or write additional rows -- but allows us to drop the `-1`, `-2` qualifiers in the future.
- Also of note, our task is made far simpler here because MySQL will automatically assign values to new `AUTO_INCREMENT` columns, so we don't have to migrate to get real IDs.

Test Plan: Ran migrations, verified table looked sane. Logged out, logged in.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3720, T4310

Differential Revision: https://secure.phabricator.com/D7975

+8 -12
+8
resources/sql/autopatches/20140115.auth.1.id.sql
··· 1 + ALTER TABLE {$NAMESPACE}_user.phabricator_session 2 + DROP PRIMARY KEY; 3 + 4 + ALTER TABLE {$NAMESPACE}_user.phabricator_session 5 + ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; 6 + 7 + ALTER TABLE {$NAMESPACE}_user.phabricator_session 8 + ADD KEY `key_identity` (userPHID, type);
-12
src/applications/auth/storage/PhabricatorAuthSession.php
··· 15 15 16 16 public function getConfiguration() { 17 17 return array( 18 - self::CONFIG_IDS => self::IDS_MANUAL, 19 18 self::CONFIG_TIMESTAMPS => false, 20 19 ) + parent::getConfiguration(); 21 20 } ··· 37 36 38 37 public function getIdentityObject() { 39 38 return $this->assertAttached($this->identityObject); 40 - } 41 - 42 - public function delete() { 43 - // TODO: We don't have a proper `id` column yet, so make this work as 44 - // expected until we do. 45 - queryfx( 46 - $this->establishConnection('w'), 47 - 'DELETE FROM %T WHERE sessionKey = %s', 48 - $this->getTableName(), 49 - $this->getSessionKey()); 50 - return $this; 51 39 } 52 40 53 41 /* -( PhabricatorPolicyInterface )----------------------------------------- */