From fdaa4a2eef877251012b69dd78cdd0752d76bcc2 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 12 Jan 2022 00:17:08 -0500 Subject: [PATCH] fix queries --- .../lib/database_queries/src/twitch_oauth/find.rs | 14 +++++++------- .../database_queries/src/twitch_oauth/insert.rs | 10 +++++----- .../2022-01-11-042235_twitch_oauth_tokens/up.sql | 6 +++++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/lib/database_queries/src/twitch_oauth/find.rs b/crates/lib/database_queries/src/twitch_oauth/find.rs index 43036c0149..44d7905597 100644 --- a/crates/lib/database_queries/src/twitch_oauth/find.rs +++ b/crates/lib/database_queries/src/twitch_oauth/find.rs @@ -13,14 +13,14 @@ pub struct TwitchOauthTokenRecord { pub maybe_gravatar_hash: Option, /// Twitch user - //pub twitch_user_id: u32, + pub twitch_user_id: String, pub maybe_twitch_username: Option, /// Token details pub access_token: String, pub maybe_refresh_token: Option, pub token_type: Option, - //pub expires_in_seconds: Option, + pub expires_in_seconds: Option, pub has_bits_read: bool, pub has_channel_read_subscriptions: bool, pub has_channel_read_redemptions: bool, @@ -76,12 +76,12 @@ impl TwitchOauthTokenFinder { maybe_user_token: record.maybe_user_token.clone(), maybe_display_name: record.maybe_display_name.clone(), maybe_gravatar_hash: record.maybe_gravatar_hash.clone(), - //twitch_user_id: record.twitch_user_id, + twitch_user_id: record.twitch_user_id.clone(), maybe_twitch_username: record.maybe_twitch_username.clone(), access_token: record.access_token.clone(), maybe_refresh_token: record.maybe_refresh_token.clone(), token_type: record.token_type.clone(), - //expires_in_seconds: record.expires_in_seconds.clone(), + expires_in_seconds: record.expires_in_seconds.clone(), has_bits_read: i8_to_bool(record.has_bits_read), has_channel_read_subscriptions: i8_to_bool(record.has_channel_read_subscriptions), has_channel_read_redemptions: i8_to_bool(record.has_channel_read_redemptions), @@ -226,7 +226,7 @@ LEFT OUTER JOIN users } } -#[derive(Serialize)] +#[derive(sqlx::FromRow)] pub struct TwitchOauthTokenRecordInternal { /// NB: Vocodes/FakeYou/Storyteller user pub maybe_user_token: Option, @@ -234,14 +234,14 @@ pub struct TwitchOauthTokenRecordInternal { pub maybe_gravatar_hash: Option, /// Twitch user - //pub twitch_user_id: u32, + pub twitch_user_id: String, pub maybe_twitch_username: Option, /// Token details pub access_token: String, pub maybe_refresh_token: Option, pub token_type: Option, - //pub expires_in_seconds: Option, + pub expires_in_seconds: Option, pub has_bits_read: i8, pub has_channel_read_subscriptions: i8, pub has_channel_read_redemptions: i8, diff --git a/crates/lib/database_queries/src/twitch_oauth/insert.rs b/crates/lib/database_queries/src/twitch_oauth/insert.rs index 8c63abec6c..3471d0b259 100644 --- a/crates/lib/database_queries/src/twitch_oauth/insert.rs +++ b/crates/lib/database_queries/src/twitch_oauth/insert.rs @@ -8,8 +8,9 @@ use sqlx::MySqlPool; pub struct TwitchOauthTokenInsertBuilder { // ===== Required Fields ===== - /// Exactly an INT(10) ~= UNSIGNED INTEGER - twitch_user_id: u32, + /// Old APIs return a u32, but this should be a string. + /// Twitch is migrating IDs to strings. + twitch_user_id: String, access_token: String, @@ -40,9 +41,9 @@ pub struct TwitchOauthTokenInsertBuilder { } impl TwitchOauthTokenInsertBuilder { - pub fn new(twitch_user_id: u32, access_token: &str) -> Self { + pub fn new(twitch_user_id: &str, access_token: &str) -> Self { Self { - twitch_user_id, + twitch_user_id: twitch_user_id.to_string(), access_token: access_token.to_string(), maybe_refresh_token: None, maybe_user_token: None, @@ -82,7 +83,6 @@ impl TwitchOauthTokenInsertBuilder { self } - pub fn set_expires_in_seconds(mut self, expires_in_seconds: Option) -> Self { self.expires_in_seconds = expires_in_seconds; self diff --git a/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql b/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql index 5cbbc58996..2d5ea3b6ed 100644 --- a/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql +++ b/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql @@ -20,7 +20,11 @@ CREATE TABLE twitch_oauth_tokens( -- The user ID / channel ID are the same -- https://discuss.dev.twitch.tv/t/what-is-the-difference-between-the-stream--id-and-channel--id/4423 - twitch_user_id INT(10) UNSIGNED NOT NULL, + -- Several suggest this should be a string and not an integer + -- https://discuss.dev.twitch.tv/t/type-of-user-id-in-api-responses/10205 + -- Yep, strings + -- https://discuss.dev.twitch.tv/t/bug-v5-api-returns--id-as-string-for-featured-channels/10310 + twitch_user_id VARCHAR(64) NOT NULL, -- Usernames are between 4 and 25 characters. maybe_twitch_username VARCHAR(32) DEFAULT NULL,