From b03a2d79958fce477936f83b95734e4e087c9345 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 19 Jul 2020 12:26:23 -0400 Subject: [PATCH 1/3] Ran cargo fmt. --- server/src/apub/activities.rs | 8 ++++++-- server/src/apub/comment.rs | 17 +++++++++++++---- server/src/apub/community.rs | 19 ++++++++++++++----- server/src/apub/community_inbox.rs | 3 ++- server/src/apub/fetcher.rs | 7 +++++-- server/src/apub/mod.rs | 3 ++- server/src/apub/post.rs | 14 +++++++++++--- server/src/apub/private_message.rs | 13 ++++++++++--- server/src/apub/shared_inbox.rs | 18 +++++++++++++----- server/src/apub/user.rs | 12 +++++++++--- server/src/apub/user_inbox.rs | 9 ++++++--- 11 files changed, 91 insertions(+), 32 deletions(-) diff --git a/server/src/apub/activities.rs b/server/src/apub/activities.rs index a436d30fc..a14e6ec37 100644 --- a/server/src/apub/activities.rs +++ b/server/src/apub/activities.rs @@ -1,10 +1,14 @@ use crate::{ apub::{ - community::do_announce, extensions::signatures::sign, insert_activity, is_apub_id_valid, + community::do_announce, + extensions::signatures::sign, + insert_activity, + is_apub_id_valid, ActorType, }, request::retry_custom, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_new::base::AnyBase; use actix_web::client::Client; diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index 2a0840150..774abba6b 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -1,16 +1,25 @@ use crate::{ apub::{ activities::send_activity_to_community, - create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url, + create_apub_response, + create_apub_tombstone_response, + create_tombstone, + fetch_webfinger_url, fetcher::{ - get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post, + get_or_fetch_and_insert_remote_comment, + get_or_fetch_and_insert_remote_post, get_or_fetch_and_upsert_remote_user, }, - ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub, + ActorType, + ApubLikeableType, + ApubObjectType, + FromApub, + ToApub, }, blocking, routes::DbPoolParam, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_new::{ activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index 0df2f3fd1..f84e6508d 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -1,13 +1,22 @@ use crate::{ apub::{ - activities::send_activity, create_apub_response, create_apub_tombstone_response, - create_tombstone, extensions::group_extensions::GroupExtension, - fetcher::get_or_fetch_and_upsert_remote_user, get_shared_inbox, insert_activity, ActorType, - FromApub, GroupExt, ToApub, + activities::send_activity, + create_apub_response, + create_apub_tombstone_response, + create_tombstone, + extensions::group_extensions::GroupExtension, + fetcher::get_or_fetch_and_upsert_remote_user, + get_shared_inbox, + insert_activity, + ActorType, + FromApub, + GroupExt, + ToApub, }, blocking, routes::DbPoolParam, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_ext::Ext2; use activitystreams_new::{ diff --git a/server/src/apub/community_inbox.rs b/server/src/apub/community_inbox.rs index 44a1c949d..3b8236749 100644 --- a/server/src/apub/community_inbox.rs +++ b/server/src/apub/community_inbox.rs @@ -2,7 +2,8 @@ use crate::{ apub::{ extensions::signatures::verify, fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, - insert_activity, ActorType, + insert_activity, + ActorType, }, blocking, routes::{ChatServerParam, DbPoolParam}, diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index 8779486ba..d224b7cd0 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -4,7 +4,8 @@ use crate::{ blocking, request::{retry, RecvError}, routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_new::{base::BaseExt, object::Note, prelude::*}; use actix_web::client::Client; @@ -20,7 +21,9 @@ use lemmy_db::{ post_view::PostView, user::{UserForm, User_}, user_view::UserView, - Crud, Joinable, SearchType, + Crud, + Joinable, + SearchType, }; use lemmy_utils::get_apub_protocol_string; use log::debug; diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 3f61dc926..4e65d9e72 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -19,7 +19,8 @@ use crate::{ blocking, request::{retry, RecvError}, routes::webfinger::WebFingerResponse, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_ext::{Ext1, Ext2}; use activitystreams_new::{ diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index 039afe86c..dc4ae2499 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -1,14 +1,22 @@ use crate::{ apub::{ activities::send_activity_to_community, - create_apub_response, create_apub_tombstone_response, create_tombstone, + create_apub_response, + create_apub_tombstone_response, + create_tombstone, extensions::page_extension::PageExtension, fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, - ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub, + ActorType, + ApubLikeableType, + ApubObjectType, + FromApub, + PageExt, + ToApub, }, blocking, routes::DbPoolParam, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_ext::Ext1; use activitystreams_new::{ diff --git a/server/src/apub/private_message.rs b/server/src/apub/private_message.rs index 17d5c09c0..94cadeec2 100644 --- a/server/src/apub/private_message.rs +++ b/server/src/apub/private_message.rs @@ -1,9 +1,16 @@ use crate::{ apub::{ - activities::send_activity, create_tombstone, fetcher::get_or_fetch_and_upsert_remote_user, - insert_activity, ApubObjectType, FromApub, ToApub, + activities::send_activity, + create_tombstone, + fetcher::get_or_fetch_and_upsert_remote_user, + insert_activity, + ApubObjectType, + FromApub, + ToApub, }, - blocking, DbPool, LemmyError, + blocking, + DbPool, + LemmyError, }; use activitystreams_new::{ activity::{Create, Delete, Undo, Update}, diff --git a/server/src/apub/shared_inbox.rs b/server/src/apub/shared_inbox.rs index 708cc0b25..8d6b255d3 100644 --- a/server/src/apub/shared_inbox.rs +++ b/server/src/apub/shared_inbox.rs @@ -8,10 +8,16 @@ use crate::{ community::do_announce, extensions::signatures::verify, fetcher::{ - get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post, - get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user, + get_or_fetch_and_insert_remote_comment, + get_or_fetch_and_insert_remote_post, + get_or_fetch_and_upsert_remote_community, + get_or_fetch_and_upsert_remote_user, }, - insert_activity, ActorType, FromApub, GroupExt, PageExt, + insert_activity, + ActorType, + FromApub, + GroupExt, + PageExt, }, blocking, routes::{ChatServerParam, DbPoolParam}, @@ -19,7 +25,8 @@ use crate::{ server::{SendComment, SendCommunityRoomMessage, SendPost}, UserOperation, }, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_new::{ activity::{ActorAndObjectRef, Announce, Create, Delete, Dislike, Like, Remove, Undo, Update}, @@ -38,7 +45,8 @@ use lemmy_db::{ post::{Post, PostForm, PostLike, PostLikeForm}, post_view::PostView, user::User_, - Crud, Likeable, + Crud, + Likeable, }; use lemmy_utils::scrape_text_for_mentions; use log::debug; diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 4ebfe77b7..2a98670ce 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -1,12 +1,18 @@ use crate::{ api::claims::Claims, apub::{ - activities::send_activity, create_apub_response, insert_activity, ActorType, FromApub, - PersonExt, ToApub, + activities::send_activity, + create_apub_response, + insert_activity, + ActorType, + FromApub, + PersonExt, + ToApub, }, blocking, routes::DbPoolParam, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_ext::Ext1; use activitystreams_new::{ diff --git a/server/src/apub/user_inbox.rs b/server/src/apub/user_inbox.rs index 73916ee2c..7b589b28c 100644 --- a/server/src/apub/user_inbox.rs +++ b/server/src/apub/user_inbox.rs @@ -3,12 +3,14 @@ use crate::{ apub::{ extensions::signatures::verify, fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, - insert_activity, FromApub, + insert_activity, + FromApub, }, blocking, routes::{ChatServerParam, DbPoolParam}, websocket::{server::SendUserRoomMessage, UserOperation}, - DbPool, LemmyError, + DbPool, + LemmyError, }; use activitystreams_new::{ activity::{Accept, Create, Delete, Undo, Update}, @@ -22,7 +24,8 @@ use lemmy_db::{ private_message::{PrivateMessage, PrivateMessageForm}, private_message_view::PrivateMessageView, user::User_, - Crud, Followable, + Crud, + Followable, }; use log::debug; use serde::Deserialize; From 87202b491504b188cfb0a57cfd1a95de05296e77 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 19 Jul 2020 13:12:42 -0400 Subject: [PATCH 2/3] Fixing duplicate actor_id for community and user. Fixes #957 --- server/lemmy_db/src/activity.rs | 2 +- server/lemmy_db/src/comment.rs | 4 +- server/lemmy_db/src/comment_view.rs | 4 +- server/lemmy_db/src/community.rs | 6 +-- server/lemmy_db/src/moderator.rs | 6 +-- server/lemmy_db/src/password_reset_request.rs | 2 +- server/lemmy_db/src/post.rs | 4 +- server/lemmy_db/src/post_view.rs | 4 +- server/lemmy_db/src/private_message.rs | 4 +- server/lemmy_db/src/user.rs | 4 +- server/lemmy_db/src/user_mention.rs | 6 +-- .../down.sql | 20 ++++++++ .../up.sql | 48 +++++++++++++++++++ server/src/code_migrations.rs | 4 +- 14 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/down.sql create mode 100644 server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql diff --git a/server/lemmy_db/src/activity.rs b/server/lemmy_db/src/activity.rs index 83f85ca1e..557eb9e9e 100644 --- a/server/lemmy_db/src/activity.rs +++ b/server/lemmy_db/src/activity.rs @@ -117,7 +117,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_862362".into(), bio: None, local: true, private_key: None, diff --git a/server/lemmy_db/src/comment.rs b/server/lemmy_db/src/comment.rs index acdddcc34..dc369c8bc 100644 --- a/server/lemmy_db/src/comment.rs +++ b/server/lemmy_db/src/comment.rs @@ -233,7 +233,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_283687".into(), bio: None, local: true, private_key: None, @@ -253,7 +253,7 @@ mod tests { deleted: None, updated: None, nsfw: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_928738972".into(), local: true, private_key: None, public_key: None, diff --git a/server/lemmy_db/src/comment_view.rs b/server/lemmy_db/src/comment_view.rs index 4af13c2d9..7f99ba4ad 100644 --- a/server/lemmy_db/src/comment_view.rs +++ b/server/lemmy_db/src/comment_view.rs @@ -498,7 +498,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_92873982".into(), bio: None, local: true, private_key: None, @@ -518,7 +518,7 @@ mod tests { deleted: None, updated: None, nsfw: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_7625376".into(), local: true, private_key: None, public_key: None, diff --git a/server/lemmy_db/src/community.rs b/server/lemmy_db/src/community.rs index ef91eb849..e1f243919 100644 --- a/server/lemmy_db/src/community.rs +++ b/server/lemmy_db/src/community.rs @@ -258,7 +258,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_8266238".into(), bio: None, local: true, private_key: None, @@ -278,7 +278,7 @@ mod tests { removed: None, deleted: None, updated: None, - actor_id: "http://fake.com".into(), + actor_id: "changeme_7625376".into(), local: true, private_key: None, public_key: None, @@ -300,7 +300,7 @@ mod tests { deleted: false, published: inserted_community.published, updated: None, - actor_id: "http://fake.com".into(), + actor_id: inserted_community.actor_id.to_owned(), local: true, private_key: None, public_key: None, diff --git a/server/lemmy_db/src/moderator.rs b/server/lemmy_db/src/moderator.rs index f5d33d967..0992197b1 100644 --- a/server/lemmy_db/src/moderator.rs +++ b/server/lemmy_db/src/moderator.rs @@ -470,7 +470,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_829398".into(), bio: None, local: true, private_key: None, @@ -497,7 +497,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_82982738".into(), bio: None, local: true, private_key: None, @@ -517,7 +517,7 @@ mod tests { deleted: None, updated: None, nsfw: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_283687".into(), local: true, private_key: None, public_key: None, diff --git a/server/lemmy_db/src/password_reset_request.rs b/server/lemmy_db/src/password_reset_request.rs index a2692add8..2529ba67a 100644 --- a/server/lemmy_db/src/password_reset_request.rs +++ b/server/lemmy_db/src/password_reset_request.rs @@ -105,7 +105,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_8292378".into(), bio: None, local: true, private_key: None, diff --git a/server/lemmy_db/src/post.rs b/server/lemmy_db/src/post.rs index 12cf927e8..66e24773a 100644 --- a/server/lemmy_db/src/post.rs +++ b/server/lemmy_db/src/post.rs @@ -279,7 +279,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_8292683678".into(), bio: None, local: true, private_key: None, @@ -299,7 +299,7 @@ mod tests { deleted: None, updated: None, nsfw: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_8223262378".into(), local: true, private_key: None, public_key: None, diff --git a/server/lemmy_db/src/post_view.rs b/server/lemmy_db/src/post_view.rs index 3e9f87376..ffc8afebd 100644 --- a/server/lemmy_db/src/post_view.rs +++ b/server/lemmy_db/src/post_view.rs @@ -415,7 +415,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_8282738268".into(), bio: None, local: true, private_key: None, @@ -435,7 +435,7 @@ mod tests { deleted: None, updated: None, nsfw: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_2763".into(), local: true, private_key: None, public_key: None, diff --git a/server/lemmy_db/src/private_message.rs b/server/lemmy_db/src/private_message.rs index 1c0b455f3..3492be2fc 100644 --- a/server/lemmy_db/src/private_message.rs +++ b/server/lemmy_db/src/private_message.rs @@ -113,7 +113,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_6723878".into(), bio: None, local: true, private_key: None, @@ -140,7 +140,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_287263876".into(), bio: None, local: true, private_key: None, diff --git a/server/lemmy_db/src/user.rs b/server/lemmy_db/src/user.rs index 556fc1a75..718067f99 100644 --- a/server/lemmy_db/src/user.rs +++ b/server/lemmy_db/src/user.rs @@ -166,7 +166,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_9826382637".into(), bio: None, local: true, private_key: None, @@ -195,7 +195,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: inserted_user.actor_id.to_owned(), bio: None, local: true, private_key: None, diff --git a/server/lemmy_db/src/user_mention.rs b/server/lemmy_db/src/user_mention.rs index 9f23f4410..5dc899b29 100644 --- a/server/lemmy_db/src/user_mention.rs +++ b/server/lemmy_db/src/user_mention.rs @@ -86,7 +86,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_628763".into(), bio: None, local: true, private_key: None, @@ -113,7 +113,7 @@ mod tests { lang: "browser".into(), show_avatars: true, send_notifications_to_email: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_927389278".into(), bio: None, local: true, private_key: None, @@ -133,7 +133,7 @@ mod tests { deleted: None, updated: None, nsfw: false, - actor_id: "http://fake.com".into(), + actor_id: "changeme_876238".into(), local: true, private_key: None, public_key: None, diff --git a/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/down.sql b/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/down.sql new file mode 100644 index 000000000..7a4f2e2f1 --- /dev/null +++ b/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/down.sql @@ -0,0 +1,20 @@ + +alter table community alter column actor_id set not null; +alter table community alter column actor_id set default 'http://fake.com'; +alter table user_ alter column actor_id set not null; +alter table user_ alter column actor_id set default 'http://fake.com'; + +drop function generate_unique_changeme; + +update community +set actor_id = 'http://fake.com' +where actor_id like 'changeme_%'; + +update user_ +set actor_id = 'http://fake.com' +where actor_id like 'changeme_%'; + +drop index idx_user_lower_actor_id; +create unique index idx_user_name_lower_actor_id on user_ (lower(name), lower(actor_id)); + +drop index idx_community_lower_actor_id; diff --git a/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql b/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql new file mode 100644 index 000000000..bbf6b18c6 --- /dev/null +++ b/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql @@ -0,0 +1,48 @@ +-- Following this issue : https://github.com/LemmyNet/lemmy/issues/957 + +-- Creating a unique changeme actor_id +create or replace function generate_unique_changeme() +returns text language sql +as $$ + select 'changeme_' || string_agg (substr('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789', ceil (random() * 62)::integer, 1), '') + from generate_series(1, 20) +$$; + +update community +set actor_id = generate_unique_changeme() +where actor_id = 'http://fake.com'; + +update user_ +set actor_id = generate_unique_changeme() +where actor_id = 'http://fake.com'; + +-- Need to delete the possible community and user dupes for ones that don't start with the fake one +-- TODO make sure this removes the later ids, not the first +delete from community a using ( + select min(id) as id, actor_id + from community + group by actor_id having count(*) > 1 +) b +where a.actor_id = b.actor_id +and a.id <> b.id; + +delete from user_ a using ( + select min(id) as id, actor_id + from user_ + group by actor_id having count(*) > 1 +) b +where a.actor_id = b.actor_id +and a.id <> b.id; + +-- Add the unique indexes +alter table community alter column actor_id set not null; +alter table community alter column actor_id set default generate_unique_changeme(); + +alter table user_ alter column actor_id set not null; +alter table user_ alter column actor_id set default generate_unique_changeme(); + +-- Add lowercase uniqueness too +drop index idx_user_name_lower_actor_id; +create unique index idx_user_lower_actor_id on user_ (lower(actor_id)); + +create unique index idx_community_lower_actor_id on community (lower(actor_id)); diff --git a/server/src/code_migrations.rs b/server/src/code_migrations.rs index b28e120a1..7c85fefcb 100644 --- a/server/src/code_migrations.rs +++ b/server/src/code_migrations.rs @@ -30,7 +30,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { // Update the actor_id, private_key, and public_key, last_refreshed_at let incorrect_users = user_ - .filter(actor_id.eq("http://fake.com")) + .filter(actor_id.like("changeme_%")) .filter(local.eq(true)) .load::(conn)?; @@ -81,7 +81,7 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { // Update the actor_id, private_key, and public_key, last_refreshed_at let incorrect_communities = community - .filter(actor_id.eq("http://fake.com")) + .filter(actor_id.like("changeme_%")) .filter(local.eq(true)) .load::(conn)?; From 2ff7acf207b6c7b78f3c4ac69d9e55b720fe9653 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 19 Jul 2020 13:32:50 -0400 Subject: [PATCH 3/3] Moving dupe checking to before new actor_id generation. --- .../up.sql | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql b/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql index bbf6b18c6..e32ed5e08 100644 --- a/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql +++ b/server/migrations/2020-07-18-234519_add_unique_community_user_actor_ids/up.sql @@ -8,16 +8,9 @@ as $$ from generate_series(1, 20) $$; -update community -set actor_id = generate_unique_changeme() -where actor_id = 'http://fake.com'; - -update user_ -set actor_id = generate_unique_changeme() -where actor_id = 'http://fake.com'; - -- Need to delete the possible community and user dupes for ones that don't start with the fake one --- TODO make sure this removes the later ids, not the first +-- A few test inserts, to make sure this removes later dupes +-- insert into community (name, title, category_id, creator_id) values ('testcom', 'another testcom', 1, 2); delete from community a using ( select min(id) as id, actor_id from community @@ -34,6 +27,15 @@ delete from user_ a using ( where a.actor_id = b.actor_id and a.id <> b.id; +-- Replacing the current default on the columns, to the unique one +update community +set actor_id = generate_unique_changeme() +where actor_id = 'http://fake.com'; + +update user_ +set actor_id = generate_unique_changeme() +where actor_id = 'http://fake.com'; + -- Add the unique indexes alter table community alter column actor_id set not null; alter table community alter column actor_id set default generate_unique_changeme();