From c8bfb1f2f0e0fa8c0801e8de2466a5297ff10ee2 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 12 Jan 2022 01:42:53 -0500 Subject: [PATCH] codegen db --- Cargo.lock | 1 + codegen_database.sh | 4 ++-- crates/service/storyteller_web/Cargo.toml | 1 + crates/service/storyteller_web/src/main.rs | 9 ++++++++- sqlx-data.json | 20 ++++++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 213928ec1f..ba6b082538 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3764,6 +3764,7 @@ dependencies = [ "config", "container_common", "data-encoding", + "database_queries", "derive_more", "diesel", "dotenv", diff --git a/codegen_database.sh b/codegen_database.sh index f1fc85b502..74ed8ec3fa 100755 --- a/codegen_database.sh +++ b/codegen_database.sh @@ -1,11 +1,11 @@ #!/bin/bash # Necessary since we're now in a more complex Rust workspace -pushd crates/app/storyteller_web +pushd crates/service/storyteller_web SQLX_OFFLINE=true cargo sqlx prepare -- --bin storyteller-web popd -mv crates/app/storyteller_web/sqlx-data.json . +mv crates/service/storyteller_web/sqlx-data.json . diff --git a/crates/service/storyteller_web/Cargo.toml b/crates/service/storyteller_web/Cargo.toml index ed2c2e565e..960e5f1850 100644 --- a/crates/service/storyteller_web/Cargo.toml +++ b/crates/service/storyteller_web/Cargo.toml @@ -40,6 +40,7 @@ path = "src/w2l_inference_job.rs" # Internal config = { path = "../../lib/config" } container_common = { path = "../../lib/container_common" } +database_queries = { path = "../../lib/database_queries" } http_server_common = { path = "../../lib/http_server_common" } # External diff --git a/crates/service/storyteller_web/src/main.rs b/crates/service/storyteller_web/src/main.rs index e618b7e806..a203619c2c 100644 --- a/crates/service/storyteller_web/src/main.rs +++ b/crates/service/storyteller_web/src/main.rs @@ -28,6 +28,13 @@ pub mod validations; // NB: This is included so sqlx can generate all the queries. mod job_queries; +// NB: Also so sqlx codegens everything. +// Not sure if this is strictly necessary. +mod shared_queries { + use database_queries::twitch_oauth::find; + use database_queries::twitch_oauth::insert; +} + use actix_cors::Cors; use actix_http::http; use actix_web::middleware::{Logger, DefaultHeaders}; @@ -98,6 +105,7 @@ use crate::http_server::middleware::ip_filter_middleware::IpFilter; use crate::http_server::web_utils::cookie_manager::CookieManager; use crate::http_server::web_utils::redis_rate_limiter::RedisRateLimiter; use crate::http_server::web_utils::session_checker::SessionChecker; +use crate::routes::add_routes; use crate::server_state::{ServerState, EnvConfig}; use crate::threads::ip_banlist_set::IpBanlistSet; use crate::threads::poll_ip_banlist_thread::poll_ip_bans; @@ -116,7 +124,6 @@ use sqlx::mysql::MySqlPoolOptions; use std::sync::Arc; use std::time::Duration; use tokio::runtime::Runtime; -use crate::routes::add_routes; // TODO TODO TODO TODO // TODO TODO TODO TODO diff --git a/sqlx-data.json b/sqlx-data.json index 3034afff0e..5b53a085f0 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -375,6 +375,16 @@ ] } }, + "05030f800d4e16abedc75fd0697711e9396a0eae783ad86a86dd7c0540a4d489": { + "query": "\nINSERT INTO twitch_oauth_tokens\nSET\n maybe_user_token = ?,\n twitch_user_id = ?,\n maybe_twitch_username = ?,\n access_token = ?,\n maybe_refresh_token = ?,\n token_type = ?,\n expires_in_seconds = ?,\n has_bits_read = ?,\n has_channel_read_subscriptions = ?,\n has_channel_read_redemptions= ?,\n has_user_read_follows = ?,\n ip_address_creation = ?,\n expires_at = DATE_ADD(NOW(), INTERVAL ? SECOND)\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 13 + }, + "nullable": [] + } + }, "05612e384bdce558e4834c720d1eb7ca9a09e3cca64b72f1497929d860345ec7": { "query": "\nSELECT\n tts.token as model_token,\n tts.tts_model_type,\n tts.creator_user_token,\n users.username as creator_username,\n users.display_name as creator_display_name,\n users.email_gravatar_hash as creator_gravatar_hash,\n tts.title,\n tts.is_locked_from_use,\n tts.created_at,\n tts.updated_at\nFROM tts_models as tts\nJOIN users\nON\n users.token = tts.creator_user_token\nWHERE\n users.username = ?\n AND tts.is_locked_from_use IS FALSE\n AND tts.user_deleted_at IS NULL\n AND tts.mod_deleted_at IS NULL\n ", "describe": { @@ -5960,6 +5970,16 @@ "nullable": [] } }, + "91beefeb04c0baafe4c3983c2760df2e5d08ea5e2433225221d20da8d2dca114": { + "query": "\nINSERT INTO twitch_oauth_tokens\nSET\n maybe_user_token = ?,\n twitch_user_id = ?,\n maybe_twitch_username = ?,\n access_token = ?,\n maybe_refresh_token = ?,\n token_type = ?,\n expires_in_seconds = NULL,\n has_bits_read = ?,\n has_channel_read_subscriptions = ?,\n has_channel_read_redemptions= ?,\n has_user_read_follows = ?,\n ip_address_creation = ?,\n expires_at = NULL\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 11 + }, + "nullable": [] + } + }, "961f792c24bee6009e3e8a215561db932871a53c48839b8cb80292de00e7b2e1": { "query": "\nUPDATE tts_results\nSET\n user_deleted_at = CURRENT_TIMESTAMP\nWHERE\n token = ?\nLIMIT 1\n ", "describe": {