Switch logincookies primary key to auto_incremented id, make cookie a secondary UNIQUE key

RESOLVED FIXED

Status

()

bugzilla.mozilla.org
General
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: dylan, Assigned: dylan)

Tracking

Production

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

2 years ago
This is a required change for bug 1192687, as natural primary keys (such as "cookie") are very difficult to work with, especially when they are secrets.
(Assignee)

Comment 1

2 years ago
Created attachment 8650840 [details] [diff] [review]
1196092_5.patch

This was remarkably hard to get right. bz_column_info_real() is used because bz_column_info() returns our fake, shadow schema...
Attachment #8650840 - Flags: review?(glob)
Comment on attachment 8650840 [details] [diff] [review]
1196092_5.patch

Review of attachment 8650840 [details] [diff] [review]:
-----------------------------------------------------------------

Updating column cookie in table logincookies ...
Old: varchar(22) PRIMARY KEY NOT NULL
New: varchar(22) NOT NULL
DBD::mysql::db do failed: Can't DROP 'PRIMARY'; check that column/key exists [for Statement "ALTER TABLE logincookies DROP PRIMARY KEY"] at Bugzilla/DB.pm line 760.
Attachment #8650840 - Flags: review?(glob) → review-
(Assignee)

Comment 3

2 years ago
Created attachment 8651196 [details] [diff] [review]
1196092_6.patch

It would appear I underestimated our DB schema layer. It can actually drop the primary key itself.
Attachment #8650840 - Attachment is obsolete: true
Attachment #8651196 - Flags: review?(glob)
Comment on attachment 8651196 [details] [diff] [review]
1196092_6.patch

Review of attachment 8651196 [details] [diff] [review]:
-----------------------------------------------------------------

this generates the same sql, which fails:

Updating column cookie in table logincookies ...
Old: varchar(22) PRIMARY KEY NOT NULL
New: varchar(22) NOT NULL
DBD::mysql::db do failed: Can't DROP 'PRIMARY'; check that column/key exists [for Statement "ALTER TABLE logincookies DROP PRIMARY KEY"] at Bugzilla/DB.pm line 760.
Attachment #8651196 - Flags: review?(glob) → review-
Comment on attachment 8651196 [details] [diff] [review]
1196092_6.patch

Review of attachment 8651196 [details] [diff] [review]:
-----------------------------------------------------------------

ah, my bad.  for reasons that are unknown logincookies.cookie isn't a PK in the db i'm using, and a mysql quirk had it reporting it incorrectly ("A UNIQUE index may be displayed as PRI if it cannot contain NULL values and there is no PRIMARY KEY in the table").

r=glob

::: Bugzilla/Install/DB.pm
@@ +738,4 @@
>      $dbh->bz_alter_column('logincookies', 'cookie',
> +                            {TYPE => 'varchar(22)', NOTNULL => 1});
> +    $dbh->bz_add_index('logincookies', 'logincookies_cookie_idx',
> +                        {TYPE => 'UNIQUE', FIELDS => ['cookie']});

nit: this line and the previous {TYPE should line up with the '
Attachment #8651196 - Flags: review- → review+
To ssh://gitolite3@git.mozilla.org/webtools/bmo/bugzilla.git
   0b05719..57f911c  master -> master
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.