From c30fbfbf82cfda98399c3fabc60b0dda8458ad03 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 31 Jan 2022 22:43:50 -0500 Subject: [PATCH] SQLX db codegen / cache failed (??), this should fix it --- codegen_database.sh | 45 ++++++++++++++++--- sqlx-data.json | 102 ++++++++++++++++++++++---------------------- 2 files changed, 91 insertions(+), 56 deletions(-) diff --git a/codegen_database.sh b/codegen_database.sh index 74ed8ec3fa..dc9d904b7f 100755 --- a/codegen_database.sh +++ b/codegen_database.sh @@ -1,11 +1,46 @@ #!/bin/bash -# Necessary since we're now in a more complex Rust workspace -pushd crates/service/storyteller_web +# This is complicated since we're now in a more complex Rust workspace with +# multiple projects and targets. -SQLX_OFFLINE=true cargo sqlx prepare -- --bin storyteller-web +# NB(2022-01-31): For some reason, 'storyteller-web', despite importing the obs queries +# via the `database_queries` shared library, started to exclude these queries. It was +# working, but mysteriously stopped. I'm using this more complicated setup with jq-based +# json merge as a stop gap. -popd +# NB: This format can be used without changing directory: +# SQLX_OFFLINE=true cargo sqlx prepare -- --bin storyteller-web --manifest-path crates/service/storyteller_web/Cargo.toml -mv crates/service/storyteller_web/sqlx-data.json . +build_shared_database_library() { + pushd crates/lib/database_queries + SQLX_OFFLINE=true cargo sqlx prepare + popd +} + +build_storyteller_web_app() { + # NB: This imports the inference/upload job queries + # It should also import the shared database lib queries, but something(???) broke. + pushd crates/service/storyteller_web + SQLX_OFFLINE=true cargo sqlx prepare -- --bin storyteller-web # NB: Because multiple binary targets + popd +} + +combine_sqlx_queries() { + # Merge multiple JSON files into a single dictionary. + # https://stackoverflow.com/a/24904276 + jq -s '.[0] * .[1]' \ + crates/lib/database_queries/sqlx-data.json \ + crates/service/storyteller_web/sqlx-data.json \ + > sqlx-data.json +} + +cleanup_temp_files() { + rm crates/lib/database_queries/sqlx-data.json \ + crates/service/storyteller_web/sqlx-data.json +} + +build_shared_database_library +build_storyteller_web_app +combine_sqlx_queries +cleanup_temp_files diff --git a/sqlx-data.json b/sqlx-data.json index 2841026a80..5701613287 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -1,5 +1,55 @@ { "db": "MySQL", + "3a4a4edd2b1a1957c5eb42ed426ef4c11468549b9b8c3d62f1d59c07f4495c0e": { + "query": "\nINSERT INTO twitch_oauth_tokens\nSET\n maybe_user_token = ?,\n twitch_user_id = ?,\n twitch_username = ?,\n twitch_username_lowercase = ?,\n access_token = ?,\n maybe_refresh_token = ?,\n refresh_count = ?,\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": 13 + }, + "nullable": [] + } + }, + "591bda610a0fe952cafc5d97808757da8652133082e94ad15ab063db9d4e2f44": { + "query": "\nINSERT INTO tts_inference_jobs\nSET\n token = ?,\n uuid_idempotency_token = ?,\n model_token = ?,\n raw_inference_text = ?,\n maybe_creator_user_token = ?,\n creator_ip_address = ?,\n creator_set_visibility = ?,\n status = \"pending\"\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 7 + }, + "nullable": [] + } + }, + "5e4a00c339ce4d7fac19aff728449156b1e02b9e1d9fd534ac37d4ac79f44820": { + "query": "\nINSERT INTO twitch_bits_events\nSET\n sender_twitch_user_id = ?,\n sender_twitch_username = ?,\n sender_twitch_username_lowercase = ?,\n destination_channel_id = ?,\n destination_channel_name = ?,\n is_anonymous= ?,\n bits_used = ?,\n total_bits_used = ?,\n chat_message = ?\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 9 + }, + "nullable": [] + } + }, + "5eacdf9c65dc13820077be2930cca7047aed07804ed2e7b2ff38e12a617b4858": { + "query": "\nINSERT INTO twitch_channel_point_events\nSET\n sender_twitch_user_id = ?,\n sender_twitch_username = ?,\n sender_twitch_username_lowercase = ?,\n destination_channel_id = ?,\n destination_channel_name = ?,\n title = ?,\n prompt = ?,\n user_text_input = ?,\n redemption_id = ?,\n reward_id = ?,\n reward_cost = ?,\n is_sub_only = ?,\n max_per_stream = ?,\n max_per_user_per_stream = ?\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 14 + }, + "nullable": [] + } + }, + "cad1a53adb21efd78fa3a6f3c8c0f4d5f55164c4f397b50426bf987ea68af3d0": { + "query": "\nINSERT INTO twitch_oauth_tokens\nSET\n maybe_user_token = ?,\n twitch_user_id = ?,\n twitch_username = ?,\n twitch_username_lowercase = ?,\n access_token = ?,\n maybe_refresh_token = ?,\n refresh_count = ?,\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": 15 + }, + "nullable": [] + } + }, "0033c76be0ea1c99069f1a8df1ce400c7064526feaf5dc88930da0718a885b19": { "query": "\nSELECT\n w2l.token as template_token,\n w2l.template_type,\n w2l.creator_user_token,\n users.is_banned as creator_is_banned,\n users.username as creator_username,\n users.display_name as creator_display_name,\n users.email_gravatar_hash as creator_gravatar_hash,\n w2l.title,\n w2l.description_markdown,\n w2l.description_rendered_html,\n w2l.frame_width,\n w2l.frame_height,\n w2l.duration_millis,\n w2l.maybe_public_bucket_preview_image_object_name,\n w2l.maybe_public_bucket_preview_video_object_name,\n w2l.creator_set_visibility,\n w2l.is_public_listing_approved,\n w2l.is_locked_from_use,\n w2l.is_locked_from_user_modification,\n w2l.creator_ip_address_creation,\n w2l.creator_ip_address_last_update,\n w2l.created_at,\n w2l.updated_at,\n w2l.user_deleted_at,\n w2l.mod_deleted_at\nFROM w2l_templates as w2l\nJOIN users\n ON users.token = w2l.creator_user_token\nWHERE w2l.token = ?\n ", "describe": { @@ -2296,16 +2346,6 @@ "nullable": [] } }, - "3a4a4edd2b1a1957c5eb42ed426ef4c11468549b9b8c3d62f1d59c07f4495c0e": { - "query": "\nINSERT INTO twitch_oauth_tokens\nSET\n maybe_user_token = ?,\n twitch_user_id = ?,\n twitch_username = ?,\n twitch_username_lowercase = ?,\n access_token = ?,\n maybe_refresh_token = ?,\n refresh_count = ?,\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": 13 - }, - "nullable": [] - } - }, "40a3301e9a3201e74d49b6b339f67291e2ae22d315188401708609ac2d28a68c": { "query": "\nUPDATE tts_results\nSET\n mod_deleted_at = NULL,\n maybe_mod_user_token = ?\nWHERE\n token = ?\nLIMIT 1\n ", "describe": { @@ -3823,16 +3863,6 @@ ] } }, - "591bda610a0fe952cafc5d97808757da8652133082e94ad15ab063db9d4e2f44": { - "query": "\nINSERT INTO tts_inference_jobs\nSET\n token = ?,\n uuid_idempotency_token = ?,\n model_token = ?,\n raw_inference_text = ?,\n maybe_creator_user_token = ?,\n creator_ip_address = ?,\n creator_set_visibility = ?,\n status = \"pending\"\n ", - "describe": { - "columns": [], - "parameters": { - "Right": 7 - }, - "nullable": [] - } - }, "5d1f983fd2555c0fcb2ba065e9b3c6174346ee0fdaecacc2a557715a68cf23e2": { "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.user_deleted_at IS NULL\n AND tts.mod_deleted_at IS NULL\n ", "describe": { @@ -3975,16 +4005,6 @@ ] } }, - "5e4a00c339ce4d7fac19aff728449156b1e02b9e1d9fd534ac37d4ac79f44820": { - "query": "\nINSERT INTO twitch_bits_events\nSET\n sender_twitch_user_id = ?,\n sender_twitch_username = ?,\n sender_twitch_username_lowercase = ?,\n destination_channel_id = ?,\n destination_channel_name = ?,\n is_anonymous= ?,\n bits_used = ?,\n total_bits_used = ?,\n chat_message = ?\n ", - "describe": { - "columns": [], - "parameters": { - "Right": 9 - }, - "nullable": [] - } - }, "5e54fd8569b2d6d3a0d11acee6bd03b75400b6325952eb16c8dac68a7933b13a": { "query": "\nSELECT\n users.token as user_token,\n username,\n display_name,\n email_gravatar_hash,\n profile_markdown,\n profile_rendered_html,\n user_role_slug,\n is_banned,\n disable_gravatar,\n discord_username,\n twitch_username,\n twitter_username,\n patreon_username,\n github_username,\n created_at\nFROM users\nWHERE\n users.username = ?\n AND users.user_deleted_at IS NULL\n AND users.mod_deleted_at IS NULL\n ", "describe": { @@ -4192,16 +4212,6 @@ ] } }, - "5eacdf9c65dc13820077be2930cca7047aed07804ed2e7b2ff38e12a617b4858": { - "query": "\nINSERT INTO twitch_channel_point_events\nSET\n sender_twitch_user_id = ?,\n sender_twitch_username = ?,\n sender_twitch_username_lowercase = ?,\n destination_channel_id = ?,\n destination_channel_name = ?,\n title = ?,\n prompt = ?,\n user_text_input = ?,\n redemption_id = ?,\n reward_id = ?,\n reward_cost = ?,\n is_sub_only = ?,\n max_per_stream = ?,\n max_per_user_per_stream = ?\n ", - "describe": { - "columns": [], - "parameters": { - "Right": 14 - }, - "nullable": [] - } - }, "60c06a507349919addb5d26b1c4a283a04f66fce86e84ed0a51db6001c9fc2b5": { "query": "\nUPDATE w2l_templates\nSET\n title = ?,\n description_markdown = ?,\n description_rendered_html = ?,\n creator_set_visibility = ?,\n maybe_mod_user_token = ?,\n version = version + 1\nWHERE token = ?\nLIMIT 1\n ", "describe": { @@ -8308,16 +8318,6 @@ "nullable": [] } }, - "cad1a53adb21efd78fa3a6f3c8c0f4d5f55164c4f397b50426bf987ea68af3d0": { - "query": "\nINSERT INTO twitch_oauth_tokens\nSET\n maybe_user_token = ?,\n twitch_user_id = ?,\n twitch_username = ?,\n twitch_username_lowercase = ?,\n access_token = ?,\n maybe_refresh_token = ?,\n refresh_count = ?,\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": 15 - }, - "nullable": [] - } - }, "cc4372cdd1a65999cbaf008f200683eedc93ab83e17256e47e011667ba8384d8": { "query": "\nUPDATE tts_results\nSET\n creator_set_visibility = ?,\n creator_ip_address = ?\nWHERE token = ?\nLIMIT 1\n ", "describe": { @@ -9492,4 +9492,4 @@ "nullable": [] } } -} \ No newline at end of file +}