]> Untitled Git - lemmy.git/commitdiff
Removing community.creator column. Fixes #1504 (#1541)
authorDessalines <dessalines@users.noreply.github.com>
Thu, 8 Apr 2021 11:29:08 +0000 (07:29 -0400)
committerGitHub <noreply@github.com>
Thu, 8 Apr 2021 11:29:08 +0000 (11:29 +0000)
* Removing community.creator column. Fixes #1504

* Fixing unit tests.

* Fixing federation tests.

32 files changed:
api_tests/package.json
api_tests/src/community.spec.ts
api_tests/src/private_message.spec.ts
api_tests/src/user.spec.ts
api_tests/yarn.lock
crates/api/src/community.rs
crates/api/src/local_user.rs
crates/api_crud/src/community/create.rs
crates/api_crud/src/community/delete.rs
crates/api_crud/src/community/update.rs
crates/api_crud/src/user/create.rs
crates/apub/src/objects/community.rs
crates/db_queries/src/aggregates/comment_aggregates.rs
crates/db_queries/src/aggregates/community_aggregates.rs
crates/db_queries/src/aggregates/person_aggregates.rs
crates/db_queries/src/aggregates/post_aggregates.rs
crates/db_queries/src/aggregates/site_aggregates.rs
crates/db_queries/src/source/comment.rs
crates/db_queries/src/source/community.rs
crates/db_queries/src/source/moderator.rs
crates/db_queries/src/source/person_mention.rs
crates/db_queries/src/source/post.rs
crates/db_schema/src/schema.rs
crates/db_schema/src/source/comment.rs
crates/db_schema/src/source/community.rs
crates/db_schema/src/source/post.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs
crates/db_views_actor/src/community_view.rs
migrations/2021-04-02-021422_remove_community_creator/down.sql [new file with mode: 0644]
migrations/2021-04-02-021422_remove_community_creator/up.sql [new file with mode: 0644]
src/code_migrations.rs

index 1b0583c4f5537da9a2fec638dcc12c67a8da7876..ca21c41302c4f65a29bd0a313beafccebc848189 100644 (file)
@@ -16,7 +16,7 @@
     "eslint": "^7.18.0",
     "eslint-plugin-jane": "^9.0.3",
     "jest": "^26.6.3",
-    "lemmy-js-client": "0.11.0-rc.1",
+    "lemmy-js-client": "0.11.0-rc.3",
     "node-fetch": "^2.6.1",
     "prettier": "^2.1.2",
     "ts-jest": "^26.4.4",
index 7be6f4c59f142a2095d0ab784d3605a8dfebaa51..a86c1259af2594fa5913a9db442ae91e38d5f996 100644 (file)
@@ -31,7 +31,6 @@ function assertCommunityFederation(
   expect(communityOne.community.published).toBe(
     communityTwo.community.published
   );
-  expect(communityOne.creator.actor_id).toBe(communityTwo.creator.actor_id);
   expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
   expect(communityOne.community.removed).toBe(communityTwo.community.removed);
   expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
index 5539b19c7d47918a2f82b221c042e81a77be840a..11b41cb17139244339fc3e47b5d8100f3fa251f8 100644 (file)
@@ -15,8 +15,8 @@ let recipient_id: number;
 
 beforeAll(async () => {
   await setupLogins();
-  let follow = await followBeta(alpha);
-  recipient_id = follow.community_view.creator.id;
+  await followBeta(alpha);
+  recipient_id = 3;
 });
 
 afterAll(async () => {
index 5d10fd04382d59b71f4154befd5505f117626c4e..a10876cf5e435ad346b2dd45390a14b931189244 100644 (file)
@@ -19,7 +19,7 @@ let apShortname: string;
 
 function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) {
   expect(userOne.person.name).toBe(userTwo.person.name);
-  expect(userOne.person.display_name).toBe(userTwo.person.display_name);
+  expect(userOne.person.preferred_username).toBe(userTwo.person.preferred_username);
   expect(userOne.person.bio).toBe(userTwo.person.bio);
   expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
   expect(userOne.person.avatar).toBe(userTwo.person.avatar);
@@ -49,7 +49,7 @@ test('Set some user settings, check that they are federated', async () => {
     lang: '',
     avatar,
     banner,
-    display_name: 'user321',
+    preferred_username: 'user321',
     show_avatars: false,
     send_notifications_to_email: false,
     bio,
index f3b8e603f9e8eda335a0b685e00c511b87a58676..1e459523b15829a60697cbe182ee3697a3b83e36 100644 (file)
@@ -3233,10 +3233,10 @@ language-tags@^1.0.5:
   dependencies:
     language-subtag-registry "~0.3.2"
 
-lemmy-js-client@0.11.0-rc.1:
-  version "0.11.0-rc.1"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.0-rc.1.tgz#0031676be9fc787157a21dd3f5095dd1ee9e6a57"
-  integrity sha512-dtpxe/hHTbYEv2WnfGkAieOB9jyKUVED+y4DosUp/FcaatjPcMTiKOvCdMNjlvvG/9GyclWEoyNitPEsvJwjmg==
+lemmy-js-client@0.11.0-rc.3:
+  version "0.11.0-rc.3"
+  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.0-rc.3.tgz#dd4727ca4d16fe9593368725aacfd9e7a8d52548"
+  integrity sha512-16mgl+TS1+0UHiY+ZKPuqHfbrn93h8K8tJ+kKJ1pjT2WhG23o0B8dLahG1jDQPG+dkXpR6PZxYudMYjuO8WvjQ==
 
 leven@^3.1.0:
   version "3.1.0"
index f1cf570c05a675a2a0ed4990a6b154c874c2a32b..3e6ae3e475e46b218df3a9f4fdb27eedee16e275 100644 (file)
@@ -10,11 +10,7 @@ use lemmy_api_common::{
 };
 use lemmy_apub::{ActorType, CommunityType, UserType};
 use lemmy_db_queries::{
-  source::{
-    comment::Comment_,
-    community::{CommunityModerator_, Community_},
-    post::Post_,
-  },
+  source::{comment::Comment_, community::CommunityModerator_, post::Post_},
   Bannable,
   Crud,
   Followable,
@@ -324,12 +320,6 @@ impl Perform for TransferCommunity {
     let data: &TransferCommunity = &self;
     let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
-    let community_id = data.community_id;
-    let read_community = blocking(context.pool(), move |conn| {
-      Community::read(conn, community_id)
-    })
-    .await??;
-
     let site_creator_id = blocking(context.pool(), move |conn| {
       Site::read(conn, 1).map(|s| s.creator_id)
     })
@@ -337,7 +327,7 @@ impl Perform for TransferCommunity {
 
     let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??;
 
-    // Making sure the creator, if an admin, is at the top
+    // Making sure the site creator, if an admin, is at the top
     let creator_index = admins
       .iter()
       .position(|r| r.person.id == site_creator_id)
@@ -345,8 +335,15 @@ impl Perform for TransferCommunity {
     let creator_person = admins.remove(creator_index);
     admins.insert(0, creator_person);
 
-    // Make sure user is the creator, or an admin
-    if local_user_view.person.id != read_community.creator_id
+    // Fetch the community mods
+    let community_id = data.community_id;
+    let mut community_mods = blocking(context.pool(), move |conn| {
+      CommunityModeratorView::for_community(conn, community_id)
+    })
+    .await??;
+
+    // Make sure transferrer is either the top community mod, or an admin
+    if local_user_view.person.id != community_mods[0].moderator.id
       && !admins
         .iter()
         .map(|a| a.person.id)
@@ -355,19 +352,8 @@ impl Perform for TransferCommunity {
       return Err(ApiError::err("not_an_admin").into());
     }
 
-    let community_id = data.community_id;
-    let new_creator = data.person_id;
-    let update = move |conn: &'_ _| Community::update_creator(conn, community_id, new_creator);
-    if blocking(context.pool(), update).await?.is_err() {
-      return Err(ApiError::err("couldnt_update_community").into());
-    };
-
-    // You also have to re-do the community_moderator table, reordering it.
-    let community_id = data.community_id;
-    let mut community_mods = blocking(context.pool(), move |conn| {
-      CommunityModeratorView::for_community(conn, community_id)
-    })
-    .await??;
+    // You have to re-do the community_moderator table, reordering it.
+    // Add the transferee to the top
     let creator_index = community_mods
       .iter()
       .position(|r| r.moderator.id == data.person_id)
@@ -375,6 +361,7 @@ impl Perform for TransferCommunity {
     let creator_person = community_mods.remove(creator_index);
     community_mods.insert(0, creator_person);
 
+    // Delete all the mods
     let community_id = data.community_id;
     blocking(context.pool(), move |conn| {
       CommunityModerator::delete_for_community(conn, community_id)
@@ -382,6 +369,7 @@ impl Perform for TransferCommunity {
     .await??;
 
     // TODO: this should probably be a bulk operation
+    // Re-add the mods, in the new order
     for cmod in &community_mods {
       let community_moderator_form = CommunityModeratorForm {
         community_id: cmod.community.id,
@@ -395,6 +383,8 @@ impl Perform for TransferCommunity {
     }
 
     // Mod tables
+    // TODO there should probably be another table for transfer community
+    // Right now, it will just look like it modded them twice
     let form = ModAddCommunityForm {
       mod_person_id: local_user_view.person.id,
       other_person_id: data.person_id,
index bf5693ce02b64ccc6bf43d1d36c14448bb7bd6e7..0acb29f1572c37a71791b7e0e6bffd8d1ab7eb14 100644 (file)
@@ -18,7 +18,6 @@ use lemmy_db_queries::{
   diesel_option_overwrite_to_url,
   source::{
     comment::Comment_,
-    community::Community_,
     local_user::LocalUser_,
     password_reset_request::PasswordResetRequest_,
     person::Person_,
@@ -33,7 +32,6 @@ use lemmy_db_schema::{
   naive_now,
   source::{
     comment::Comment,
-    community::*,
     local_user::{LocalUser, LocalUserForm},
     moderator::*,
     password_reset_request::*,
@@ -407,10 +405,9 @@ impl Perform for BanPerson {
       .await??;
 
       // Communities
-      blocking(context.pool(), move |conn: &'_ _| {
-        Community::update_removed_for_creator(conn, banned_person_id, true)
-      })
-      .await??;
+      // Remove all communities where they're the top mod
+      // TODO couldn't get group by's working in diesel,
+      // for now, remove the communities manually
 
       // Comments
       blocking(context.pool(), move |conn: &'_ _| {
index bef376f0bc079c00dda7b92b4d32bbb2a5eee666..393b3746a22c4168b4d762e681d5164e89380f4a 100644 (file)
@@ -75,7 +75,6 @@ impl PerformCrud for CreateCommunity {
       description: data.description.to_owned(),
       icon,
       banner,
-      creator_id: local_user_view.person.id,
       nsfw: data.nsfw,
       actor_id: Some(community_actor_id.to_owned()),
       private_key: Some(keypair.private_key),
index 9b52660f6bfb811c2aafa477e22d95fba431c852..b94c153b2503256e5d24f53e6f4c032055309c90 100644 (file)
@@ -7,7 +7,10 @@ use lemmy_db_schema::source::{
   community::*,
   moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
 };
-use lemmy_db_views_actor::community_view::CommunityView;
+use lemmy_db_views_actor::{
+  community_moderator_view::CommunityModeratorView,
+  community_view::CommunityView,
+};
 use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{LemmyContext, UserOperationCrud};
 
@@ -23,13 +26,15 @@ impl PerformCrud for DeleteCommunity {
     let data: &DeleteCommunity = &self;
     let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
-    // Verify its the creator (only a creator can delete the community)
+    // Fetch the community mods
     let community_id = data.community_id;
-    let read_community = blocking(context.pool(), move |conn| {
-      Community::read(conn, community_id)
+    let community_mods = blocking(context.pool(), move |conn| {
+      CommunityModeratorView::for_community(conn, community_id)
     })
     .await??;
-    if read_community.creator_id != local_user_view.person.id {
+
+    // Make sure deleter is the top mod
+    if local_user_view.person.id != community_mods[0].moderator.id {
       return Err(ApiError::err("no_community_edit_allowed").into());
     }
 
index 0a0540fa7a89fbb2501a169e8fb063e8aed721a3..9e8339fbe70ba63a9320a8340b55cda2c86d5406 100644 (file)
@@ -61,7 +61,6 @@ impl PerformCrud for EditCommunity {
     let community_form = CommunityForm {
       name: read_community.name,
       title: data.title.to_owned(),
-      creator_id: read_community.creator_id,
       description: data.description.to_owned(),
       icon,
       banner,
index c61c1e79a6663b63626194d5b84e2bf92fb73d39..96bc3be9ac34aca8359d9070138f0cc918b0e792 100644 (file)
@@ -178,7 +178,6 @@ impl PerformCrud for Register {
           name: default_community_name.to_string(),
           title: "The Default Community".to_string(),
           description: Some("The Default Community".to_string()),
-          creator_id: inserted_person.id,
           actor_id: Some(actor_id.to_owned()),
           private_key: Some(main_community_keypair.private_key),
           public_key: Some(main_community_keypair.public_key),
index acf1f045cf15d5d60ac0f59a5a86263aeaefbe27..f886fd1b00a08b39e5ac4592d4edd9df248a3c26 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   extensions::{context::lemmy_context, group_extension::GroupExtension},
-  fetcher::{community::fetch_community_mods, person::get_or_fetch_and_upsert_person},
+  fetcher::community::fetch_community_mods,
   generate_moderators_url,
   objects::{
     check_object_domain,
@@ -140,24 +140,7 @@ impl FromApubToForm<GroupExt> for CommunityForm {
     request_counter: &mut i32,
     _mod_action_allowed: bool,
   ) -> Result<Self, LemmyError> {
-    let moderator_uris = fetch_community_mods(context, group, request_counter).await?;
-    let creator = if let Some(creator_uri) = moderator_uris.first() {
-      get_or_fetch_and_upsert_person(creator_uri, context, request_counter)
-    } else {
-      // NOTE: code for compatibility with lemmy v0.9.9
-      let creator_uri = group
-        .inner
-        .attributed_to()
-        .map(|a| a.as_many())
-        .flatten()
-        .map(|a| a.first())
-        .flatten()
-        .map(|a| a.as_xsd_any_uri())
-        .flatten()
-        .context(location_info!())?;
-      get_or_fetch_and_upsert_person(creator_uri, context, request_counter)
-    }
-    .await?;
+    fetch_community_mods(context, group, request_counter).await?;
 
     let name = group
       .inner
@@ -215,7 +198,6 @@ impl FromApubToForm<GroupExt> for CommunityForm {
       name,
       title,
       description,
-      creator_id: creator.id,
       removed: None,
       published: group.inner.published().map(|u| u.to_owned().naive_local()),
       updated: group.inner.updated().map(|u| u.to_owned().naive_local()),
index a2bea11efaf325f1e66430e93c2dbe608ccef242..898c57da392e3b8b1eed89077e56629d9a1b10e5 100644 (file)
@@ -58,7 +58,6 @@ mod tests {
 
     let new_community = CommunityForm {
       name: "TIL_comment_agg".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -142,5 +141,9 @@ mod tests {
     Person::delete(&conn, another_inserted_person.id).unwrap();
     let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
     assert_eq!(1, person_num_deleted);
+
+    // Delete the community
+    let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
+    assert_eq!(1, community_num_deleted);
   }
 }
index 25c0b394e22024b81c49d736bfdd494bde9728bc..c668c15ac8a4fa50d1fe989e4a5cc2debad9cd39 100644 (file)
@@ -62,7 +62,6 @@ mod tests {
 
     let new_community = CommunityForm {
       name: "TIL_community_agg".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -71,7 +70,6 @@ mod tests {
 
     let another_community = CommunityForm {
       name: "TIL_community_agg_2".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -169,6 +167,14 @@ mod tests {
     let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
     assert_eq!(1, person_num_deleted);
 
+    // Delete the community
+    let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
+    assert_eq!(1, community_num_deleted);
+
+    let another_community_num_deleted =
+      Community::delete(&conn, another_inserted_community.id).unwrap();
+    assert_eq!(1, another_community_num_deleted);
+
     // Should be none found, since the creator was deleted
     let after_delete = CommunityAggregates::read(&conn, inserted_community.id);
     assert!(after_delete.is_err());
index 953f74ee7f3f7f3158e4e7a3fb530c13af4c4608..56d72d38b076b974725b83d975936c887ddb56b5 100644 (file)
@@ -58,7 +58,6 @@ mod tests {
 
     let new_community = CommunityForm {
       name: "TIL_site_agg".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -160,6 +159,10 @@ mod tests {
     assert_eq!(1, person_num_deleted);
     Person::delete(&conn, another_inserted_person.id).unwrap();
 
+    // Delete the community
+    let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
+    assert_eq!(1, community_num_deleted);
+
     // Should be none found
     let after_delete = PersonAggregates::read(&conn, inserted_person.id);
     assert!(after_delete.is_err());
index fe73813167f1adc4d950d89a4e5a7bdbe30e59ef..2fcb6f5d2132b8782d914cf94560c9566b1bbca2 100644 (file)
@@ -62,7 +62,6 @@ mod tests {
 
     let new_community = CommunityForm {
       name: "TIL_community_agg".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -149,6 +148,10 @@ mod tests {
     let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
     assert_eq!(1, person_num_deleted);
 
+    // Delete the community
+    let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
+    assert_eq!(1, community_num_deleted);
+
     // Should be none found, since the creator was deleted
     let after_delete = PostAggregates::read(&conn, inserted_post.id);
     assert!(after_delete.is_err());
index e7c6bfaef30db4db6382454fc8df7814683b0fac..995462e1a8b8f72fc5d8ae81177949e933fbfea7 100644 (file)
@@ -64,7 +64,6 @@ mod tests {
 
     let new_community = CommunityForm {
       name: "TIL_site_agg".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -119,6 +118,10 @@ mod tests {
     let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
     assert_eq!(1, person_num_deleted);
 
+    // Delete the community
+    let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
+    assert_eq!(1, community_num_deleted);
+
     let after_delete = SiteAggregates::read(&conn);
     assert!(after_delete.is_err());
   }
index 8d77626aa70c6a5d4703f235698451d814ea4465..1eec0c987115f1611d1fd1d35092bc859bf9fbb2 100644 (file)
@@ -254,7 +254,6 @@ mod tests {
     let new_community = CommunityForm {
       name: "test community".to_string(),
       title: "nada".to_owned(),
-      creator_id: inserted_person.id,
       ..CommunityForm::default()
     };
 
index 1970eef88babe398b77458f9d50fb99baf9ae286..3f1f047673e2024baabeb61ed4de68d56725492f 100644 (file)
@@ -26,7 +26,6 @@ mod safe_type {
     name,
     title,
     description,
-    creator_id,
     removed,
     published,
     updated,
@@ -46,7 +45,6 @@ mod safe_type {
         name,
         title,
         description,
-        creator_id,
         removed,
         published,
         updated,
@@ -122,16 +120,6 @@ pub trait Community_ {
     community_id: CommunityId,
     new_removed: bool,
   ) -> Result<Community, Error>;
-  fn update_removed_for_creator(
-    conn: &PgConnection,
-    for_creator_id: PersonId,
-    new_removed: bool,
-  ) -> Result<Vec<Community>, Error>;
-  fn update_creator(
-    conn: &PgConnection,
-    community_id: CommunityId,
-    new_creator_id: PersonId,
-  ) -> Result<Community, Error>;
   fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
   fn read_from_followers_url(
     conn: &PgConnection,
@@ -170,28 +158,6 @@ impl Community_ for Community {
       .get_result::<Self>(conn)
   }
 
-  fn update_removed_for_creator(
-    conn: &PgConnection,
-    for_creator_id: PersonId,
-    new_removed: bool,
-  ) -> Result<Vec<Community>, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
-    diesel::update(community.filter(creator_id.eq(for_creator_id)))
-      .set((removed.eq(new_removed), updated.eq(naive_now())))
-      .get_results::<Self>(conn)
-  }
-
-  fn update_creator(
-    conn: &PgConnection,
-    community_id: CommunityId,
-    new_creator_id: PersonId,
-  ) -> Result<Community, Error> {
-    use lemmy_db_schema::schema::community::dsl::*;
-    diesel::update(community.find(community_id))
-      .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
-      .get_result::<Self>(conn)
-  }
-
   fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
     use lemmy_db_schema::schema::community::dsl::*;
     community.select(actor_id).distinct().load::<String>(conn)
@@ -363,7 +329,6 @@ mod tests {
 
     let new_community = CommunityForm {
       name: "TIL".into(),
-      creator_id: inserted_person.id,
       title: "nada".to_owned(),
       ..CommunityForm::default()
     };
@@ -372,7 +337,6 @@ mod tests {
 
     let expected_community = Community {
       id: inserted_community.id,
-      creator_id: inserted_person.id,
       name: "TIL".into(),
       title: "nada".to_owned(),
       description: None,
index c641fffc74fd9b0880ac8d6394eec95e467b2915..14bb07f1c8ec4bd84ddc78d8ba8d56cca54eabc8 100644 (file)
@@ -224,7 +224,6 @@ mod tests {
     let new_community = CommunityForm {
       name: "mod_community".to_string(),
       title: "nada".to_owned(),
-      creator_id: inserted_person.id,
       ..CommunityForm::default()
     };
 
index 5a3a7ea61dcca9d418a317a360203130180feb7a..45689420037a304f346b56294a3c25bcaeb23009 100644 (file)
@@ -105,7 +105,6 @@ mod tests {
     let new_community = CommunityForm {
       name: "test community lake".to_string(),
       title: "nada".to_owned(),
-      creator_id: inserted_person.id,
       ..CommunityForm::default()
     };
 
index 169ca18ef51c8ab062ee735bdafdfd0c11f7873d..0205dc954063836878fd78eb8e74b9e6e8c15e13 100644 (file)
@@ -281,7 +281,6 @@ mod tests {
     let new_community = CommunityForm {
       name: "test community_3".to_string(),
       title: "nada".to_owned(),
-      creator_id: inserted_person.id,
       ..CommunityForm::default()
     };
 
index ee94b6c5209406dd1780cd7a342f2c3182a8ecf8..9b05d29ab0364cea80bb7e8664d9cf6ee35126f5 100644 (file)
@@ -78,7 +78,6 @@ table! {
         name -> Varchar,
         title -> Varchar,
         description -> Nullable<Text>,
-        creator_id -> Int4,
         removed -> Bool,
         published -> Timestamp,
         updated -> Nullable<Timestamp>,
@@ -534,7 +533,6 @@ joinable!(comment_like -> post (post_id));
 joinable!(comment_report -> comment (comment_id));
 joinable!(comment_saved -> comment (comment_id));
 joinable!(comment_saved -> person (person_id));
-joinable!(community -> person (creator_id));
 joinable!(community_aggregates -> community (community_id));
 joinable!(community_follower -> community (community_id));
 joinable!(community_follower -> person (person_id));
index fba61f4632de84b46043c4369fe0576d3dc02348..bd36a48e8ba3a2ffabcf643464424efd466d467f 100644 (file)
@@ -56,8 +56,8 @@ pub struct CommentAlias1 {
 pub struct CommentForm {
   pub creator_id: PersonId,
   pub post_id: PostId,
-  pub parent_id: Option<CommentId>,
   pub content: String,
+  pub parent_id: Option<CommentId>,
   pub removed: Option<bool>,
   pub read: Option<bool>,
   pub published: Option<chrono::NaiveDateTime>,
index 4275102709c19e098314794c71c98c144fe8baa9..1581933f0053530cc63fedbae9b38033878e7d4c 100644 (file)
@@ -13,7 +13,6 @@ pub struct Community {
   pub name: String,
   pub title: String,
   pub description: Option<String>,
-  pub creator_id: PersonId,
   pub removed: bool,
   pub published: chrono::NaiveDateTime,
   pub updated: Option<chrono::NaiveDateTime>,
@@ -39,7 +38,6 @@ pub struct CommunitySafe {
   pub name: String,
   pub title: String,
   pub description: Option<String>,
-  pub creator_id: PersonId,
   pub removed: bool,
   pub published: chrono::NaiveDateTime,
   pub updated: Option<chrono::NaiveDateTime>,
@@ -57,7 +55,6 @@ pub struct CommunityForm {
   pub name: String,
   pub title: String,
   pub description: Option<String>,
-  pub creator_id: PersonId,
   pub removed: Option<bool>,
   pub published: Option<chrono::NaiveDateTime>,
   pub updated: Option<chrono::NaiveDateTime>,
index 87681e010eaf5eb7fd5ebda7e6a200552f38f081..2581db95c77967eb12bec91cba77c2a790cdcf8b 100644 (file)
@@ -35,16 +35,16 @@ pub struct Post {
 #[table_name = "post"]
 pub struct PostForm {
   pub name: String,
-  pub url: Option<DbUrl>,
-  pub body: Option<String>,
   pub creator_id: PersonId,
   pub community_id: CommunityId,
+  pub nsfw: bool,
+  pub url: Option<DbUrl>,
+  pub body: Option<String>,
   pub removed: Option<bool>,
   pub locked: Option<bool>,
   pub published: Option<chrono::NaiveDateTime>,
   pub updated: Option<chrono::NaiveDateTime>,
   pub deleted: Option<bool>,
-  pub nsfw: bool,
   pub stickied: Option<bool>,
   pub embed_title: Option<String>,
   pub embed_description: Option<String>,
index ff5b6debfc4515f4d744b2a93d353a6b38b307bc..fd2debf2c050d7f1c0c425a57e71e55cdce2c822 100644 (file)
@@ -462,7 +462,6 @@ mod tests {
     let new_community = CommunityForm {
       name: "test community 5".to_string(),
       title: "nada".to_owned(),
-      creator_id: inserted_person.id,
       ..CommunityForm::default()
     };
 
@@ -567,7 +566,6 @@ mod tests {
         local: true,
         title: "nada".to_owned(),
         description: None,
-        creator_id: inserted_person.id,
         updated: None,
         banner: None,
         published: inserted_community.published,
index 64f261aadbb0ac94f53562362d0a696630d6daca..a6843416eed1fa731a1226dc09932f92d285d8be 100644 (file)
@@ -263,7 +263,7 @@ impl<'a> PostQueryBuilder<'a> {
         community_person_ban::table.on(
           post::community_id
             .eq(community_person_ban::community_id)
-            .and(community_person_ban::person_id.eq(community::creator_id)),
+            .and(community_person_ban::person_id.eq(post::creator_id)),
         ),
       )
       .inner_join(post_aggregates::table)
@@ -462,7 +462,6 @@ mod tests {
     let new_community = CommunityForm {
       name: community_name.to_owned(),
       title: "nada".to_owned(),
-      creator_id: inserted_person.id,
       ..CommunityForm::default()
     };
 
@@ -568,7 +567,6 @@ mod tests {
         local: true,
         title: "nada".to_owned(),
         description: None,
-        creator_id: inserted_person.id,
         updated: None,
         banner: None,
         published: inserted_community.published,
index 87b9cbcf16748181bd4f4638ba9e95331b1d72fd..0ee503a710781a3a232fc5f8d88d58593b1155b7 100644 (file)
@@ -12,11 +12,8 @@ use lemmy_db_queries::{
   ViewToVec,
 };
 use lemmy_db_schema::{
-  schema::{community, community_aggregates, community_follower, person},
-  source::{
-    community::{Community, CommunityFollower, CommunitySafe},
-    person::{Person, PersonSafe},
-  },
+  schema::{community, community_aggregates, community_follower},
+  source::community::{Community, CommunityFollower, CommunitySafe},
   CommunityId,
   PersonId,
 };
@@ -25,14 +22,12 @@ use serde::Serialize;
 #[derive(Debug, Serialize, Clone)]
 pub struct CommunityView {
   pub community: CommunitySafe,
-  pub creator: PersonSafe,
   pub subscribed: bool,
   pub counts: CommunityAggregates,
 }
 
 type CommunityViewTuple = (
   CommunitySafe,
-  PersonSafe,
   CommunityAggregates,
   Option<CommunityFollower>,
 );
@@ -46,9 +41,8 @@ impl CommunityView {
     // The left join below will return None in this case
     let person_id_join = my_person_id.unwrap_or(PersonId(-1));
 
-    let (community, creator, counts, follower) = community::table
+    let (community, counts, follower) = community::table
       .find(community_id)
-      .inner_join(person::table)
       .inner_join(community_aggregates::table)
       .left_join(
         community_follower::table.on(
@@ -59,7 +53,6 @@ impl CommunityView {
       )
       .select((
         Community::safe_columns_tuple(),
-        Person::safe_columns_tuple(),
         community_aggregates::all_columns,
         community_follower::all_columns.nullable(),
       ))
@@ -67,7 +60,6 @@ impl CommunityView {
 
     Ok(CommunityView {
       community,
-      creator,
       subscribed: follower.is_some(),
       counts,
     })
@@ -165,7 +157,6 @@ impl<'a> CommunityQueryBuilder<'a> {
     let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
 
     let mut query = community::table
-      .inner_join(person::table)
       .inner_join(community_aggregates::table)
       .left_join(
         community_follower::table.on(
@@ -176,7 +167,6 @@ impl<'a> CommunityQueryBuilder<'a> {
       )
       .select((
         Community::safe_columns_tuple(),
-        Person::safe_columns_tuple(),
         community_aggregates::all_columns,
         community_follower::all_columns.nullable(),
       ))
@@ -237,9 +227,8 @@ impl ViewToVec for CommunityView {
       .iter()
       .map(|a| Self {
         community: a.0.to_owned(),
-        creator: a.1.to_owned(),
-        counts: a.2.to_owned(),
-        subscribed: a.3.is_some(),
+        counts: a.1.to_owned(),
+        subscribed: a.2.is_some(),
       })
       .collect::<Vec<Self>>()
   }
diff --git a/migrations/2021-04-02-021422_remove_community_creator/down.sql b/migrations/2021-04-02-021422_remove_community_creator/down.sql
new file mode 100644 (file)
index 0000000..d015f25
--- /dev/null
@@ -0,0 +1,24 @@
+
+--  Add the column back
+alter table community add column creator_id int references person on update cascade on delete cascade;
+
+-- Recreate the index
+create index idx_community_creator on community (creator_id);
+
+-- Add the data, selecting the highest mod
+update community
+set creator_id = sub.person_id
+from (
+  select 
+  cm.community_id,
+  cm.person_id
+  from 
+  community_moderator cm
+  limit 1
+) as sub
+where id = sub.community_id;
+
+-- Set to not null
+alter table community alter column creator_id set not null;
+
+
diff --git a/migrations/2021-04-02-021422_remove_community_creator/up.sql b/migrations/2021-04-02-021422_remove_community_creator/up.sql
new file mode 100644 (file)
index 0000000..c3415c6
--- /dev/null
@@ -0,0 +1,2 @@
+-- Drop the column
+alter table community drop column creator_id;
index 144c39f872563f69e3731a920c65b45f6ecc535e..d8563b51bda293a79d2f40e73c524dd0ab395c32 100644 (file)
@@ -89,7 +89,6 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
       name: ccommunity.name.to_owned(),
       title: ccommunity.title.to_owned(),
       description: ccommunity.description.to_owned(),
-      creator_id: ccommunity.creator_id,
       removed: None,
       deleted: None,
       nsfw: None,