diff --git a/migrations_wip/2021-09-29-042235_twitch_oauth_tokens/down.sql b/migrations/2022-01-11-042235_twitch_oauth_tokens/down.sql similarity index 80% rename from migrations_wip/2021-09-29-042235_twitch_oauth_tokens/down.sql rename to migrations/2022-01-11-042235_twitch_oauth_tokens/down.sql index fdbf0af1b8..0e3e1baa53 100644 --- a/migrations_wip/2021-09-29-042235_twitch_oauth_tokens/down.sql +++ b/migrations/2022-01-11-042235_twitch_oauth_tokens/down.sql @@ -2,3 +2,4 @@ -- noinspection SqlNoDataSourceInspectionForFile -- noinspection SqlResolveForFile +DROP TABLE twitch_oauth_tokens; diff --git a/migrations_wip/2021-09-29-042235_twitch_oauth_tokens/up.sql b/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql similarity index 64% rename from migrations_wip/2021-09-29-042235_twitch_oauth_tokens/up.sql rename to migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql index eed73ee95b..cf0ff137b7 100644 --- a/migrations_wip/2021-09-29-042235_twitch_oauth_tokens/up.sql +++ b/migrations/2022-01-11-042235_twitch_oauth_tokens/up.sql @@ -10,17 +10,37 @@ CREATE TABLE twitch_oauth_tokens( -- Not used for anything except replication. id BIGINT(20) NOT NULL AUTO_INCREMENT, - -- Foreign key to user (Vocodes/Storyteller user) + -- ========== STORYTELLER/FAKEYOU USER ========== + + -- Foreign key to user (Storyteller/FakeYou user) -- If no user is associated (anonymous Twitch user), then this is null. maybe_user_token VARCHAR(32) DEFAULT NULL, + -- ========== TWITCH USER ========== + -- 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 - maybe_twitch_user_id VARCHAR(32) DEFAULT NULL, + twitch_user_id VARCHAR(32) NOT NULL, -- Usernames are between 4 and 25 characters. maybe_twitch_username VARCHAR(32) DEFAULT NULL, + -- ========== OAUTH TOKEN DETAILS ========== + + -- The ever important OAuth access token. + access_token VARCHAR(128) NOT NULL, + + -- If we can refresh the token, this is the thing to use. + maybe_refresh_token VARCHAR(128) DEFAULT NULL, + + -- Should be "bearer". Included in the OAuth redemption. + token_type VARCHAR(32) DEFAULT NULL, + + -- When the token expires from time of first grant. + -- (We don't update this field.) + -- Null if it does not expire or we were not informed + expires_in_seconds INT(10) DEFAULT NULL, + -- ========== OAUTH SCOPES ========== -- "bits:read" @@ -56,7 +76,11 @@ CREATE TABLE twitch_oauth_tokens( created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - -- This is when the OAuth token will expire. We need to refresh before this time. + -- This is when the OAuth token will expire. + -- While we need to refresh before this time, Twitch recommends against eager + -- refreshes and instead wants the code to lazily refresh. + -- This also has no bearing on the "refresh_token". + -- We'll just use this for bookkeeping. expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- If the OAuth token is deleted, we set this. @@ -66,10 +90,15 @@ CREATE TABLE twitch_oauth_tokens( -- INDICES -- PRIMARY KEY (id), - KEY fk_maybe_user_token (maybe_user_token) + KEY fk_maybe_user_token (maybe_user_token), + KEY index_twitch_user_id (twitch_user_id), + KEY index_maybe_twitch_username (maybe_twitch_username), + KEY index_expires_at (expires_at), + KEY index_user_deleted_at (user_deleted_at), + KEY index_mod_deleted_at (mod_deleted_at) - --KEY index_has_bits_read (has_bits_read), - --KEY index_creator_ip_address (creator_ip_address) + -- KEY index_has_bits_read (has_bits_read), + -- KEY index_creator_ip_address (creator_ip_address) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;