feat: bump k-ap to v0.1.9 and implement migrate_follower_actor
This commit is contained in:
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.8" }
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" }
|
||||
domain = { workspace = true }
|
||||
url = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.8" }
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" }
|
||||
sqlx = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
|
||||
@@ -490,6 +490,41 @@ impl FederationRepository for PostgresFederationRepository {
|
||||
).bind(local_user_id).bind(actor_url).fetch_one(&self.pool).await.map_err(|e| anyhow!(e))?;
|
||||
Ok(n > 0)
|
||||
}
|
||||
|
||||
async fn migrate_follower_actor(
|
||||
&self,
|
||||
old_actor_url: &str,
|
||||
new_actor_url: &str,
|
||||
) -> Result<Vec<uuid::Uuid>> {
|
||||
let mut tx = self.pool.begin().await.map_err(|e| anyhow!(e))?;
|
||||
|
||||
// Copy rows to the new actor URL, carrying over existing data.
|
||||
// ON CONFLICT DO NOTHING skips users already following the new actor.
|
||||
// RETURNING gives us user IDs that actually need a re-follow.
|
||||
let affected: Vec<uuid::Uuid> = sqlx::query_scalar(
|
||||
"INSERT INTO federation_following(local_user_id, remote_actor_url, follow_activity_id, outbox_url)
|
||||
SELECT local_user_id, $2, follow_activity_id, outbox_url
|
||||
FROM federation_following
|
||||
WHERE remote_actor_url = $1
|
||||
ON CONFLICT (local_user_id, remote_actor_url) DO NOTHING
|
||||
RETURNING local_user_id",
|
||||
)
|
||||
.bind(old_actor_url)
|
||||
.bind(new_actor_url)
|
||||
.fetch_all(&mut *tx)
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
|
||||
// Delete the old rows.
|
||||
sqlx::query("DELETE FROM federation_following WHERE remote_actor_url = $1")
|
||||
.bind(old_actor_url)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
|
||||
tx.commit().await.map_err(|e| anyhow!(e))?;
|
||||
Ok(affected)
|
||||
}
|
||||
}
|
||||
|
||||
// ── PostgresApUserRepository ──────────────────────────────────────────────────
|
||||
|
||||
@@ -14,7 +14,7 @@ postgres = { workspace = true }
|
||||
postgres-search = { workspace = true }
|
||||
postgres-federation = { workspace = true }
|
||||
activitypub = { workspace = true }
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.8" }
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" }
|
||||
nats = { workspace = true }
|
||||
event-transport = { workspace = true }
|
||||
auth = { workspace = true }
|
||||
|
||||
@@ -13,7 +13,7 @@ application = { workspace = true }
|
||||
nats = { workspace = true }
|
||||
event-transport = { workspace = true }
|
||||
event-payload = { workspace = true }
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.8" }
|
||||
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" }
|
||||
activitypub = { workspace = true }
|
||||
postgres = { workspace = true }
|
||||
postgres-federation = { workspace = true }
|
||||
|
||||
Reference in New Issue
Block a user