From: Dessalines Date: Sat, 20 Mar 2021 19:21:51 +0000 (-0400) Subject: Moving matrix_user_id to person table. #1438 X-Git-Url: http://these/git/%22https:/image.com/%24%7Bargs.pageFn.jump%20n%7D?a=commitdiff_plain;h=1745b64cebf3599a41599f67d19cea5d53fa3573;p=lemmy.git Moving matrix_user_id to person table. #1438 --- diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 529a13cf..8c6fe8a5 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -543,6 +543,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -550,7 +551,6 @@ mod tests { let local_user_form = LocalUserForm { person_id: inserted_person.id, email: None, - matrix_user_id: None, password_encrypted: "123456".to_string(), admin: None, show_nsfw: None, diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 266d28ee..c43db39c 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -214,6 +214,7 @@ impl Perform for Register { last_refreshed_at: None, inbox_url: Some(generate_inbox_url(&actor_id)?), shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)), + matrix_user_id: None, }; // insert the person @@ -232,7 +233,6 @@ impl Perform for Register { let local_user_form = LocalUserForm { person_id: inserted_person.id, email: Some(data.email.to_owned()), - matrix_user_id: None, password_encrypted: data.password.to_owned(), admin: Some(no_admins), show_nsfw: Some(data.show_nsfw), @@ -477,6 +477,7 @@ impl Perform for SaveUserSettings { public_key: None, last_refreshed_at: None, shared_inbox_url: None, + matrix_user_id, }; let person_res = blocking(context.pool(), move |conn| { @@ -493,7 +494,6 @@ impl Perform for SaveUserSettings { let local_user_form = LocalUserForm { person_id, email, - matrix_user_id, password_encrypted, admin: None, show_nsfw: data.show_nsfw, diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index de45aedd..d1eb6707 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -187,6 +187,7 @@ impl FromApubToForm for PersonForm { last_refreshed_at: Some(naive_now()), inbox_url: Some(person.inner.inbox()?.to_owned().into()), shared_inbox_url: Some(shared_inbox), + matrix_user_id: None, // TODO }) } } diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index c55fef0c..d3e92524 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -59,6 +59,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -80,6 +81,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index bbe751ae..ad90f20f 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -63,6 +63,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -84,6 +85,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/person_aggregates.rs b/crates/db_queries/src/aggregates/person_aggregates.rs index c1082c4b..f6a6cd1b 100644 --- a/crates/db_queries/src/aggregates/person_aggregates.rs +++ b/crates/db_queries/src/aggregates/person_aggregates.rs @@ -59,6 +59,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -80,6 +81,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index aa5e774e..a32b9da6 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -63,6 +63,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -84,6 +85,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index a685ad0d..67cb04a7 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -57,6 +57,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/activity.rs b/crates/db_queries/src/source/activity.rs index 1ec9b8d1..5d345db6 100644 --- a/crates/db_queries/src/source/activity.rs +++ b/crates/db_queries/src/source/activity.rs @@ -153,6 +153,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_creator = Person::create(&conn, &creator_form).unwrap(); diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index 69ac4c08..47965d3b 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -261,6 +261,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/community.rs b/crates/db_queries/src/source/community.rs index 5b7fc92c..a0038c9d 100644 --- a/crates/db_queries/src/source/community.rs +++ b/crates/db_queries/src/source/community.rs @@ -371,6 +371,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/local_user.rs b/crates/db_queries/src/source/local_user.rs index eabd067d..7e84011b 100644 --- a/crates/db_queries/src/source/local_user.rs +++ b/crates/db_queries/src/source/local_user.rs @@ -25,7 +25,6 @@ mod safe_settings_type { lang, show_avatars, send_notifications_to_email, - matrix_user_id, validator_time, ); @@ -46,7 +45,6 @@ mod safe_settings_type { lang, show_avatars, send_notifications_to_email, - matrix_user_id, validator_time, ) } diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index 526fc2bd..3b6d2544 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -224,6 +224,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_mod = Person::create(&conn, &new_mod).unwrap(); @@ -245,6 +246,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/password_reset_request.rs b/crates/db_queries/src/source/password_reset_request.rs index 89c37505..654dabf6 100644 --- a/crates/db_queries/src/source/password_reset_request.rs +++ b/crates/db_queries/src/source/password_reset_request.rs @@ -110,6 +110,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -118,7 +119,6 @@ mod tests { person_id: inserted_person.id, password_encrypted: "pass".to_string(), email: None, - matrix_user_id: None, admin: None, show_nsfw: None, theme: None, diff --git a/crates/db_queries/src/source/person.rs b/crates/db_queries/src/source/person.rs index f9979c97..40adab3d 100644 --- a/crates/db_queries/src/source/person.rs +++ b/crates/db_queries/src/source/person.rs @@ -27,6 +27,7 @@ mod safe_type { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ); impl ToSafe for Person { @@ -47,6 +48,7 @@ mod safe_type { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ) } } @@ -71,6 +73,7 @@ mod safe_type_alias_1 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ); impl ToSafe for PersonAlias1 { @@ -91,6 +94,7 @@ mod safe_type_alias_1 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ) } } @@ -115,6 +119,7 @@ mod safe_type_alias_2 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ); impl ToSafe for PersonAlias2 { @@ -135,6 +140,7 @@ mod safe_type_alias_2 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ) } } @@ -212,16 +218,14 @@ impl Person_ for Person { // Set the local user info to none diesel::update(local_user::table.filter(local_user::person_id.eq(person_id))) - .set(( - local_user::email.eq::>(None), - local_user::matrix_user_id.eq::>(None), - )) + .set((local_user::email.eq::>(None),)) .execute(conn)?; diesel::update(person.find(person_id)) .set(( preferred_username.eq::>(None), bio.eq::>(None), + matrix_user_id.eq::>(None), deleted.eq(true), updated.eq(naive_now()), )) @@ -254,6 +258,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -276,6 +281,7 @@ mod tests { last_refreshed_at: inserted_person.published, inbox_url: inserted_person.inbox_url.to_owned(), shared_inbox_url: None, + matrix_user_id: None, }; let read_person = Person::read(&conn, inserted_person.id).unwrap(); diff --git a/crates/db_queries/src/source/person_mention.rs b/crates/db_queries/src/source/person_mention.rs index dfd626cb..a6a86e78 100644 --- a/crates/db_queries/src/source/person_mention.rs +++ b/crates/db_queries/src/source/person_mention.rs @@ -105,6 +105,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -126,6 +127,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_recipient = Person::create(&conn, &recipient_form).unwrap(); diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index d6492e13..b1f6b7c2 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -288,6 +288,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/private_message.rs b/crates/db_queries/src/source/private_message.rs index fe245689..cd663093 100644 --- a/crates/db_queries/src/source/private_message.rs +++ b/crates/db_queries/src/source/private_message.rs @@ -165,6 +165,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_creator = Person::create(&conn, &creator_form).unwrap(); @@ -186,6 +187,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_recipient = Person::create(&conn, &recipient_form).unwrap(); diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 9bb3fe2d..4c990ec0 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -154,7 +154,6 @@ table! { lang -> Varchar, show_avatars -> Bool, send_notifications_to_email -> Bool, - matrix_user_id -> Nullable, validator_time -> Timestamp, } } @@ -287,6 +286,7 @@ table! { deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, + matrix_user_id -> Nullable, } } @@ -485,6 +485,7 @@ table! { deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, + matrix_user_id -> Nullable, } } @@ -507,6 +508,7 @@ table! { deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, + matrix_user_id -> Nullable, } } diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 11dac6c9..d902e6b4 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -16,7 +16,6 @@ pub struct LocalUser { pub lang: String, pub show_avatars: bool, pub send_notifications_to_email: bool, - pub matrix_user_id: Option, pub validator_time: chrono::NaiveDateTime, } @@ -35,7 +34,6 @@ pub struct LocalUserForm { pub lang: Option, pub show_avatars: Option, pub send_notifications_to_email: Option, - pub matrix_user_id: Option>, } /// A local user view that removes password encrypted @@ -53,6 +51,5 @@ pub struct LocalUserSettings { pub lang: String, pub show_avatars: bool, pub send_notifications_to_email: bool, - pub matrix_user_id: Option, pub validator_time: chrono::NaiveDateTime, } diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index f669f0c5..8c66b1a8 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -25,6 +25,7 @@ pub struct Person { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } /// A safe representation of person, without the sensitive info @@ -45,6 +46,7 @@ pub struct PersonSafe { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -67,6 +69,7 @@ pub struct PersonAlias1 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -86,6 +89,7 @@ pub struct PersonSafeAlias1 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -108,6 +112,7 @@ pub struct PersonAlias2 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -127,6 +132,7 @@ pub struct PersonSafeAlias2 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Insertable, AsChangeset, Clone)] @@ -148,4 +154,5 @@ pub struct PersonForm { pub deleted: Option, pub inbox_url: Option, pub shared_inbox_url: Option>, + pub matrix_user_id: Option>, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 6c5850ad..478a906f 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -469,6 +469,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -581,6 +582,7 @@ mod tests { updated: None, inbox_url: inserted_person.inbox_url.to_owned(), shared_inbox_url: None, + matrix_user_id: None, }, recipient: None, post: Post { diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index fe852e37..08d889d1 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -469,6 +469,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -596,6 +597,7 @@ mod tests { updated: None, inbox_url: inserted_person.inbox_url.to_owned(), shared_inbox_url: None, + matrix_user_id: None, }, creator_banned_from_community: false, community: CommunitySafe { diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql new file mode 100644 index 00000000..ce4eb4ad --- /dev/null +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql @@ -0,0 +1,8 @@ +alter table local_user add column matrix_user_id text; + +update local_user lu +set matrix_user_id = p.matrix_user_id +from person p +where p.id = lu.person_id; + +alter table person drop column matrix_user_id; diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql new file mode 100644 index 00000000..f8c577c9 --- /dev/null +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql @@ -0,0 +1,8 @@ +alter table person add column matrix_user_id text; + +update person p +set matrix_user_id = lu.matrix_user_id +from local_user lu +where p.id = lu.person_id; + +alter table local_user drop column matrix_user_id; diff --git a/src/code_migrations.rs b/src/code_migrations.rs index bd67fe69..e9b43356 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -70,6 +70,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { last_refreshed_at: Some(naive_now()), inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; Person::update(&conn, cperson.id, &form)?;