From 66e3eb834369e54cc810df8b52e662d2f0be9710 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 13 Sep 2024 11:23:26 +0200 Subject: [PATCH] Remove TypedBuilder in favor of derive_new (fixes #4863) --- Cargo.lock | 21 --- Cargo.toml | 1 - .../site/registration_applications/tests.rs | 21 +-- crates/api_crud/src/comment/create.rs | 9 +- crates/api_crud/src/community/create.rs | 34 ++--- crates/api_crud/src/custom_emoji/create.rs | 20 ++- crates/api_crud/src/custom_emoji/update.rs | 18 ++- crates/api_crud/src/post/create.rs | 20 +-- crates/api_crud/src/private_message/create.rs | 10 +- crates/apub/src/api/user_settings_backup.rs | 22 ++-- crates/apub/src/http/community.rs | 27 ++-- crates/apub/src/objects/community.rs | 43 +++--- crates/apub/src/objects/post.rs | 26 ++-- crates/db_perf/src/main.rs | 11 +- crates/db_schema/Cargo.toml | 1 - .../src/aggregates/comment_aggregates.rs | 46 +++---- .../src/aggregates/community_aggregates.rs | 59 ++++----- .../src/aggregates/person_aggregates.rs | 46 +++---- .../src/aggregates/post_aggregates.rs | 80 ++++++----- .../src/aggregates/site_aggregates.rs | 49 ++++--- crates/db_schema/src/impls/actor_language.rs | 31 ++--- crates/db_schema/src/impls/comment.rs | 46 +++---- crates/db_schema/src/impls/community.rs | 13 +- crates/db_schema/src/impls/instance.rs | 6 +- crates/db_schema/src/impls/local_user.rs | 4 +- crates/db_schema/src/impls/moderator.rs | 34 +++-- crates/db_schema/src/impls/post.rs | 33 +++-- crates/db_schema/src/impls/post_report.rs | 18 +-- crates/db_schema/src/impls/private_message.rs | 10 +- crates/db_schema/src/source/comment.rs | 15 ++- crates/db_schema/src/source/community.rs | 31 +++-- crates/db_schema/src/source/custom_emoji.rs | 5 +- .../src/source/custom_emoji_keyword.rs | 3 +- crates/db_schema/src/source/image_upload.rs | 3 +- crates/db_schema/src/source/instance.rs | 8 +- crates/db_schema/src/source/local_site.rs | 27 +++- .../src/source/local_site_rate_limit.rs | 19 ++- .../source/local_user_vote_display_mode.rs | 9 +- crates/db_schema/src/source/post.rs | 26 +++- .../db_schema/src/source/private_message.rs | 13 +- crates/db_schema/src/source/site.rs | 19 ++- crates/db_views/src/comment_report_view.rs | 34 +++-- crates/db_views/src/comment_view.rs | 97 +++++++------- crates/db_views/src/post_report_view.rs | 35 +++-- crates/db_views/src/post_view.rs | 124 ++++++++---------- .../src/private_message_report_view.rs | 10 +- crates/db_views/src/private_message_view.rs | 28 ++-- crates/db_views/src/vote_view.rs | 35 +++-- .../db_views_actor/src/comment_reply_view.rs | 32 ++--- crates/db_views_actor/src/community_view.rs | 13 +- .../db_views_actor/src/person_mention_view.rs | 35 +++-- crates/federate/src/lib.rs | 6 +- crates/federate/src/worker.rs | 11 +- src/code_migrations.rs | 56 ++++---- src/scheduled_tasks.rs | 6 +- 55 files changed, 690 insertions(+), 769 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1658ff0e38..0bec1dcef4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3000,7 +3000,6 @@ dependencies = [ "tokio-postgres-rustls", "tracing", "ts-rs", - "typed-builder", "url", "uuid", ] @@ -6315,26 +6314,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "typed-builder" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06fbd5b8de54c5f7c91f6fe4cebb949be2125d7758e630bb58b1d831dbce600" -dependencies = [ - "typed-builder-macro", -] - -[[package]] -name = "typed-builder-macro" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9534daa9fd3ed0bd911d462a37f172228077e7abf18c18a5f67199d959205f8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "typenum" version = "1.17.0" diff --git a/Cargo.toml b/Cargo.toml index 272691bc78..9d2871d37c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,7 +132,6 @@ anyhow = { version = "1.0.86", features = [ "backtrace", ] } # backtrace is on by default on nightly, but not stable rust diesel_ltree = "0.3.1" -typed-builder = "0.19.1" serial_test = "3.1.1" tokio = { version = "1.39.2", features = ["full"] } regex = "1.10.5" diff --git a/crates/api/src/site/registration_applications/tests.rs b/crates/api/src/site/registration_applications/tests.rs index 062fa550f8..b41f355e92 100644 --- a/crates/api/src/site/registration_applications/tests.rs +++ b/crates/api/src/site/registration_applications/tests.rs @@ -58,28 +58,21 @@ async fn create_test_site(context: &Data) -> LemmyResult<(Instance .await? .unwrap(); - let site_form = SiteInsertForm::builder() - .name("test site".to_string()) - .instance_id(inserted_instance.id) - .build(); + let site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id); let site = Site::create(pool, &site_form).await.unwrap(); // Create a local site, since this is necessary for determining if email verification is // required - let local_site_form = LocalSiteInsertForm::builder() - .site_id(site.id) - .require_email_verification(Some(true)) - .application_question(Some(".".to_string())) - .registration_mode(Some(RegistrationMode::RequireApplication)) - .site_setup(Some(true)) - .build(); + let mut local_site_form = LocalSiteInsertForm::new(site.id); + local_site_form.require_email_verification = Some(true); + local_site_form.application_question = Some(".".to_string()); + local_site_form.registration_mode = Some(RegistrationMode::RequireApplication); + local_site_form.site_setup = Some(true); let local_site = LocalSite::create(pool, &local_site_form).await.unwrap(); // Required to have a working local SiteView when updating the site to change email verification // requirement or registration mode - let rate_limit_form = LocalSiteRateLimitInsertForm::builder() - .local_site_id(local_site.id) - .build(); + let rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id); LocalSiteRateLimit::create(pool, &rate_limit_form) .await .unwrap(); diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 49de9d5de4..be3f981075 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -111,12 +111,9 @@ pub async fn create_comment( } }; - let comment_form = CommentInsertForm::builder() - .content(content.clone()) - .post_id(data.post_id) - .creator_id(local_user_view.person.id) - .language_id(language_id) - .build(); + let mut comment_form = + CommentInsertForm::new(local_user_view.person.id, data.post_id, content.clone()); + comment_form.language_id = language_id; // Create the comment let parent_path = parent_opt.clone().map(|t| t.path); diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index 4289b7d244..332f0e21b5 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -90,23 +90,23 @@ pub async fn create_community( // When you create a community, make sure the user becomes a moderator and a follower let keypair = generate_actor_keypair()?; - let community_form = CommunityInsertForm::builder() - .name(data.name.clone()) - .title(data.title.clone()) - .description(description) - .icon(icon) - .banner(banner) - .nsfw(data.nsfw) - .actor_id(Some(community_actor_id.clone())) - .private_key(Some(keypair.private_key)) - .public_key(keypair.public_key) - .followers_url(Some(generate_followers_url(&community_actor_id)?)) - .inbox_url(Some(generate_inbox_url(&community_actor_id)?)) - .shared_inbox_url(Some(generate_shared_inbox_url(context.settings())?)) - .posting_restricted_to_mods(data.posting_restricted_to_mods) - .instance_id(site_view.site.instance_id) - .visibility(data.visibility) - .build(); + let mut community_form = CommunityInsertForm::new( + site_view.site.instance_id, + data.name.clone(), + data.title.clone(), + keypair.private_key, + ); + community_form.description = description; + community_form.icon = icon; + community_form.banner = banner; + community_form.nsfw = data.nsfw; + community_form.actor_id = Some(community_actor_id.clone()); + community_form.public_key = keypair.public_key; + community_form.followers_url = Some(generate_followers_url(&community_actor_id)?); + community_form.inbox_url = Some(generate_inbox_url(&community_actor_id)?); + community_form.shared_inbox_url = Some(generate_shared_inbox_url(context.settings())?); + community_form.posting_restricted_to_mods = data.posting_restricted_to_mods; + community_form.visibility = data.visibility; let inserted_community = Community::create(&mut context.pool(), &community_form) .await diff --git a/crates/api_crud/src/custom_emoji/create.rs b/crates/api_crud/src/custom_emoji/create.rs index 3c5ce32961..4c7af52999 100644 --- a/crates/api_crud/src/custom_emoji/create.rs +++ b/crates/api_crud/src/custom_emoji/create.rs @@ -23,20 +23,18 @@ pub async fn create_custom_emoji( // Make sure user is an admin is_admin(&local_user_view)?; - let emoji_form = CustomEmojiInsertForm::builder() - .local_site_id(local_site.id) - .shortcode(data.shortcode.to_lowercase().trim().to_string()) - .alt_text(data.alt_text.to_string()) - .category(data.category.to_string()) - .image_url(data.clone().image_url.into()) - .build(); + let emoji_form = CustomEmojiInsertForm::new( + local_site.id, + data.shortcode.to_lowercase().trim().to_string(), + data.clone().image_url.into(), + data.alt_text.to_string(), + data.category.to_string(), + ); let emoji = CustomEmoji::create(&mut context.pool(), &emoji_form).await?; let mut keywords = vec![]; for keyword in &data.keywords { - let keyword_form = CustomEmojiKeywordInsertForm::builder() - .custom_emoji_id(emoji.id) - .keyword(keyword.to_lowercase().trim().to_string()) - .build(); + let keyword_form = + CustomEmojiKeywordInsertForm::new(emoji.id, keyword.to_lowercase().trim().to_string()); keywords.push(keyword_form); } CustomEmojiKeyword::create(&mut context.pool(), keywords).await?; diff --git a/crates/api_crud/src/custom_emoji/update.rs b/crates/api_crud/src/custom_emoji/update.rs index 63246f85da..c87976621b 100644 --- a/crates/api_crud/src/custom_emoji/update.rs +++ b/crates/api_crud/src/custom_emoji/update.rs @@ -23,20 +23,18 @@ pub async fn update_custom_emoji( // Make sure user is an admin is_admin(&local_user_view)?; - let emoji_form = CustomEmojiUpdateForm::builder() - .local_site_id(local_site.id) - .alt_text(data.alt_text.to_string()) - .category(data.category.to_string()) - .image_url(data.clone().image_url.into()) - .build(); + let emoji_form = CustomEmojiUpdateForm::new( + local_site.id, + data.clone().image_url.into(), + data.alt_text.to_string(), + data.category.to_string(), + ); let emoji = CustomEmoji::update(&mut context.pool(), data.id, &emoji_form).await?; CustomEmojiKeyword::delete(&mut context.pool(), data.id).await?; let mut keywords = vec![]; for keyword in &data.keywords { - let keyword_form = CustomEmojiKeywordInsertForm::builder() - .custom_emoji_id(emoji.id) - .keyword(keyword.to_lowercase().trim().to_string()) - .build(); + let keyword_form = + CustomEmojiKeywordInsertForm::new(emoji.id, keyword.to_lowercase().trim().to_string()); keywords.push(keyword_form); } CustomEmojiKeyword::create(&mut context.pool(), keywords).await?; diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index a0f0b75259..4c709fa4dd 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -130,16 +130,16 @@ pub async fn create_post( } }; - let post_form = PostInsertForm::builder() - .name(data.name.trim().to_string()) - .url(url.map(Into::into)) - .body(body) - .alt_text(data.alt_text.clone()) - .community_id(data.community_id) - .creator_id(local_user_view.person.id) - .nsfw(data.nsfw) - .language_id(language_id) - .build(); + let mut post_form = PostInsertForm::new( + data.name.trim().to_string(), + local_user_view.person.id, + data.community_id, + ); + post_form.url = url.map(Into::into); + post_form.body = body; + post_form.alt_text = data.alt_text.clone(); + post_form.nsfw = data.nsfw; + post_form.language_id = language_id; let inserted_post = Post::create(&mut context.pool(), &post_form) .await diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index 46908da6e9..d8fe1bbfcf 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -46,11 +46,11 @@ pub async fn create_private_message( ) .await?; - let private_message_form = PrivateMessageInsertForm::builder() - .content(content.clone()) - .creator_id(local_user_view.person.id) - .recipient_id(data.recipient_id) - .build(); + let private_message_form = PrivateMessageInsertForm::new( + local_user_view.person.id, + data.recipient_id, + content.clone(), + ); let inserted_private_message = PrivateMessage::create(&mut context.pool(), &private_message_form) .await diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index fdf8dc2ad8..c1ab9dbadb 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -362,11 +362,12 @@ mod tests { let export_user = create_user("hanna".to_string(), Some("my bio".to_string()), &context).await?; - let community_form = CommunityInsertForm::builder() - .name("testcom".to_string()) - .title("testcom".to_string()) - .instance_id(export_user.person.instance_id) - .build(); + let community_form = CommunityInsertForm::new( + export_user.person.instance_id, + "testcom".to_string(), + "testcom".to_string(), + "pubkey".to_string(), + ); let community = Community::create(&mut context.pool(), &community_form).await?; let follower_form = CommunityFollowerForm { community_id: community.id, @@ -412,11 +413,12 @@ mod tests { let export_user = create_user("hanna".to_string(), Some("my bio".to_string()), &context).await?; - let community_form = CommunityInsertForm::builder() - .name("testcom".to_string()) - .title("testcom".to_string()) - .instance_id(export_user.person.instance_id) - .build(); + let community_form = CommunityInsertForm::new( + export_user.person.instance_id, + "testcom".to_string(), + "testcom".to_string(), + "pubkey".to_string(), + ); let community = Community::create(&mut context.pool(), &community_form).await?; let follower_form = CommunityFollowerForm { community_id: community.id, diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index 0f6ee57cb3..38b96df30e 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -151,14 +151,14 @@ pub(crate) mod tests { Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?; create_local_site(context, instance.id).await?; - let community_form = CommunityInsertForm::builder() - .name("testcom6".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(instance.id) - .deleted(Some(deleted)) - .visibility(Some(visibility)) - .build(); + let mut community_form = CommunityInsertForm::new( + instance.id, + "testcom6".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); + community_form.deleted = Some(deleted); + community_form.visibility = Some(visibility); let community = Community::create(&mut context.pool(), &community_form).await?; Ok((instance, community)) } @@ -169,18 +169,13 @@ pub(crate) mod tests { instance_id: InstanceId, ) -> LemmyResult<()> { // Create a local site, since this is necessary for community fetching. - let site_form = SiteInsertForm::builder() - .name("test site".to_string()) - .instance_id(instance_id) - .build(); + let site_form = SiteInsertForm::new("test site".to_string(), instance_id); let site = Site::create(&mut context.pool(), &site_form).await?; - let local_site_form = LocalSiteInsertForm::builder().site_id(site.id).build(); + let local_site_form = LocalSiteInsertForm::new(site.id); let local_site = LocalSite::create(&mut context.pool(), &local_site_form).await?; - let local_site_rate_limit_form = LocalSiteRateLimitInsertForm::builder() - .local_site_id(local_site.id) - .build(); + let local_site_rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id); LocalSiteRateLimit::create(&mut context.pool(), &local_site_rate_limit_form).await?; Ok(()) } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 93c2c83ae1..f2cca00df0 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -151,29 +151,28 @@ impl Object for ApubCommunity { let icon = proxy_image_link_opt_apub(group.icon.map(|i| i.url), context).await?; let banner = proxy_image_link_opt_apub(group.image.map(|i| i.url), context).await?; - let form = CommunityInsertForm { - name: group.preferred_username.clone(), - title: group.name.unwrap_or(group.preferred_username.clone()), - description, - published: group.published, - updated: group.updated, - deleted: Some(false), - nsfw: Some(group.sensitive.unwrap_or(false)), - actor_id: Some(group.id.into()), - local: Some(false), - public_key: group.public_key.public_key_pem, - last_refreshed_at: Some(naive_now()), - icon, - banner, - followers_url: group.followers.clone().map(Into::into), - inbox_url: Some(group.inbox.into()), - shared_inbox_url: group.endpoints.map(|e| e.shared_inbox.into()), - moderators_url: group.attributed_to.clone().map(Into::into), - posting_restricted_to_mods: group.posting_restricted_to_mods, + let mut form = CommunityInsertForm::new( instance_id, - featured_url: group.featured.clone().map(Into::into), - ..Default::default() - }; + group.preferred_username.clone(), + group.name.unwrap_or(group.preferred_username.clone()), + group.public_key.public_key_pem, + ); + form.published = group.published; + form.updated = group.updated; + form.deleted = Some(false); + form.nsfw = Some(group.sensitive.unwrap_or(false)); + form.actor_id = Some(group.id.into()); + form.local = Some(false); + form.last_refreshed_at = Some(naive_now()); + form.icon = icon; + form.banner = banner; + form.description = description; + form.followers_url = group.followers.clone().map(Into::into); + form.inbox_url = Some(group.inbox.into()); + form.shared_inbox_url = group.endpoints.map(|e| e.shared_inbox.into()); + form.moderators_url = group.attributed_to.clone().map(Into::into); + form.posting_restricted_to_mods = group.posting_restricted_to_mods; + form.featured_url = group.featured.clone().map(Into::into); let languages = LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?; diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 44e8424133..fbd6c5afee 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -247,21 +247,17 @@ impl Object for ApubPost { let language_id = LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?; - let form = PostInsertForm::builder() - .name(name) - .url(url.map(Into::into)) - .body(body) - .alt_text(alt_text) - .creator_id(creator.id) - .community_id(community.id) - .published(page.published.map(Into::into)) - .updated(page.updated.map(Into::into)) - .deleted(Some(false)) - .nsfw(page.sensitive) - .ap_id(Some(page.id.clone().into())) - .local(Some(false)) - .language_id(language_id) - .build(); + let mut form = PostInsertForm::new(name, creator.id, community.id); + form.url = url.map(Into::into); + form.body = body; + form.alt_text = alt_text; + form.published = page.published.map(Into::into); + form.updated = page.updated.map(Into::into); + form.deleted = Some(false); + form.nsfw = page.sensitive; + form.ap_id = Some(page.id.clone().into()); + form.local = Some(false); + form.language_id = language_id; let timestamp = page.updated.or(page.published).unwrap_or_else(naive_now); let post = Post::insert_apub(&mut context.pool(), timestamp, &form).await?; diff --git a/crates/db_perf/src/main.rs b/crates/db_perf/src/main.rs index 8e03a0a1dd..dd67d30366 100644 --- a/crates/db_perf/src/main.rs +++ b/crates/db_perf/src/main.rs @@ -79,11 +79,12 @@ async fn try_main() -> LemmyResult<()> { println!("🌍 creating {} communities", args.communities); let mut community_ids = vec![]; for i in 0..args.communities.get() { - let form = CommunityInsertForm::builder() - .name(format!("c{i}")) - .title(i.to_string()) - .instance_id(instance.id) - .build(); + let form = CommunityInsertForm::new( + instance.id, + format!("c{i}"), + i.to_string(), + "pubkey".to_string(), + ); community_ids.push(Community::create(&mut conn.into(), &form).await?.id); } diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 57af68f469..aeaa55c931 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -64,7 +64,6 @@ diesel-async = { workspace = true, features = [ ], optional = true } regex = { workspace = true, optional = true } diesel_ltree = { workspace = true, optional = true } -typed-builder = { workspace = true } async-trait = { workspace = true } tracing = { workspace = true } deadpool = { version = "0.12.1", features = ["rt_tokio_1"], optional = true } diff --git a/crates/db_schema/src/aggregates/comment_aggregates.rs b/crates/db_schema/src/aggregates/comment_aggregates.rs index 92b24beb5f..a928f26847 100644 --- a/crates/db_schema/src/aggregates/comment_aggregates.rs +++ b/crates/db_schema/src/aggregates/comment_aggregates.rs @@ -72,37 +72,33 @@ mod tests { let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("TIL_comment_agg".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_comment_agg".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); - let child_comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let child_comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let _inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)) .await diff --git a/crates/db_schema/src/aggregates/community_aggregates.rs b/crates/db_schema/src/aggregates/community_aggregates.rs index fe9de62bbb..1e52052f6d 100644 --- a/crates/db_schema/src/aggregates/community_aggregates.rs +++ b/crates/db_schema/src/aggregates/community_aggregates.rs @@ -73,22 +73,20 @@ mod tests { let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("TIL_community_agg".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_community_agg".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let another_community = CommunityInsertForm::builder() - .name("TIL_community_agg_2".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let another_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_community_agg_2".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let another_inserted_community = Community::create(pool, &another_community).await.unwrap(); let first_person_follow = CommunityFollowerForm { @@ -121,28 +119,25 @@ mod tests { .await .unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); - let child_comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let child_comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let _inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)) .await diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index a8767895c1..337af5ef3c 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -57,21 +57,20 @@ mod tests { let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("TIL_site_agg".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_site_agg".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); let post_like = PostLikeForm { @@ -79,15 +78,13 @@ mod tests { person_id: inserted_person.id, score: 1, }; - let _inserted_post_like = PostLike::like(pool, &post_like).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); let mut comment_like = CommentLikeForm { @@ -99,12 +96,11 @@ mod tests { let _inserted_comment_like = CommentLike::like(pool, &comment_like).await.unwrap(); - let child_comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let child_comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)) .await diff --git a/crates/db_schema/src/aggregates/post_aggregates.rs b/crates/db_schema/src/aggregates/post_aggregates.rs index eba3a02a3b..fe6ced04b1 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -91,37 +91,33 @@ mod tests { let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("TIL_community_agg".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_community_agg".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); - let child_comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let child_comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)) .await @@ -225,28 +221,26 @@ mod tests { let inserted_person = Person::create(pool, &new_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("TIL_community_agg".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_community_agg".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); diff --git a/crates/db_schema/src/aggregates/site_aggregates.rs b/crates/db_schema/src/aggregates/site_aggregates.rs index ee9a1be9cf..81d6b559d3 100644 --- a/crates/db_schema/src/aggregates/site_aggregates.rs +++ b/crates/db_schema/src/aggregates/site_aggregates.rs @@ -46,19 +46,15 @@ mod tests { let inserted_person = Person::create(pool, &new_person).await.unwrap(); - let site_form = SiteInsertForm::builder() - .name("test_site".into()) - .instance_id(inserted_instance.id) - .build(); - + let site_form = SiteInsertForm::new("test_site".into(), inserted_instance.id); let inserted_site = Site::create(pool, &site_form).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("TIL_site_agg".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL_site_agg".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); ( @@ -78,31 +74,30 @@ mod tests { let (inserted_instance, inserted_person, inserted_site, inserted_community) = prepare_site_with_community(pool).await; - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); // Insert two of those posts let inserted_post = Post::create(pool, &new_post).await.unwrap(); let _inserted_post_again = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); // Insert two of those comments let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); - let child_comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let child_comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let _inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)) .await diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 5a8658baf5..958c5b1e66 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -446,14 +446,11 @@ mod tests { .await .unwrap(); - let site_form = SiteInsertForm::builder() - .name("test site".to_string()) - .instance_id(inserted_instance.id) - .build(); + let site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id); let site = Site::create(pool, &site_form).await.unwrap(); // Create a local site, since this is necessary for local languages - let local_site_form = LocalSiteInsertForm::builder().site_id(site.id).build(); + let local_site_form = LocalSiteInsertForm::new(site.id); LocalSite::create(pool, &local_site_form).await.unwrap(); (site, inserted_instance) @@ -576,12 +573,12 @@ mod tests { let read_local_site_langs = SiteLanguage::read_local_raw(pool).await.unwrap(); assert_eq!(test_langs, read_local_site_langs); - let community_form = CommunityInsertForm::builder() - .name("test community".to_string()) - .title("test community".to_string()) - .public_key("pubkey".to_string()) - .instance_id(instance.id) - .build(); + let community_form = CommunityInsertForm::new( + instance.id, + "test community".to_string(), + "test community".to_string(), + "pubkey".to_string(), + ); let community = Community::create(pool, &community_form).await.unwrap(); let community_langs1 = CommunityLanguage::read(pool, community.id).await.unwrap(); @@ -629,12 +626,12 @@ mod tests { let test_langs = test_langs1(pool).await; let test_langs2 = test_langs2(pool).await; - let community_form = CommunityInsertForm::builder() - .name("test community".to_string()) - .title("test community".to_string()) - .public_key("pubkey".to_string()) - .instance_id(instance.id) - .build(); + let community_form = CommunityInsertForm::new( + instance.id, + "test community".to_string(), + "test community".to_string(), + "pubkey".to_string(), + ); let community = Community::create(pool, &community_form).await.unwrap(); CommunityLanguage::update(pool, test_langs, community.id) .await diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 977bc9083f..44151cfbb6 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -239,29 +239,26 @@ mod tests { let inserted_person = Person::create(pool, &new_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("test community".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); let expected_comment = Comment { @@ -285,12 +282,11 @@ mod tests { language_id: LanguageId::default(), }; - let child_comment_form = CommentInsertForm::builder() - .content("A child comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let child_comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A child comment".into(), + ); let inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)) .await diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index eaf35a90d6..a79a23f479 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -473,13 +473,12 @@ mod tests { let artemis_person = PersonInsertForm::test_form(inserted_instance.id, "artemis"); let inserted_artemis = Person::create(pool, &artemis_person).await?; - let new_community = CommunityInsertForm::builder() - .name("TIL".into()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "TIL".into(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await?; let expected_community = Community { diff --git a/crates/db_schema/src/impls/instance.rs b/crates/db_schema/src/impls/instance.rs index 94bf909a31..95985269c0 100644 --- a/crates/db_schema/src/impls/instance.rs +++ b/crates/db_schema/src/impls/instance.rs @@ -51,10 +51,8 @@ impl Instance { Some(i) => Ok(i), None => { // Instance not in database yet, insert it - let form = InstanceForm::builder() - .domain(domain_) - .updated(Some(naive_now())) - .build(); + let mut form = InstanceForm::new(domain_); + form.updated = Some(naive_now()); insert_into(instance::table) .values(&form) // Necessary because this method may be called concurrently for the same domain. This diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index acff6af2a4..29a8d16719 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -47,9 +47,7 @@ impl LocalUser { LocalUserLanguage::update(pool, languages, local_user_.id).await?; // Create their vote_display_modes - let vote_display_mode_form = LocalUserVoteDisplayModeInsertForm::builder() - .local_user_id(local_user_.id) - .build(); + let vote_display_mode_form = LocalUserVoteDisplayModeInsertForm::new(local_user_.id); LocalUserVoteDisplayMode::create(pool, &vote_display_mode_form).await?; Ok(local_user_) diff --git a/crates/db_schema/src/impls/moderator.rs b/crates/db_schema/src/impls/moderator.rs index c10d818f8c..fdee8537bd 100644 --- a/crates/db_schema/src/impls/moderator.rs +++ b/crates/db_schema/src/impls/moderator.rs @@ -521,29 +521,27 @@ mod tests { let inserted_person = Person::create(pool, &new_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("mod_community".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "mod_community".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post thweep".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post thweep".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); // Now the actual tests diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 8e14bee9f1..0fd567c53c 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -406,28 +406,27 @@ mod tests { let inserted_person = Person::create(pool, &new_person).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("test community_3".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community_3".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let new_post2 = PostInsertForm::builder() - .name("A test post 2".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); + let new_post2 = PostInsertForm::new( + "A test post 2".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post2 = Post::create(pool, &new_post2).await.unwrap(); let expected_post = Post { diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index 7218ef4685..ccb2f83fb0 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -104,19 +104,15 @@ mod tests { let person_form = PersonInsertForm::test_form(inserted_instance.id, "jim"); let person = Person::create(pool, &person_form).await.unwrap(); - let community_form = CommunityInsertForm::builder() - .name("test community_4".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); + let community_form = CommunityInsertForm::new( + inserted_instance.id, + "test community_4".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let community = Community::create(pool, &community_form).await.unwrap(); - let form = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(person.id) - .community_id(community.id) - .build(); + let form = PostInsertForm::new("A test post".into(), person.id, community.id); let post = Post::create(pool, &form).await.unwrap(); let report_form = PostReportForm { diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index fe3629a1a6..c11882b14c 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -120,11 +120,11 @@ mod tests { let inserted_recipient = Person::create(pool, &recipient_form).await.unwrap(); - let private_message_form = PrivateMessageInsertForm::builder() - .content("A test private message".into()) - .creator_id(inserted_creator.id) - .recipient_id(inserted_recipient.id) - .build(); + let private_message_form = PrivateMessageInsertForm::new( + inserted_creator.id, + inserted_recipient.id, + "A test private message".into(), + ); let inserted_private_message = PrivateMessage::create(pool, &private_message_form) .await diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index 74ae0b7f6e..e7d031c682 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -10,7 +10,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -51,24 +50,28 @@ pub struct Comment { pub language_id: LanguageId, } -#[derive(Debug, Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Debug, Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = comment))] pub struct CommentInsertForm { - #[builder(!default)] pub creator_id: PersonId, - #[builder(!default)] pub post_id: PostId, - #[builder(!default)] pub content: String, + #[new(default)] pub removed: Option, + #[new(default)] pub published: Option>, + #[new(default)] pub updated: Option>, + #[new(default)] pub deleted: Option, + #[new(default)] pub ap_id: Option, + #[new(default)] pub local: Option, + #[new(default)] pub distinguished: Option, + #[new(default)] pub language_id: Option, } diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index fe7f120ec1..ced85bf4c0 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -71,37 +70,53 @@ pub struct Community { pub visibility: CommunityVisibility, } -#[derive(Debug, Clone, TypedBuilder, Default)] -#[builder(field_defaults(default))] +#[derive(Debug, Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = community))] pub struct CommunityInsertForm { - #[builder(!default)] + pub instance_id: InstanceId, pub name: String, - #[builder(!default)] pub title: String, + pub public_key: String, + #[new(default)] pub description: Option, + #[new(default)] pub removed: Option, + #[new(default)] pub published: Option>, + #[new(default)] pub updated: Option>, + #[new(default)] pub deleted: Option, + #[new(default)] pub nsfw: Option, + #[new(default)] pub actor_id: Option, + #[new(default)] pub local: Option, + #[new(default)] pub private_key: Option, - pub public_key: String, + #[new(default)] pub last_refreshed_at: Option>, + #[new(default)] pub icon: Option, + #[new(default)] pub banner: Option, + #[new(default)] pub followers_url: Option, + #[new(default)] pub inbox_url: Option, + #[new(default)] pub shared_inbox_url: Option, + #[new(default)] pub moderators_url: Option, + #[new(default)] pub featured_url: Option, + #[new(default)] pub hidden: Option, + #[new(default)] pub posting_restricted_to_mods: Option, - #[builder(!default)] - pub instance_id: InstanceId, + #[new(default)] pub visibility: Option, } diff --git a/crates/db_schema/src/source/custom_emoji.rs b/crates/db_schema/src/source/custom_emoji.rs index 3217c9736b..25c2049a29 100644 --- a/crates/db_schema/src/source/custom_emoji.rs +++ b/crates/db_schema/src/source/custom_emoji.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] @@ -33,7 +32,7 @@ pub struct CustomEmoji { pub updated: Option>, } -#[derive(Debug, Clone, TypedBuilder)] +#[derive(Debug, Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = custom_emoji))] pub struct CustomEmojiInsertForm { @@ -44,7 +43,7 @@ pub struct CustomEmojiInsertForm { pub category: String, } -#[derive(Debug, Clone, TypedBuilder)] +#[derive(Debug, Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = custom_emoji))] pub struct CustomEmojiUpdateForm { diff --git a/crates/db_schema/src/source/custom_emoji_keyword.rs b/crates/db_schema/src/source/custom_emoji_keyword.rs index 34ee071b52..a47ba411e3 100644 --- a/crates/db_schema/src/source/custom_emoji_keyword.rs +++ b/crates/db_schema/src/source/custom_emoji_keyword.rs @@ -4,7 +4,6 @@ use crate::schema::custom_emoji_keyword; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] #[cfg_attr( @@ -25,7 +24,7 @@ pub struct CustomEmojiKeyword { pub keyword: String, } -#[derive(Debug, Clone, TypedBuilder)] +#[derive(Debug, Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = custom_emoji_keyword))] pub struct CustomEmojiKeywordInsertForm { diff --git a/crates/db_schema/src/source/image_upload.rs b/crates/db_schema/src/source/image_upload.rs index b72c550655..db840dc1d3 100644 --- a/crates/db_schema/src/source/image_upload.rs +++ b/crates/db_schema/src/source/image_upload.rs @@ -7,7 +7,6 @@ use serde_with::skip_serializing_none; use std::fmt::Debug; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] @@ -30,7 +29,7 @@ pub struct ImageUpload { pub published: DateTime, } -#[derive(Debug, Clone, TypedBuilder)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = image_upload))] pub struct ImageUploadForm { diff --git a/crates/db_schema/src/source/instance.rs b/crates/db_schema/src/source/instance.rs index 98e0d401bf..8c27a2cb69 100644 --- a/crates/db_schema/src/source/instance.rs +++ b/crates/db_schema/src/source/instance.rs @@ -7,7 +7,6 @@ use serde_with::skip_serializing_none; use std::fmt::Debug; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -25,14 +24,15 @@ pub struct Instance { pub version: Option, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = instance))] pub struct InstanceForm { - #[builder(!default)] pub domain: String, + #[new(default)] pub software: Option, + #[new(default)] pub version: Option, + #[new(default)] pub updated: Option>, } diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index 05583c0653..03d14853e7 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Default)] @@ -72,34 +71,54 @@ pub struct LocalSite { pub default_sort_type: SortType, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable))] #[cfg_attr(feature = "full", diesel(table_name = local_site))] pub struct LocalSiteInsertForm { - #[builder(!default)] pub site_id: SiteId, + #[new(default)] pub site_setup: Option, + #[new(default)] pub enable_downvotes: Option, + #[new(default)] pub enable_nsfw: Option, + #[new(default)] pub community_creation_admin_only: Option, + #[new(default)] pub require_email_verification: Option, + #[new(default)] pub application_question: Option, + #[new(default)] pub private_instance: Option, + #[new(default)] pub default_theme: Option, + #[new(default)] pub default_post_listing_type: Option, + #[new(default)] pub legal_information: Option, + #[new(default)] pub hide_modlog_mod_names: Option, + #[new(default)] pub application_email_admins: Option, + #[new(default)] pub slur_filter_regex: Option, + #[new(default)] pub actor_name_max_length: Option, + #[new(default)] pub federation_enabled: Option, + #[new(default)] pub captcha_enabled: Option, + #[new(default)] pub captcha_difficulty: Option, + #[new(default)] pub registration_mode: Option, + #[new(default)] pub reports_email_admins: Option, + #[new(default)] pub federation_signed_fetch: Option, + #[new(default)] pub default_post_listing_mode: Option, + #[new(default)] pub default_sort_type: Option, } diff --git a/crates/db_schema/src/source/local_site_rate_limit.rs b/crates/db_schema/src/source/local_site_rate_limit.rs index 6ba3df59ec..f7f25f5c1a 100644 --- a/crates/db_schema/src/source/local_site_rate_limit.rs +++ b/crates/db_schema/src/source/local_site_rate_limit.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] @@ -40,26 +39,38 @@ pub struct LocalSiteRateLimit { pub import_user_settings_per_second: i32, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable))] #[cfg_attr(feature = "full", diesel(table_name = local_site_rate_limit))] pub struct LocalSiteRateLimitInsertForm { - #[builder(!default)] pub local_site_id: LocalSiteId, + #[new(default)] pub message: Option, + #[new(default)] pub message_per_second: Option, + #[new(default)] pub post: Option, + #[new(default)] pub post_per_second: Option, + #[new(default)] pub register: Option, + #[new(default)] pub register_per_second: Option, + #[new(default)] pub image: Option, + #[new(default)] pub image_per_second: Option, + #[new(default)] pub comment: Option, + #[new(default)] pub comment_per_second: Option, + #[new(default)] pub search: Option, + #[new(default)] pub search_per_second: Option, + #[new(default)] pub import_user_settings: Option, + #[new(default)] pub import_user_settings_per_second: Option, } diff --git a/crates/db_schema/src/source/local_user_vote_display_mode.rs b/crates/db_schema/src/source/local_user_vote_display_mode.rs index 8c6ad95eb7..06a4330346 100644 --- a/crates/db_schema/src/source/local_user_vote_display_mode.rs +++ b/crates/db_schema/src/source/local_user_vote_display_mode.rs @@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)] @@ -28,16 +27,18 @@ pub struct LocalUserVoteDisplayMode { pub upvote_percentage: bool, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable))] #[cfg_attr(feature = "full", diesel(table_name = local_user_vote_display_mode))] pub struct LocalUserVoteDisplayModeInsertForm { - #[builder(!default)] pub local_user_id: LocalUserId, + #[new(default)] pub score: Option, + #[new(default)] pub upvotes: Option, + #[new(default)] pub downvotes: Option, + #[new(default)] pub upvote_percentage: Option, } diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index 541d9c3076..bf719f54f4 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -60,35 +59,50 @@ pub struct Post { pub alt_text: Option, } -#[derive(Debug, Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Debug, Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = post))] pub struct PostInsertForm { - #[builder(!default)] pub name: String, - #[builder(!default)] pub creator_id: PersonId, - #[builder(!default)] pub community_id: CommunityId, + #[new(default)] pub nsfw: Option, + #[new(default)] pub url: Option, + #[new(default)] pub body: Option, + #[new(default)] pub removed: Option, + #[new(default)] pub locked: Option, + #[new(default)] pub updated: Option>, + #[new(default)] pub published: Option>, + #[new(default)] pub deleted: Option, + #[new(default)] pub embed_title: Option, + #[new(default)] pub embed_description: Option, + #[new(default)] pub embed_video_url: Option, + #[new(default)] pub thumbnail_url: Option, + #[new(default)] pub ap_id: Option, + #[new(default)] pub local: Option, + #[new(default)] pub language_id: Option, + #[new(default)] pub featured_community: Option, + #[new(default)] pub featured_local: Option, + #[new(default)] pub url_content_type: Option, + #[new(default)] pub alt_text: Option, } diff --git a/crates/db_schema/src/source/private_message.rs b/crates/db_schema/src/source/private_message.rs index 94a6009214..8afaa14f14 100644 --- a/crates/db_schema/src/source/private_message.rs +++ b/crates/db_schema/src/source/private_message.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -35,22 +34,24 @@ pub struct PrivateMessage { pub local: bool, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = private_message))] pub struct PrivateMessageInsertForm { - #[builder(!default)] pub creator_id: PersonId, - #[builder(!default)] pub recipient_id: PersonId, - #[builder(!default)] pub content: String, + #[new(default)] pub deleted: Option, + #[new(default)] pub read: Option, + #[new(default)] pub published: Option>, + #[new(default)] pub updated: Option>, + #[new(default)] pub ap_id: Option, + #[new(default)] pub local: Option, } diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index 325bff97c7..0ec4043e47 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -9,7 +9,6 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use ts_rs::TS; -use typed_builder::TypedBuilder; #[skip_serializing_none] #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] @@ -47,25 +46,33 @@ pub struct Site { pub content_warning: Option, } -#[derive(Clone, TypedBuilder)] -#[builder(field_defaults(default))] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = site))] pub struct SiteInsertForm { - #[builder(!default)] pub name: String, + pub instance_id: InstanceId, + #[new(default)] pub sidebar: Option, + #[new(default)] pub updated: Option>, + #[new(default)] pub icon: Option, + #[new(default)] pub banner: Option, + #[new(default)] pub description: Option, + #[new(default)] pub actor_id: Option, + #[new(default)] pub last_refreshed_at: Option>, + #[new(default)] pub inbox_url: Option, + #[new(default)] pub private_key: Option, + #[new(default)] pub public_key: Option, - #[builder(!default)] - pub instance_id: InstanceId, + #[new(default)] pub content_warning: Option, } diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 1866aaee9a..c140196b0e 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -321,13 +321,12 @@ mod tests { let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("test community crv".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community crv".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); // Make timmy a mod @@ -340,20 +339,19 @@ mod tests { .await .unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post crv".into()) - .creator_id(inserted_timmy.id) - .community_id(inserted_community.id) - .build(); + let new_post = PostInsertForm::new( + "A test post crv".into(), + inserted_timmy.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment 32".into()) - .creator_id(inserted_timmy.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_timmy.id, + inserted_post.id, + "A test comment 32".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); // sara reports diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index e2752a0c71..ca1d8828c2 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -491,21 +491,19 @@ mod tests { let sara_person_form = PersonInsertForm::test_form(inserted_instance.id, "sara"); let inserted_sara_person = Person::create(pool, &sara_person_form).await?; - let new_community = CommunityInsertForm::builder() - .name("test community 5".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community 5".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await?; - let new_post = PostInsertForm::builder() - .name("A test post 2".into()) - .creator_id(inserted_timmy_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post 2".into(), + inserted_timmy_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await?; let english_id = Language::read_id_from_code(pool, Some("en")).await?; @@ -517,65 +515,62 @@ mod tests { // 3 4 // \ // 5 - let comment_form_0 = CommentInsertForm::builder() - .content("Comment 0".into()) - .creator_id(inserted_timmy_person.id) - .post_id(inserted_post.id) - .language_id(english_id) - .build(); + let mut comment_form_0 = CommentInsertForm::new( + inserted_timmy_person.id, + inserted_post.id, + "Comment 0".into(), + ); + comment_form_0.language_id = english_id; let inserted_comment_0 = Comment::create(pool, &comment_form_0, None).await?; - let comment_form_1 = CommentInsertForm::builder() - .content("Comment 1, A test blocked comment".into()) - .creator_id(inserted_sara_person.id) - .post_id(inserted_post.id) - .language_id(english_id) - .build(); - + let mut comment_form_1 = CommentInsertForm::new( + inserted_sara_person.id, + inserted_post.id, + "Comment 1, A test blocked comment".into(), + ); + comment_form_1.language_id = english_id; let inserted_comment_1 = Comment::create(pool, &comment_form_1, Some(&inserted_comment_0.path)).await?; let finnish_id = Language::read_id_from_code(pool, Some("fi")).await?; - let comment_form_2 = CommentInsertForm::builder() - .content("Comment 2".into()) - .creator_id(inserted_timmy_person.id) - .post_id(inserted_post.id) - .language_id(finnish_id) - .build(); + let mut comment_form_2 = CommentInsertForm::new( + inserted_timmy_person.id, + inserted_post.id, + "Comment 2".into(), + ); + comment_form_2.language_id = finnish_id; let inserted_comment_2 = Comment::create(pool, &comment_form_2, Some(&inserted_comment_0.path)).await?; - let comment_form_3 = CommentInsertForm::builder() - .content("Comment 3".into()) - .creator_id(inserted_timmy_person.id) - .post_id(inserted_post.id) - .language_id(english_id) - .build(); - + let mut comment_form_3 = CommentInsertForm::new( + inserted_timmy_person.id, + inserted_post.id, + "Comment 3".into(), + ); + comment_form_3.language_id = english_id; let _inserted_comment_3 = Comment::create(pool, &comment_form_3, Some(&inserted_comment_1.path)).await?; let polish_id = Language::read_id_from_code(pool, Some("pl")) .await? .ok_or(LemmyErrorType::LanguageNotAllowed)?; - let comment_form_4 = CommentInsertForm::builder() - .content("Comment 4".into()) - .creator_id(inserted_timmy_person.id) - .post_id(inserted_post.id) - .language_id(Some(polish_id)) - .build(); + let mut comment_form_4 = CommentInsertForm::new( + inserted_timmy_person.id, + inserted_post.id, + "Comment 4".into(), + ); + comment_form_4.language_id = Some(polish_id); let inserted_comment_4 = Comment::create(pool, &comment_form_4, Some(&inserted_comment_1.path)).await?; - let comment_form_5 = CommentInsertForm::builder() - .content("Comment 5".into()) - .creator_id(inserted_timmy_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form_5 = CommentInsertForm::new( + inserted_timmy_person.id, + inserted_post.id, + "Comment 5".into(), + ); let _inserted_comment_5 = Comment::create(pool, &comment_form_5, Some(&inserted_comment_4.path)).await?; diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 0cd06dd4ef..ed72db2c19 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -343,13 +343,12 @@ mod tests { let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("test community prv".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community prv".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); // Make timmy a mod @@ -362,12 +361,11 @@ mod tests { .await .unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post crv".into()) - .creator_id(inserted_timmy.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post crv".into(), + inserted_timmy.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); // sara reports @@ -382,12 +380,11 @@ mod tests { PostReport::report(pool, &sara_report_form).await.unwrap(); - let new_post_2 = PostInsertForm::builder() - .name("A test post crv 2".into()) - .creator_id(inserted_timmy.id) - .community_id(inserted_community.id) - .build(); - + let new_post_2 = PostInsertForm::new( + "A test post crv 2".into(), + inserted_timmy.id, + inserted_community.id, + ); let inserted_post_2 = Post::create(pool, &new_post_2).await.unwrap(); // jessica reports diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 0ec7e0a5d8..79e16e0a87 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -824,13 +824,12 @@ mod tests { let inserted_bot = Person::create(pool, &new_bot).await?; - let new_community = CommunityInsertForm::builder() - .name("test_community_3".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test_community_3".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await?; // Test a person block, make sure the post query doesn't include their post @@ -845,13 +844,12 @@ mod tests { ) .await?; - let post_from_blocked_person = PostInsertForm::builder() - .name(POST_BY_BLOCKED_PERSON.to_string()) - .creator_id(inserted_blocked_person.id) - .community_id(inserted_community.id) - .language_id(Some(LanguageId(1))) - .build(); - + let mut post_from_blocked_person = PostInsertForm::new( + POST_BY_BLOCKED_PERSON.to_string(), + inserted_blocked_person.id, + inserted_community.id, + ); + post_from_blocked_person.language_id = Some(LanguageId(1)); Post::create(pool, &post_from_blocked_person).await?; // block that person @@ -863,22 +861,18 @@ mod tests { PersonBlock::block(pool, &person_block).await?; // A sample post - let new_post = PostInsertForm::builder() - .name(POST.to_string()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .language_id(Some(LanguageId(47))) - .build(); - + let mut new_post = + PostInsertForm::new(POST.to_string(), inserted_person.id, inserted_community.id); + new_post.language_id = Some(LanguageId(47)); let inserted_post = Post::create(pool, &new_post).await?; - let new_bot_post = PostInsertForm::builder() - .name(POST_BY_BOT.to_string()) - .creator_id(inserted_bot.id) - .community_id(inserted_community.id) - .build(); - + let new_bot_post = PostInsertForm::new( + POST_BY_BOT.to_string(), + inserted_bot.id, + inserted_community.id, + ); let inserted_bot_post = Post::create(pool, &new_bot_post).await?; + let local_user_view = LocalUserView { local_user: inserted_local_user, local_user_vote_display_mode: LocalUserVoteDisplayMode::default(), @@ -1210,13 +1204,12 @@ mod tests { .await? .expect("french should exist"); - let post_spanish = PostInsertForm::builder() - .name(EL_POSTO.to_string()) - .creator_id(data.local_user_view.person.id) - .community_id(data.inserted_community.id) - .language_id(Some(spanish_id)) - .build(); - + let mut post_spanish = PostInsertForm::new( + EL_POSTO.to_string(), + data.local_user_view.person.id, + data.inserted_community.id, + ); + post_spanish.language_id = Some(spanish_id); Post::create(pool, &post_spanish).await?; let post_listings_all = data.default_post_query().list(&data.site, pool).await?; @@ -1344,21 +1337,20 @@ mod tests { let blocked_instance = Instance::read_or_create(pool, "another_domain.tld".to_string()).await?; - let community_form = CommunityInsertForm::builder() - .name("test_community_4".to_string()) - .title("none".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(blocked_instance.id) - .build(); + let community_form = CommunityInsertForm::new( + blocked_instance.id, + "test_community_4".to_string(), + "none".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &community_form).await?; - let post_form = PostInsertForm::builder() - .name(POST_FROM_BLOCKED_INSTANCE.to_string()) - .creator_id(data.inserted_bot.id) - .community_id(inserted_community.id) - .language_id(Some(LanguageId(1))) - .build(); - + let mut post_form = PostInsertForm::new( + POST_FROM_BLOCKED_INSTANCE.to_string(), + data.inserted_bot.id, + inserted_community.id, + ); + post_form.language_id = Some(LanguageId(1)); let post_from_blocked_instance = Post::create(pool, &post_form).await?; // no instance block, should return all posts @@ -1401,12 +1393,12 @@ mod tests { let pool = &mut pool.into(); let data = init_data(pool).await?; - let community_form = CommunityInsertForm::builder() - .name("yes".to_string()) - .title("yes".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(data.inserted_instance.id) - .build(); + let community_form = CommunityInsertForm::new( + data.inserted_instance.id, + "yes".to_string(), + "yes".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &community_form).await?; let mut inserted_post_ids = vec![]; @@ -1416,23 +1408,23 @@ mod tests { // and featured for comments in 0..10 { for _ in 0..15 { - let post_form = PostInsertForm::builder() - .name("keep Christ in Christmas".to_owned()) - .creator_id(data.local_user_view.person.id) - .community_id(inserted_community.id) - .featured_local(Some((comments % 2) == 0)) - .featured_community(Some((comments % 2) == 0)) - .published(Some(Utc::now() - Duration::from_secs(comments % 3))) - .build(); + let mut post_form = PostInsertForm::new( + "keep Christ in Christmas".to_owned(), + data.local_user_view.person.id, + inserted_community.id, + ); + post_form.featured_local = Some((comments % 2) == 0); + post_form.featured_community = Some((comments % 2) == 0); + post_form.published = Some(Utc::now() - Duration::from_secs(comments % 3)); let inserted_post = Post::create(pool, &post_form).await?; inserted_post_ids.push(inserted_post.id); for _ in 0..comments { - let comment_form = CommentInsertForm::builder() - .creator_id(data.local_user_view.person.id) - .post_id(inserted_post.id) - .content("yes".to_owned()) - .build(); + let comment_form = CommentInsertForm::new( + data.local_user_view.person.id, + inserted_post.id, + "yes".to_owned(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await?; inserted_comment_ids.push(inserted_comment.id); } diff --git a/crates/db_views/src/private_message_report_view.rs b/crates/db_views/src/private_message_report_view.rs index f5e70fb3e0..5a8c8a8fd0 100644 --- a/crates/db_views/src/private_message_report_view.rs +++ b/crates/db_views/src/private_message_report_view.rs @@ -147,11 +147,11 @@ mod tests { let inserted_jessica = Person::create(pool, &new_person_2).await.unwrap(); // timmy sends private message to jessica - let pm_form = PrivateMessageInsertForm::builder() - .creator_id(inserted_timmy.id) - .recipient_id(inserted_jessica.id) - .content("something offensive".to_string()) - .build(); + let pm_form = PrivateMessageInsertForm::new( + inserted_timmy.id, + inserted_jessica.id, + "something offensive".to_string(), + ); let pm = PrivateMessage::create(pool, &pm_form).await.unwrap(); // jessica reports private message diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index 79224d86fb..9d5f8aba1e 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -221,38 +221,26 @@ mod tests { let jess = Person::create(pool, &jess_form).await.unwrap(); - let sara_timmy_message_form = PrivateMessageInsertForm::builder() - .creator_id(sara.id) - .recipient_id(timmy.id) - .content(message_content.clone()) - .build(); + let sara_timmy_message_form = + PrivateMessageInsertForm::new(sara.id, timmy.id, message_content.clone()); PrivateMessage::create(pool, &sara_timmy_message_form) .await .unwrap(); - let sara_jess_message_form = PrivateMessageInsertForm::builder() - .creator_id(sara.id) - .recipient_id(jess.id) - .content(message_content.clone()) - .build(); + let sara_jess_message_form = + PrivateMessageInsertForm::new(sara.id, jess.id, message_content.clone()); PrivateMessage::create(pool, &sara_jess_message_form) .await .unwrap(); - let timmy_sara_message_form = PrivateMessageInsertForm::builder() - .creator_id(timmy.id) - .recipient_id(sara.id) - .content(message_content.clone()) - .build(); + let timmy_sara_message_form = + PrivateMessageInsertForm::new(timmy.id, sara.id, message_content.clone()); PrivateMessage::create(pool, &timmy_sara_message_form) .await .unwrap(); - let jess_timmy_message_form = PrivateMessageInsertForm::builder() - .creator_id(jess.id) - .recipient_id(timmy.id) - .content(message_content.clone()) - .build(); + let jess_timmy_message_form = + PrivateMessageInsertForm::new(jess.id, timmy.id, message_content.clone()); PrivateMessage::create(pool, &jess_timmy_message_form) .await .unwrap(); diff --git a/crates/db_views/src/vote_view.rs b/crates/db_views/src/vote_view.rs index 5daa072c3b..c97f60e28a 100644 --- a/crates/db_views/src/vote_view.rs +++ b/crates/db_views/src/vote_view.rs @@ -120,29 +120,26 @@ mod tests { let inserted_sara = Person::create(pool, &new_person_2).await.unwrap(); - let new_community = CommunityInsertForm::builder() - .name("test community vv".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community vv".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); - let new_post = PostInsertForm::builder() - .name("A test post vv".into()) - .creator_id(inserted_timmy.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post vv".into(), + inserted_timmy.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await.unwrap(); - let comment_form = CommentInsertForm::builder() - .content("A test comment vv".into()) - .creator_id(inserted_timmy.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_timmy.id, + inserted_post.id, + "A test comment vv".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap(); // Timmy upvotes his own post diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index b1d95e719e..3c5fea4a7f 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -348,29 +348,23 @@ mod tests { let recipient_local_user = LocalUser::create(pool, &LocalUserInsertForm::test_form(recipient_id), vec![]).await?; - let new_community = CommunityInsertForm::builder() - .name("test community lake".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community lake".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await?; - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_terry.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_terry.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await?; - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_terry.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = + CommentInsertForm::new(inserted_terry.id, inserted_post.id, "A test comment".into()); let inserted_comment = Comment::create(pool, &comment_form, None).await?; let comment_reply_form = CommentReplyInsertForm { diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 0e731878a6..70496d575d 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -280,13 +280,12 @@ mod tests { .await .unwrap(); - let new_community = CommunityInsertForm::builder() - .name("test_community_3".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test_community_3".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await.unwrap(); let url = Url::parse("http://example.com").unwrap(); diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index d6fd7363d4..b31610ce4a 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -346,29 +346,26 @@ mod tests { let recipient_local_user = LocalUser::create(pool, &LocalUserInsertForm::test_form(recipient_id), vec![]).await?; - let new_community = CommunityInsertForm::builder() - .name("test community lake".to_string()) - .title("nada".to_owned()) - .public_key("pubkey".to_string()) - .instance_id(inserted_instance.id) - .build(); - + let new_community = CommunityInsertForm::new( + inserted_instance.id, + "test community lake".to_string(), + "nada".to_owned(), + "pubkey".to_string(), + ); let inserted_community = Community::create(pool, &new_community).await?; - let new_post = PostInsertForm::builder() - .name("A test post".into()) - .creator_id(inserted_person.id) - .community_id(inserted_community.id) - .build(); - + let new_post = PostInsertForm::new( + "A test post".into(), + inserted_person.id, + inserted_community.id, + ); let inserted_post = Post::create(pool, &new_post).await?; - let comment_form = CommentInsertForm::builder() - .content("A test comment".into()) - .creator_id(inserted_person.id) - .post_id(inserted_post.id) - .build(); - + let comment_form = CommentInsertForm::new( + inserted_person.id, + inserted_post.id, + "A test comment".into(), + ); let inserted_comment = Comment::create(pool, &comment_form, None).await?; let person_mention_form = PersonMentionInsertForm { diff --git a/crates/federate/src/lib.rs b/crates/federate/src/lib.rs index 66c0a28727..c891ad3002 100644 --- a/crates/federate/src/lib.rs +++ b/crates/federate/src/lib.rs @@ -354,10 +354,8 @@ mod test { let mut data = TestData::init(1, 1).await?; let instance = &data.instances[0]; - let form = InstanceForm::builder() - .domain(instance.domain.clone()) - .updated(DateTime::from_timestamp(0, 0)) - .build(); + let mut form = InstanceForm::new(instance.domain.clone()); + form.updated = DateTime::from_timestamp(0, 0); Instance::update(&mut data.context.pool(), instance.id, form).await?; data.run().await?; diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index 6c83aaa21c..fefe2ec238 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -290,10 +290,8 @@ impl InstanceWorker { if updated.add(Days::new(1)) < Utc::now() { self.instance.updated = Some(Utc::now()); - let form = InstanceForm::builder() - .domain(self.instance.domain.clone()) - .updated(Some(naive_now())) - .build(); + let mut form = InstanceForm::new(self.instance.domain.clone()); + form.updated = Some(naive_now()); Instance::update(&mut self.pool(), self.instance.id, form).await?; } Ok(()) @@ -658,10 +656,7 @@ mod test { #[tokio::test] #[serial] async fn test_update_instance(data: &mut Data) -> LemmyResult<()> { - let form = InstanceForm::builder() - .domain(data.instance.domain.clone()) - .updated(None) - .build(); + let form = InstanceForm::new(data.instance.domain.clone()); Instance::update(&mut data.context.pool(), data.instance.id, form).await?; send_activity(data.person.actor_id.clone(), &data.context, true).await?; diff --git a/src/code_migrations.rs b/src/code_migrations.rs index ae6155bb6c..915b72ec95 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -480,44 +480,36 @@ async fn initialize_local_site_2022_10_10( let site_key_pair = generate_actor_keypair()?; let site_actor_id = Url::parse(&settings.get_protocol_and_hostname())?; - let site_form = SiteInsertForm::builder() - .name( - settings - .setup - .clone() - .map(|s| s.site_name) - .unwrap_or_else(|| "New Site".to_string()), - ) - .instance_id(instance.id) - .actor_id(Some(site_actor_id.clone().into())) - .last_refreshed_at(Some(naive_now())) - .inbox_url(Some(generate_shared_inbox_url(settings)?)) - .private_key(Some(site_key_pair.private_key)) - .public_key(Some(site_key_pair.public_key)) - .build(); + let name = settings + .setup + .clone() + .map(|s| s.site_name) + .unwrap_or_else(|| "New Site".to_string()); + let mut site_form = SiteInsertForm::new(name, instance.id); + site_form.actor_id = Some(site_actor_id.clone().into()); + site_form.last_refreshed_at = Some(naive_now()); + site_form.inbox_url = Some(generate_shared_inbox_url(settings)?); + site_form.private_key = Some(site_key_pair.private_key); + site_form.public_key = Some(site_key_pair.public_key); let site = Site::create(pool, &site_form).await?; // Finally create the local_site row - let local_site_form = LocalSiteInsertForm::builder() - .site_id(site.id) - .site_setup(Some(settings.setup.is_some())) - .build(); + let mut local_site_form = LocalSiteInsertForm::new(site.id); + local_site_form.site_setup = Some(settings.setup.is_some()); let local_site = LocalSite::create(pool, &local_site_form).await?; // Create the rate limit table - let local_site_rate_limit_form = LocalSiteRateLimitInsertForm::builder() - // TODO these have to be set, because the database defaults are too low for the federation - // tests to pass, and there's no way to live update the rate limits without restarting the - // server. - // This can be removed once live rate limits are enabled. - .message(Some(999)) - .post(Some(999)) - .register(Some(999)) - .image(Some(999)) - .comment(Some(999)) - .search(Some(999)) - .local_site_id(local_site.id) - .build(); + let mut local_site_rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id); + // TODO these have to be set, because the database defaults are too low for the federation + // tests to pass, and there's no way to live update the rate limits without restarting the + // server. + // This can be removed once live rate limits are enabled. + local_site_rate_limit_form.message = Some(999); + local_site_rate_limit_form.post = Some(999); + local_site_rate_limit_form.register = Some(999); + local_site_rate_limit_form.image = Some(999); + local_site_rate_limit_form.comment = Some(999); + local_site_rate_limit_form.search = Some(999); LocalSiteRateLimit::create(pool, &local_site_rate_limit_form).await?; Ok(()) diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index ae6187a53a..883c588c61 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -493,10 +493,8 @@ async fn build_update_instance_form( // not every Fediverse instance has a valid Nodeinfo endpoint (its not required for // Activitypub). That's why we always need to mark instances as updated if they are // alive. - let mut instance_form = InstanceForm::builder() - .domain(domain.to_string()) - .updated(Some(naive_now())) - .build(); + let mut instance_form = InstanceForm::new(domain.to_string()); + instance_form.updated = Some(naive_now()); // First, fetch their /.well-known/nodeinfo, then extract the correct nodeinfo link from it let well_known_url = format!("https://{}/.well-known/nodeinfo", domain);