// This is for db migrations that require code
-use activitypub_federation::core::signatures::generate_actor_keypair;
+use activitypub_federation::http_signatures::generate_actor_keypair;
use diesel::{
sql_types::{Nullable, Text},
ExpressionMethods,
TextExpressionMethods,
};
use diesel_async::RunQueryDsl;
-use lemmy_api_common::lemmy_db_views::structs::SiteView;
-use lemmy_apub::{
- generate_followers_url,
- generate_inbox_url,
- generate_local_apub_endpoint,
- generate_shared_inbox_url,
- generate_site_inbox_url,
- EndpointType,
+use lemmy_api_common::{
+ lemmy_db_views::structs::SiteView,
+ utils::{
+ generate_followers_url,
+ generate_inbox_url,
+ generate_local_apub_endpoint,
+ generate_shared_inbox_url,
+ generate_site_inbox_url,
+ EndpointType,
+ },
};
use lemmy_db_schema::{
source::{
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?;
}
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};
}
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};
}
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};
}
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};
}
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};
}
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};
info!("Running post_thumbnail_url_updates_2020_07_27");
- let domain_prefix = format!("{}/pictrs/image/", protocol_and_hostname,);
+ let domain_prefix = format!("{protocol_and_hostname}/pictrs/image/",);
let incorrect_thumbnails = post.filter(thumbnail_url.not_like("http%"));
/// 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");
{
/// 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");
/// 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");
.public_key(Some(key_pair.public_key))
.private_key(Some(Some(key_pair.private_key)))
.build();
- Community::update(pool, community_.id, &form).await?;
+ Community::update(&mut conn.into(), community_.id, &form).await?;
}
}
/// 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");
.expect("must have domain");
// Upsert this to the instance table
- let instance = Instance::create(pool, &domain).await?;
+ let instance = Instance::read_or_create(pool, domain).await?;
if let Some(setup) = &settings.setup {
let person_keypair = generate_actor_keypair()?;