Page MenuHomePhabricator

[keyserver] Add thread column to uploads table
ClosedPublic

Authored by rohan on Jan 30 2023, 7:26 AM.
Tags
None
Referenced Files
F3538210: D6465.diff
Wed, Dec 25, 10:24 PM
Unknown Object (File)
Nov 24 2024, 8:13 AM
Unknown Object (File)
Nov 24 2024, 5:12 AM
Unknown Object (File)
Nov 23 2024, 9:00 PM
Unknown Object (File)
Nov 21 2024, 7:16 PM
Unknown Object (File)
Nov 21 2024, 2:12 PM
Unknown Object (File)
Nov 21 2024, 2:01 PM
Unknown Object (File)
Nov 21 2024, 1:55 PM
Subscribers
Tokens
"Party Time" token, awarded by atul.

Details

Summary

Attaching a thread column to the uploads table will important so we can associate each upload with a thread. This will allow us to later query media that was uploaded in a specific thread.

https://linear.app/comm/issue/ENG-2862/modify-the-uploads-table-to-include-a-thread-column (uploads table modification)

https://linear.app/comm/issue/ENG-2883/create-a-script-to-retroactively-populate-the-thread-column-in-the (retroactively populate table)

Test Plan

Restart keyserver and check the tables on TablePlus for uploads to check and confirm that there is a new thread column.

Thread column in uploads table.png (862×2 px, 583 KB)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

rohan edited the test plan for this revision. (Show Details)
rohan requested review of this revision.Jan 30 2023, 7:40 AM
This revision is now accepted and ready to land.Jan 30 2023, 9:58 AM

Not 100% sure if this is necessary but should we also add thread to the ALTER statement for the uploads table

Not 100% sure if this is necessary but should we also add thread to the ALTER statement for the uploads table

Nvm, I think we only do this if we made thread and INDEX

ashoat requested changes to this revision.Jan 30 2023, 12:25 PM

We need an index on thread if we plan to query on it

We also need a script to populate the column, not sure if that's meant to be a separate diff

This revision now requires changes to proceed.Jan 30 2023, 12:25 PM

Add index on thread, restarted keyserver to check that it started up ok

ashoat requested changes to this revision.Jan 30 2023, 1:33 PM

Please think this through... you're not adding the index in the migration.

This also wasn't addressed:

We also need a script to populate the column, not sure if that's meant to be a separate diff

This revision now requires changes to proceed.Jan 30 2023, 1:33 PM

Please think this through... you're not adding the index in the migration.

This also wasn't addressed:

We also need a script to populate the column, not sure if that's meant to be a separate diff

Ah right, this slipped my mind sorry about that.

To address the script, do you mean retroactively populate for existing media? This is the linear task for that per @atul's suggestion on Linear https://linear.app/comm/issue/ENG-2883/create-a-script-to-retroactively-populate-the-thread-column-in-the

Add the index into the migration following the statement to add the thread column. Followed migration #9 to confirm syntax with multipleStatements, and restarted keyserver to check that it starts up fine.

We also need a script to populate the column, not sure if that's meant to be a separate diff

Ah right, this slipped my mind sorry about that.

To address the script, do you mean retroactively populate for existing media? This is the linear task for that per @atul's suggestion on Linear https://linear.app/comm/issue/ENG-2883/create-a-script-to-retroactively-populate-the-thread-column-in-the

Yeah, that's what I mean. Except instead of a script it should just be a migration. Could just be migration 15, or you could introduce a subsequent migration later.

Note that it's important that we land the code that will populate the thread column for new uploads at the same time as (or earlier than) we land the migration that will populate the thread column for existing uploads – otherwise we might get some uploads that are missing thread.

This revision is now accepted and ready to land.Jan 31 2023, 6:20 AM

Could just be migration 15

(This would only be possible if you wait to land this until you have that other migration code ready to land as well)

Include the UPDATE statement to retroactively update all entries in the uploads table to have a corresponding thread.

Tested by doing the following:

  1. Ran UPDATE metadata SET data = 14 WHERE name = "db_version"; in TablePlus to trigger the migration to occur when restarting keyserver.
  2. Observed that several entries in the uploads table had their thread field as NULL.
  3. Ran yarn dev in keyserver
  4. Checked the uploads table to see all entries had a corresponding thread field, not NULL.

An additional update I added in this revision is IF NOT EXISTS to ADD INDEX IF NOT EXISTS thread (thread); to prevent anyone who ran the migration (mainly me, but if anyone tested this locally as
well) from running into an error of Duplicate key name 'thread' since the index already existed in a previous run of the migration.

Before:

Before.png (1×2 px, 1 MB)

After:

After.png (1×2 px, 761 KB)

rohan requested review of this revision.Jan 31 2023, 3:55 PM
rohan attached a referenced file: F354571: Before.png. (Show Details)
rohan attached a referenced file: F354572: After.png. (Show Details)

Requesting review again with the new changes to retroactively populate the thread column for existing uploads.

Please don't land this until you're ready to land a separate diff (presumably D6482) that updates keyserver to populate this column for new rows... otherwise we'll have a set of rows in the table without the thread column populated

keyserver/src/database/migration-config.js
155–159 ↗(On Diff #21722)

I think you can combine these two ALTER TABLE queries into one

This revision is now accepted and ready to land.Feb 1 2023, 2:52 AM

Combine the ALTER TABLE queries and re-do the the testing as mentioned in the previous revision. Confirmed migration 15 succeeded. was in my console.

keyserver/src/database/migration-config.js
160 ↗(On Diff #21747)

Can you keep this line to a max of 80 chars?

Reduce line length. Set my DB version back to 14 and restarted keyserver for good measure

This revision was landed with ongoing or failed builds.Feb 26 2023, 11:41 AM
This revision was automatically updated to reflect the committed changes.