diff --git a/src/command/config/migrate/v20240701.rs b/src/command/config/migrate/v20240701.rs index 7eb366e..40e5a12 100644 --- a/src/command/config/migrate/v20240701.rs +++ b/src/command/config/migrate/v20240701.rs @@ -66,7 +66,8 @@ fn read_default_yml() -> Result, ReadYamlConfigError> { Ok(res) } -#[derive(Debug)] +#[derive(sqlx::FromRow, Debug)] +#[sqlx(rename_all = "camelCase")] struct Meta { name: Option, description: Option, @@ -164,368 +165,11 @@ async fn read_meta_table( .connect() .await?; - let ( - name, - description, - maintainer_name, - maintainer_email, - disable_registration, - disable_local_timeline, - disable_global_timeline, - banner_url, - error_image_url, - icon_url, - cache_remote_files, - enable_recaptcha, - recaptcha_site_key, - recaptcha_secret_key, - local_drive_capacity_mb, - ): ( - Option, - Option, - Option, - Option, - bool, - bool, - bool, - Option, - Option, - Option, - bool, - bool, - Option, - Option, - i32, - ) = sqlx::query_as( - r#" - SELECT - "name", - "description", - "maintainerName", - "maintainerEmail", - "disableRegistration", - "disableLocalTimeline", - "disableGlobalTimeline", - "bannerUrl", - "errorImageUrl", - "iconUrl", - "cacheRemoteFiles", - "enableRecaptcha", - "recaptchaSiteKey", - "recaptchaSecretKey", - "localDriveCapacityMb" - FROM - "meta" - "#, - ) - .fetch_one(&mut conn) - .await?; + let meta: Meta = sqlx::query_as(r#"SELECT * FROM "meta""#) + .fetch_one(&mut conn) + .await?; - let ( - remote_drive_capacity_mb, - summaly_proxy, - enable_email, - email, - smtp_secure, - smtp_host, - smtp_port, - smtp_user, - smtp_pass, - enable_service_worker, - sw_public_key, - sw_private_key, - pinned_users, - tos_url, - repository_url, - ): ( - i32, - Option, - bool, - Option, - bool, - Option, - Option, - Option, - Option, - bool, - Option, - Option, - Vec, - Option, - String, - ) = sqlx::query_as( - r#" - SELECT - "remoteDriveCapacityMb", - "summalyProxy", - "enableEmail", - "email", - "smtpSecure", - "smtpHost", - "smtpPort", - "smtpUser", - "smtpPass", - "enableServiceWorker", - "swPublicKey", - "swPrivateKey", - "pinnedUsers", - "tosUrl", - "repositoryUrl" - FROM - "meta" - "#, - ) - .fetch_one(&mut conn) - .await?; - - let ( - feedback_url, - use_object_storage, - object_storage_bucket, - object_storage_prefix, - object_storage_base_url, - object_storage_endpoint, - object_storage_region, - object_storage_access_key, - object_storage_secret_key, - object_storage_port, - object_storage_use_ssl, - object_storage_set_public_read, - object_storage_s3_force_path_style, - object_storage_use_proxy, - proxy_account_id, - ): ( - Option, - bool, - Option, - Option, - Option, - Option, - Option, - Option, - Option, - Option, - bool, - bool, - bool, - bool, - Option, - ) = sqlx::query_as( - r#" - SELECT - "feedbackUrl", - "useObjectStorage", - "objectStorageBucket", - "objectStoragePrefix", - "objectStorageBaseUrl", - "objectStorageEndpoint", - "objectStorageRegion", - "objectStorageAccessKey", - "objectStorageSecretKey", - "objectStoragePort", - "objectStorageUseSsl", - "objectStorageSetPublicRead", - "objectStorageS3ForcePathStyle", - "objectStorageUseProxy", - "proxyAccountId" - FROM - "meta" - "#, - ) - .fetch_one(&mut conn) - .await?; - - let ( - enable_hcaptcha, - hcaptcha_site_key, - hcaptcha_secret_key, - background_image_url, - logo_image_url, - pinned_clip_id, - allowed_hosts, - secure_mode, - private_mode, - deepl_auth_key, - deepl_is_pro, - email_required_for_signup, - theme_color, - default_light_theme, - default_dark_theme, - ): ( - bool, - Option, - Option, - Option, - Option, - Option, - Vec, - bool, - bool, - Option, - bool, - bool, - Option, - Option, - Option, - ) = sqlx::query_as( - r#" - SELECT - "enableHcaptcha", - "hcaptchaSiteKey", - "hcaptchaSecretKey", - "backgroundImageUrl", - "logoImageUrl", - "pinnedClipId", - "allowedHosts", - "secureMode", - "privateMode", - "deeplAuthKey", - "deeplIsPro", - "emailRequiredForSignup", - "themeColor", - "defaultLightTheme", - "defaultDarkTheme" - FROM - "meta" - "#, - ) - .fetch_one(&mut conn) - .await?; - - let ( - enable_ip_logging, - enable_active_email_validation, - custom_motd, - custom_splash_icons, - disable_recommended_timeline, - recommended_instances, - enable_guest_timeline, - default_reaction, - libre_translate_api_url, - libre_translate_api_key, - enable_server_machine_stats, - enable_identicon_generation, - donation_link, - mark_local_files_nsfw_by_default, - antenna_limit, - ): ( - bool, - bool, - Vec, - Vec, - bool, - Vec, - bool, - String, - Option, - Option, - bool, - bool, - Option, - bool, - i32, - ) = sqlx::query_as( - r#" - SELECT - "enableIpLogging", - "enableActiveEmailValidation", - "customMotd", - "customSplashIcons", - "disableRecommendedTimeline", - "recommendedInstances", - "enableGuestTimeline", - "defaultReaction", - "libreTranslateApiUrl", - "libreTranslateApiKey", - "enableServerMachineStats", - "enableIdenticonGeneration", - "donationLink", - "markLocalFilesNsfwByDefault", - "antennaLimit" - FROM - "meta" - "#, - ) - .fetch_one(&mut conn) - .await?; - - Ok(Meta { - name, - description, - maintainer_name, - maintainer_email, - disable_registration, - disable_local_timeline, - disable_global_timeline, - banner_url, - error_image_url, - icon_url, - cache_remote_files, - enable_recaptcha, - recaptcha_site_key, - recaptcha_secret_key, - local_drive_capacity_mb, - remote_drive_capacity_mb, - summaly_proxy, - enable_email, - email, - smtp_secure, - smtp_host, - smtp_port, - smtp_user, - smtp_pass, - enable_service_worker, - sw_public_key, - sw_private_key, - pinned_users, - tos_url, - repository_url, - feedback_url, - use_object_storage, - object_storage_bucket, - object_storage_prefix, - object_storage_base_url, - object_storage_endpoint, - object_storage_region, - object_storage_access_key, - object_storage_secret_key, - object_storage_port, - object_storage_use_ssl, - object_storage_set_public_read, - object_storage_s3_force_path_style, - object_storage_use_proxy, - proxy_account_id, - enable_hcaptcha, - hcaptcha_site_key, - hcaptcha_secret_key, - background_image_url, - logo_image_url, - pinned_clip_id, - allowed_hosts, - secure_mode, - private_mode, - deepl_auth_key, - deepl_is_pro, - email_required_for_signup, - theme_color, - default_light_theme, - default_dark_theme, - enable_ip_logging, - enable_active_email_validation, - custom_motd, - custom_splash_icons, - disable_recommended_timeline, - recommended_instances, - enable_guest_timeline, - default_reaction, - libre_translate_api_url, - libre_translate_api_key, - enable_server_machine_stats, - enable_identicon_generation, - donation_link, - mark_local_files_nsfw_by_default, - antenna_limit, - }) + Ok(meta) } pub(super) async fn run() -> Result<(), Error> {