mirror of https://github.com/LemmyNet/lemmy.git
Fixing duplicate actor_id for community and user. Fixes #957
parent
b03a2d7995
commit
87202b4915
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
|
@ -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));
|
|
@ -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::<User_>(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::<Community>(conn)?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue