From: Dessalines Date: Tue, 10 May 2022 18:14:01 +0000 (-0400) Subject: Making community_follower.pending column not null. X-Git-Url: http://these/git/%22https:/nerdica.net/%7B%24%7B%60data:application/README.ja.md?a=commitdiff_plain;h=d4ee171b085d8c7168b3c21b23177377360ff92f;p=lemmy.git Making community_follower.pending column not null. --- diff --git a/api_tests/package.json b/api_tests/package.json index 849b721e..4deffe4f 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -16,7 +16,7 @@ "eslint": "^7.30.0", "eslint-plugin-jane": "^9.0.3", "jest": "^27.0.6", - "lemmy-js-client": "0.17.0-rc.2", + "lemmy-js-client": "0.17.0-rc.3", "node-fetch": "^2.6.1", "prettier": "^2.3.2", "ts-jest": "^27.0.3", diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index 8e075486..3b198755 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -3076,10 +3076,10 @@ language-tags@^1.0.5: dependencies: language-subtag-registry "~0.3.2" -lemmy-js-client@0.17.0-rc.2: - version "0.17.0-rc.2" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.2.tgz#4e6ff9a8d83ac922cd36eeaa01c657b3b93309e6" - integrity sha512-2YkZiAkq2ZUHPSl/B7pvMMkI19XRtTKwLFJ1u4NT2BlFkNdlvkvkOddnJ6aRwKAp/WBohxoKLoDHhlwePS5gqA== +lemmy-js-client@0.17.0-rc.3: + version "0.17.0-rc.3" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.3.tgz#3c9b3d5e3346eed8cb8096dad527e72096052223" + integrity sha512-VwKSkjqZhsTrtlKTKs9DEVaj9rlmMEjzn/BxkizU9v03Km7OIs9Z7cOEfperOR9A6q5gh2hWfTDp5eV/0kYkVg== leven@^3.1.0: version "3.1.0" diff --git a/crates/api/src/community/ban.rs b/crates/api/src/community/ban.rs index 60fd3227..f4a727eb 100644 --- a/crates/api/src/community/ban.rs +++ b/crates/api/src/community/ban.rs @@ -76,7 +76,7 @@ impl Perform for BanFromCommunity { let community_follower_form = CommunityFollowerForm { community_id: data.community_id, person_id: banned_person_id, - pending: false, + pending: Some(false), }; blocking(context.pool(), move |conn: &'_ _| { CommunityFollower::unfollow(conn, &community_follower_form) diff --git a/crates/api/src/community/block.rs b/crates/api/src/community/block.rs index 4f740c91..a8672e3e 100644 --- a/crates/api/src/community/block.rs +++ b/crates/api/src/community/block.rs @@ -47,7 +47,7 @@ impl Perform for BlockCommunity { let community_follower_form = CommunityFollowerForm { community_id: data.community_id, person_id, - pending: false, + pending: Some(false), }; blocking(context.pool(), move |conn: &'_ _| { CommunityFollower::unfollow(conn, &community_follower_form) diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index a61383b2..15a56b17 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -47,7 +47,7 @@ impl Perform for FollowCommunity { let community_follower_form = CommunityFollowerForm { community_id: data.community_id, person_id: local_user_view.person.id, - pending: false, // Don't worry, this form isn't used for remote follows + pending: Some(false), // Don't worry, this form isn't used for remote follows }; if community.local { diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index a7582d2e..451e9bfa 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -123,7 +123,7 @@ impl PerformCrud for CreateCommunity { let community_follower_form = CommunityFollowerForm { community_id: inserted_community.id, person_id: local_user_view.person.id, - pending: false, + pending: Some(false), }; let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form); diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 45661704..6752dcc8 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -232,7 +232,7 @@ impl PerformCrud for Register { let community_follower_form = CommunityFollowerForm { community_id: main_community.id, person_id: inserted_person.id, - pending: false, + pending: Some(false), }; let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form); diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index bcab3148..c05f2f87 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -200,7 +200,7 @@ impl ActivityHandler for BlockUser { let community_follower_form = CommunityFollowerForm { community_id: community.id, person_id: blocked_person.id, - pending: false, + pending: Some(false), }; blocking(context.pool(), move |conn: &'_ _| { CommunityFollower::unfollow(conn, &community_follower_form) diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index d46b3dc2..eb70cb91 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -50,7 +50,7 @@ impl FollowCommunity { let community_follower_form = CommunityFollowerForm { community_id: community.id, person_id: actor.id, - pending: true, + pending: Some(true), }; blocking(context.pool(), move |conn| { CommunityFollower::follow(conn, &community_follower_form).ok() @@ -100,7 +100,7 @@ impl ActivityHandler for FollowCommunity { let community_follower_form = CommunityFollowerForm { community_id: community.id, person_id: person.id, - pending: false, + pending: Some(false), }; // This will fail if they're already a follower, but ignore the error. diff --git a/crates/apub/src/activities/following/undo_follow.rs b/crates/apub/src/activities/following/undo_follow.rs index f70acdf2..f579d232 100644 --- a/crates/apub/src/activities/following/undo_follow.rs +++ b/crates/apub/src/activities/following/undo_follow.rs @@ -77,7 +77,7 @@ impl ActivityHandler for UndoFollowCommunity { let community_follower_form = CommunityFollowerForm { community_id: community.id, person_id: person.id, - pending: false, + pending: Some(false), }; // This will fail if they aren't a follower, but ignore the error. diff --git a/crates/db_schema/src/aggregates/community_aggregates.rs b/crates/db_schema/src/aggregates/community_aggregates.rs index 950e68d3..fc8cf0b0 100644 --- a/crates/db_schema/src/aggregates/community_aggregates.rs +++ b/crates/db_schema/src/aggregates/community_aggregates.rs @@ -66,7 +66,7 @@ mod tests { let first_person_follow = CommunityFollowerForm { community_id: inserted_community.id, person_id: inserted_person.id, - pending: false, + pending: Some(false), }; CommunityFollower::follow(&conn, &first_person_follow).unwrap(); @@ -74,7 +74,7 @@ mod tests { let second_person_follow = CommunityFollowerForm { community_id: inserted_community.id, person_id: another_inserted_person.id, - pending: false, + pending: Some(false), }; CommunityFollower::follow(&conn, &second_person_follow).unwrap(); @@ -82,7 +82,7 @@ mod tests { let another_community_follow = CommunityFollowerForm { community_id: another_inserted_community.id, person_id: inserted_person.id, - pending: false, + pending: Some(false), }; CommunityFollower::follow(&conn, &another_community_follow).unwrap(); diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 14a670f5..18619de6 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -380,7 +380,7 @@ mod tests { let community_follower_form = CommunityFollowerForm { community_id: inserted_community.id, person_id: inserted_person.id, - pending: false, + pending: Some(false), }; let inserted_community_follower = @@ -390,7 +390,7 @@ mod tests { id: inserted_community_follower.id, community_id: inserted_community.id, person_id: inserted_person.id, - pending: Some(false), + pending: false, published: inserted_community_follower.published, }; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 666986a6..74285e3c 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -119,7 +119,7 @@ table! { community_id -> Int4, person_id -> Int4, published -> Timestamp, - pending -> Nullable, + pending -> Bool, } } diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index 7693f2f4..9700e07a 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -128,7 +128,7 @@ pub struct CommunityFollower { pub community_id: CommunityId, pub person_id: PersonId, pub published: chrono::NaiveDateTime, - pub pending: Option, + pub pending: bool, } #[derive(Clone)] @@ -137,5 +137,5 @@ pub struct CommunityFollower { pub struct CommunityFollowerForm { pub community_id: CommunityId, pub person_id: PersonId, - pub pending: bool, + pub pending: Option, } diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index 7e37e446..7bece59d 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -10,7 +10,7 @@ use lemmy_db_schema::{ traits::{ToSafe, ViewToVec}, }; -type CommunityFollowerViewTuple = (CommunitySafe, PersonSafe, Option); +type CommunityFollowerViewTuple = (CommunitySafe, PersonSafe, bool); impl CommunityFollowerView { pub fn for_community(conn: &PgConnection, community_id: CommunityId) -> Result, Error> { diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index 25d2c178..a0b1ad4b 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -20,7 +20,7 @@ pub struct CommunityBlockView { pub struct CommunityFollowerView { pub community: CommunitySafe, pub follower: PersonSafe, - pub pending: Option, + pub pending: bool, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/migrations/2022-05-10-173801_change_pending_to_notnull/down.sql b/migrations/2022-05-10-173801_change_pending_to_notnull/down.sql new file mode 100644 index 00000000..4ef1387a --- /dev/null +++ b/migrations/2022-05-10-173801_change_pending_to_notnull/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` + +alter table community_follower + alter column pending drop not null, + alter column pending set default false; diff --git a/migrations/2022-05-10-173801_change_pending_to_notnull/up.sql b/migrations/2022-05-10-173801_change_pending_to_notnull/up.sql new file mode 100644 index 00000000..c589ac62 --- /dev/null +++ b/migrations/2022-05-10-173801_change_pending_to_notnull/up.sql @@ -0,0 +1,8 @@ +-- Make the pending column not null + +update community_follower set pending = true where pending is null; + +alter table community_follower + alter column pending set not null, + alter column pending set default true; +