]> Untitled Git - lemmy.git/blobdiff - src/code_migrations.rs
Speedup CI (#3852)
[lemmy.git] / src / code_migrations.rs
index c69ce591c7aa563d8b6cd7449d9d11a6c2cd70b5..51302524f409f1e7157cb120773c49e5492fe70b 100644 (file)
@@ -39,7 +39,10 @@ use lemmy_utils::{error::LemmyError, settings::structs::Settings};
 use tracing::info;
 use url::Url;
 
-pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Result<(), LemmyError> {
+pub async fn run_advanced_migrations(
+  pool: &mut DbPool<'_>,
+  settings: &Settings,
+) -> Result<(), LemmyError> {
   let protocol_and_hostname = &settings.get_protocol_and_hostname();
   user_updates_2020_04_02(pool, protocol_and_hostname).await?;
   community_updates_2020_04_02(pool, protocol_and_hostname).await?;
@@ -56,7 +59,7 @@ pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Resu
 }
 
 async fn user_updates_2020_04_02(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
@@ -74,16 +77,17 @@ async fn user_updates_2020_04_02(
   for cperson in &incorrect_persons {
     let keypair = generate_actor_keypair()?;
 
-    let form = PersonUpdateForm::builder()
-      .actor_id(Some(generate_local_apub_endpoint(
+    let form = PersonUpdateForm {
+      actor_id: Some(generate_local_apub_endpoint(
         EndpointType::Person,
         &cperson.name,
         protocol_and_hostname,
-      )?))
-      .private_key(Some(Some(keypair.private_key)))
-      .public_key(Some(keypair.public_key))
-      .last_refreshed_at(Some(naive_now()))
-      .build();
+      )?),
+      private_key: Some(Some(keypair.private_key)),
+      public_key: Some(keypair.public_key),
+      last_refreshed_at: Some(naive_now()),
+      ..Default::default()
+    };
 
     Person::update(pool, cperson.id, &form).await?;
   }
@@ -94,7 +98,7 @@ async fn user_updates_2020_04_02(
 }
 
 async fn community_updates_2020_04_02(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
@@ -117,12 +121,13 @@ async fn community_updates_2020_04_02(
       protocol_and_hostname,
     )?;
 
-    let form = CommunityUpdateForm::builder()
-      .actor_id(Some(community_actor_id.clone()))
-      .private_key(Some(Some(keypair.private_key)))
-      .public_key(Some(keypair.public_key))
-      .last_refreshed_at(Some(naive_now()))
-      .build();
+    let form = CommunityUpdateForm {
+      actor_id: Some(community_actor_id.clone()),
+      private_key: Some(Some(keypair.private_key)),
+      public_key: Some(keypair.public_key),
+      last_refreshed_at: Some(naive_now()),
+      ..Default::default()
+    };
 
     Community::update(pool, ccommunity.id, &form).await?;
   }
@@ -133,7 +138,7 @@ async fn community_updates_2020_04_02(
 }
 
 async fn post_updates_2020_04_03(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
@@ -157,7 +162,10 @@ async fn post_updates_2020_04_03(
     Post::update(
       pool,
       cpost.id,
-      &PostUpdateForm::builder().ap_id(Some(apub_id)).build(),
+      &PostUpdateForm {
+        ap_id: Some(apub_id),
+        ..Default::default()
+      },
     )
     .await?;
   }
@@ -168,7 +176,7 @@ async fn post_updates_2020_04_03(
 }
 
 async fn comment_updates_2020_04_03(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
@@ -192,7 +200,10 @@ async fn comment_updates_2020_04_03(
     Comment::update(
       pool,
       ccomment.id,
-      &CommentUpdateForm::builder().ap_id(Some(apub_id)).build(),
+      &CommentUpdateForm {
+        ap_id: Some(apub_id),
+        ..Default::default()
+      },
     )
     .await?;
   }
@@ -203,7 +214,7 @@ async fn comment_updates_2020_04_03(
 }
 
 async fn private_message_updates_2020_05_05(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
@@ -227,9 +238,10 @@ async fn private_message_updates_2020_05_05(
     PrivateMessage::update(
       pool,
       cpm.id,
-      &PrivateMessageUpdateForm::builder()
-        .ap_id(Some(apub_id))
-        .build(),
+      &PrivateMessageUpdateForm {
+        ap_id: Some(apub_id),
+        ..Default::default()
+      },
     )
     .await?;
   }
@@ -240,7 +252,7 @@ async fn private_message_updates_2020_05_05(
 }
 
 async fn post_thumbnail_url_updates_2020_07_27(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
@@ -271,7 +283,7 @@ async fn post_thumbnail_url_updates_2020_07_27(
 
 /// We are setting inbox and follower URLs for local and remote actors alike, because for now
 /// all federated instances are also Lemmy and use the same URL scheme.
-async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> {
+async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>) -> Result<(), LemmyError> {
   let conn = &mut get_conn(pool).await?;
   info!("Running apub_columns_2021_02_02");
   {
@@ -329,7 +341,7 @@ async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> {
 /// Before this point, there is only a single value in the site table which refers to the local
 /// Lemmy instance, so thats all we need to update.
 async fn instance_actor_2022_01_28(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   protocol_and_hostname: &str,
 ) -> Result<(), LemmyError> {
   info!("Running instance_actor_2021_09_29");
@@ -341,13 +353,14 @@ async fn instance_actor_2022_01_28(
     }
     let key_pair = generate_actor_keypair()?;
     let actor_id = Url::parse(protocol_and_hostname)?;
-    let site_form = SiteUpdateForm::builder()
-      .actor_id(Some(actor_id.clone().into()))
-      .last_refreshed_at(Some(naive_now()))
-      .inbox_url(Some(generate_site_inbox_url(&actor_id.into())?))
-      .private_key(Some(Some(key_pair.private_key)))
-      .public_key(Some(key_pair.public_key))
-      .build();
+    let site_form = SiteUpdateForm {
+      actor_id: Some(actor_id.clone().into()),
+      last_refreshed_at: Some(naive_now()),
+      inbox_url: Some(generate_site_inbox_url(&actor_id.into())?),
+      private_key: Some(Some(key_pair.private_key)),
+      public_key: Some(key_pair.public_key),
+      ..Default::default()
+    };
     Site::update(pool, site.id, &site_form).await?;
   }
   Ok(())
@@ -358,7 +371,7 @@ async fn instance_actor_2022_01_28(
 /// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey,
 /// but thats more complicated and has no benefit, as federation is already broken for these actors.
 /// https://github.com/LemmyNet/lemmy/issues/2347
-async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyError> {
+async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> Result<(), LemmyError> {
   let conn = &mut get_conn(pool).await?;
   info!("Running regenerate_public_keys_2022_07_05");
 
@@ -376,11 +389,12 @@ async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyErr
         community_.name
       );
       let key_pair = generate_actor_keypair()?;
-      let form = CommunityUpdateForm::builder()
-        .public_key(Some(key_pair.public_key))
-        .private_key(Some(Some(key_pair.private_key)))
-        .build();
-      Community::update(pool, community_.id, &form).await?;
+      let form = CommunityUpdateForm {
+        public_key: Some(key_pair.public_key),
+        private_key: Some(Some(key_pair.private_key)),
+        ..Default::default()
+      };
+      Community::update(&mut conn.into(), community_.id, &form).await?;
     }
   }
 
@@ -398,10 +412,11 @@ async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyErr
         person_.name
       );
       let key_pair = generate_actor_keypair()?;
-      let form = PersonUpdateForm::builder()
-        .public_key(Some(key_pair.public_key))
-        .private_key(Some(Some(key_pair.private_key)))
-        .build();
+      let form = PersonUpdateForm {
+        public_key: Some(key_pair.public_key),
+        private_key: Some(Some(key_pair.private_key)),
+        ..Default::default()
+      };
       Person::update(pool, person_.id, &form).await?;
     }
   }
@@ -413,7 +428,7 @@ async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyErr
 /// If a site already exists, the DB migration should generate a local_site row.
 /// This will only be run for brand new sites.
 async fn initialize_local_site_2022_10_10(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   settings: &Settings,
 ) -> Result<(), LemmyError> {
   info!("Running initialize_local_site_2022_10_10");