From 723ec65ac61642c47df9b3e4424623f26f5d09db Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 24 Feb 2021 17:10:28 -0500 Subject: [PATCH 1/3] Use more recent version of cargo chef. --- docker/dev/Dockerfile | 4 ++-- docker/prod/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index a2712f9f2..3e3963d29 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -3,7 +3,7 @@ ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0 # Cargo chef plan FROM $RUST_BUILDER_IMAGE as planner WORKDIR /app -RUN cargo install cargo-chef --version 0.1.6 +RUN cargo install cargo-chef # Copy dirs COPY ./ ./ @@ -15,7 +15,7 @@ RUN cargo chef prepare --recipe-path recipe.json FROM $RUST_BUILDER_IMAGE as cacher ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl WORKDIR /app -RUN cargo install cargo-chef --version 0.1.6 +RUN cargo install cargo-chef COPY --from=planner /app/recipe.json ./recipe.json RUN sudo chown -R rust:rust . RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index 8f307bf60..66e8217fe 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -3,7 +3,7 @@ ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0 # Cargo chef plan FROM $RUST_BUILDER_IMAGE as planner WORKDIR /app -RUN cargo install cargo-chef --version 0.1.6 +RUN cargo install cargo-chef # Copy dirs COPY ./ ./ @@ -15,7 +15,7 @@ RUN cargo chef prepare --recipe-path recipe.json FROM $RUST_BUILDER_IMAGE as cacher ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl WORKDIR /app -RUN cargo install cargo-chef --version 0.1.6 +RUN cargo install cargo-chef COPY --from=planner /app/recipe.json ./recipe.json RUN sudo chown -R rust:rust . RUN cargo chef cook --release --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json From 3141ad31de1eea105bc0d6b41da0b0878d1222ab Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 25 Feb 2021 13:16:58 +0100 Subject: [PATCH 2/3] Remove categories (fixes #1429) --- crates/api/src/community.rs | 2 - crates/api/src/lib.rs | 3 -- crates/api/src/routes.rs | 5 -- crates/api/src/site.rs | 27 +--------- crates/api/src/user.rs | 1 - .../apub/src/extensions/group_extensions.rs | 28 +--------- crates/apub/src/objects/community.rs | 16 +----- .../src/aggregates/comment_aggregates.rs | 1 - .../src/aggregates/community_aggregates.rs | 2 - .../src/aggregates/post_aggregates.rs | 1 - .../src/aggregates/site_aggregates.rs | 1 - .../src/aggregates/user_aggregates.rs | 1 - crates/db_queries/src/source/category.rs | 54 ------------------- crates/db_queries/src/source/comment.rs | 1 - crates/db_queries/src/source/community.rs | 4 -- crates/db_queries/src/source/mod.rs | 1 - crates/db_queries/src/source/moderator.rs | 1 - crates/db_queries/src/source/post.rs | 1 - crates/db_queries/src/source/user_mention.rs | 1 - crates/db_schema/src/schema.rs | 10 ---- crates/db_schema/src/source/category.rs | 15 ------ crates/db_schema/src/source/community.rs | 3 -- crates/db_schema/src/source/mod.rs | 1 - crates/db_views/src/comment_view.rs | 2 - crates/db_views/src/post_view.rs | 2 - crates/db_views_actor/src/community_view.rs | 17 ++---- crates/structs/src/site.rs | 10 +--- crates/websocket/src/lib.rs | 1 - .../down.sql | 34 ++++++++++++ .../up.sql | 2 + src/code_migrations.rs | 1 - tests/integration_test.rs | 1 - 32 files changed, 45 insertions(+), 205 deletions(-) delete mode 100644 crates/db_queries/src/source/category.rs delete mode 100644 crates/db_schema/src/source/category.rs create mode 100644 migrations/2021-02-25-112959_remove-categories/down.sql create mode 100644 migrations/2021-02-25-112959_remove-categories/up.sql diff --git a/crates/api/src/community.rs b/crates/api/src/community.rs index fcfe79133..128d8b303 100644 --- a/crates/api/src/community.rs +++ b/crates/api/src/community.rs @@ -170,7 +170,6 @@ impl Perform for CreateCommunity { description: data.description.to_owned(), icon, banner, - category_id: data.category_id, creator_id: user.id, removed: None, deleted: None, @@ -273,7 +272,6 @@ impl Perform for EditCommunity { description: data.description.to_owned(), icon, banner, - category_id: data.category_id.to_owned(), creator_id: read_community.creator_id, removed: Some(read_community.removed), deleted: Some(read_community.deleted), diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 7f6fcb029..5642c4b9c 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -298,9 +298,6 @@ pub async fn match_websocket_operation( UserOperation::TransferSite => { do_websocket_operation::(context, id, op, data).await } - UserOperation::ListCategories => { - do_websocket_operation::(context, id, op, data).await - } // Community ops UserOperation::GetCommunity => { diff --git a/crates/api/src/routes.rs b/crates/api/src/routes.rs index a55dec5f2..7ca609f1a 100644 --- a/crates/api/src/routes.rs +++ b/crates/api/src/routes.rs @@ -22,11 +22,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route("/config", web::get().to(route_get::)) .route("/config", web::put().to(route_post::)), ) - .service( - web::resource("/categories") - .wrap(rate_limit.message()) - .route(web::get().to(route_get::)), - ) .service( web::resource("/modlog") .wrap(rate_limit.message()) diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index d9ed835ea..b545a72ea 100644 --- a/crates/api/src/site.rs +++ b/crates/api/src/site.rs @@ -10,17 +10,10 @@ use crate::{ use actix_web::web::Data; use anyhow::Context; use lemmy_apub::fetcher::search::search_by_apub_id; -use lemmy_db_queries::{ - diesel_option_overwrite, - source::{category::Category_, site::Site_}, - Crud, - SearchType, - SortType, -}; +use lemmy_db_queries::{diesel_option_overwrite, source::site::Site_, Crud, SearchType, SortType}; use lemmy_db_schema::{ naive_now, source::{ - category::Category, moderator::*, site::{Site, *}, }, @@ -63,24 +56,6 @@ use lemmy_websocket::{ use log::{debug, info}; use std::str::FromStr; -#[async_trait::async_trait(?Send)] -impl Perform for ListCategories { - type Response = ListCategoriesResponse; - - async fn perform( - &self, - context: &Data, - _websocket_id: Option, - ) -> Result { - let _data: &ListCategories = &self; - - let categories = blocking(context.pool(), move |conn| Category::list_all(conn)).await??; - - // Return the jwt - Ok(ListCategoriesResponse { categories }) - } -} - #[async_trait::async_trait(?Send)] impl Perform for GetModlog { type Response = GetModlogResponse; diff --git a/crates/api/src/user.rs b/crates/api/src/user.rs index dfe527db3..c6877fe0d 100644 --- a/crates/api/src/user.rs +++ b/crates/api/src/user.rs @@ -251,7 +251,6 @@ impl Perform for Register { name: default_community_name.to_string(), title: "The Default Community".to_string(), description: Some("The Default Community".to_string()), - category_id: 1, nsfw: false, creator_id: inserted_user.id, removed: None, diff --git a/crates/apub/src/extensions/group_extensions.rs b/crates/apub/src/extensions/group_extensions.rs index 891cb26c7..face43cab 100644 --- a/crates/apub/src/extensions/group_extensions.rs +++ b/crates/apub/src/extensions/group_extensions.rs @@ -1,41 +1,19 @@ use activitystreams::unparsed::UnparsedMutExt; use activitystreams_ext::UnparsedExtension; -use diesel::PgConnection; -use lemmy_db_queries::Crud; -use lemmy_db_schema::source::category::Category; use lemmy_utils::LemmyError; use serde::{Deserialize, Serialize}; -/// Activitystreams extension to allow (de)serializing additional Community fields `category` and +/// Activitystreams extension to allow (de)serializing additional Community field /// `sensitive` (called 'nsfw' in Lemmy). #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct GroupExtension { - pub category: Option, pub sensitive: Option, } -#[derive(Clone, Debug, Default, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct GroupCategory { - // Using a string because that's how Peertube does it. - pub identifier: String, - pub name: String, -} - impl GroupExtension { - pub fn new( - conn: &PgConnection, - category_id: i32, - sensitive: bool, - ) -> Result { - let category = Category::read(conn, category_id)?; - let group_category = GroupCategory { - identifier: category_id.to_string(), - name: category.name, - }; + pub fn new(sensitive: bool) -> Result { Ok(GroupExtension { - category: Some(group_category), sensitive: Some(sensitive), }) } @@ -49,13 +27,11 @@ where fn try_from_unparsed(unparsed_mut: &mut U) -> Result { Ok(GroupExtension { - category: unparsed_mut.remove("category")?, sensitive: unparsed_mut.remove("sensitive")?, }) } fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { - unparsed_mut.insert("category", self.category)?; unparsed_mut.insert("sensitive", self.sensitive)?; Ok(()) } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index c6189f9c7..827eae294 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -93,16 +93,9 @@ impl ToApub for Community { ..Default::default() }); - let nsfw = self.nsfw; - let category_id = self.category_id; - let group_extension = blocking(pool, move |conn| { - GroupExtension::new(conn, category_id, nsfw) - }) - .await??; - Ok(Ext2::new( ap_actor, - group_extension, + GroupExtension::new(self.nsfw)?, self.get_public_key_ext()?, )) } @@ -207,13 +200,6 @@ impl FromApubToForm for CommunityForm { name, title, description, - category_id: group - .ext_one - .category - .clone() - .map(|c| c.identifier.parse::().ok()) - .flatten() - .unwrap_or(1), creator_id: creator.id, removed: None, published: group.inner.published().map(|u| u.to_owned().naive_local()), diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index 619847271..a4db471b6 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -109,7 +109,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index baeaa759b..f5cd577e4 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -113,7 +113,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, @@ -138,7 +137,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index ffee93bec..fa8b69255 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -113,7 +113,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index 125513656..46db2f0cd 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -94,7 +94,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, diff --git a/crates/db_queries/src/aggregates/user_aggregates.rs b/crates/db_queries/src/aggregates/user_aggregates.rs index 8d232268c..fcda1d462 100644 --- a/crates/db_queries/src/aggregates/user_aggregates.rs +++ b/crates/db_queries/src/aggregates/user_aggregates.rs @@ -109,7 +109,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, diff --git a/crates/db_queries/src/source/category.rs b/crates/db_queries/src/source/category.rs deleted file mode 100644 index 2d9eeb37b..000000000 --- a/crates/db_queries/src/source/category.rs +++ /dev/null @@ -1,54 +0,0 @@ -use crate::Crud; -use diesel::{dsl::*, result::Error, *}; -use lemmy_db_schema::{schema::category::dsl::*, source::category::*}; - -impl Crud for Category { - fn read(conn: &PgConnection, category_id: i32) -> Result { - category.find(category_id).first::(conn) - } - - fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result { - insert_into(category) - .values(new_category) - .get_result::(conn) - } - - fn update( - conn: &PgConnection, - category_id: i32, - new_category: &CategoryForm, - ) -> Result { - diesel::update(category.find(category_id)) - .set(new_category) - .get_result::(conn) - } -} - -pub trait Category_ { - fn list_all(conn: &PgConnection) -> Result, Error>; -} - -impl Category_ for Category { - fn list_all(conn: &PgConnection) -> Result, Error> { - category.load::(conn) - } -} - -#[cfg(test)] -mod tests { - use crate::{establish_unpooled_connection, source::category::Category_}; - use lemmy_db_schema::source::category::Category; - - #[test] - fn test_crud() { - let conn = establish_unpooled_connection(); - - let categories = Category::list_all(&conn).unwrap(); - let expected_first_category = Category { - id: 1, - name: "Discussion".into(), - }; - - assert_eq!(expected_first_category, categories[0]); - } -} diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index 3abff1c5d..709a8aa39 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -252,7 +252,6 @@ mod tests { name: "test community".to_string(), title: "nada".to_owned(), description: None, - category_id: 1, creator_id: inserted_user.id, removed: None, deleted: None, diff --git a/crates/db_queries/src/source/community.rs b/crates/db_queries/src/source/community.rs index c2809a78f..08421bd5d 100644 --- a/crates/db_queries/src/source/community.rs +++ b/crates/db_queries/src/source/community.rs @@ -24,7 +24,6 @@ mod safe_type { name, title, description, - category_id, creator_id, removed, published, @@ -45,7 +44,6 @@ mod safe_type { name, title, description, - category_id, creator_id, removed, published, @@ -383,7 +381,6 @@ mod tests { creator_id: inserted_user.id, title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, @@ -409,7 +406,6 @@ mod tests { name: "TIL".into(), title: "nada".to_owned(), description: None, - category_id: 1, nsfw: false, removed: false, deleted: false, diff --git a/crates/db_queries/src/source/mod.rs b/crates/db_queries/src/source/mod.rs index 211194a44..a39dc1108 100644 --- a/crates/db_queries/src/source/mod.rs +++ b/crates/db_queries/src/source/mod.rs @@ -1,5 +1,4 @@ pub mod activity; -pub mod category; pub mod comment; pub mod comment_report; pub mod community; diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index e3ee76328..9b6e58edf 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -271,7 +271,6 @@ mod tests { name: "mod_community".to_string(), title: "nada".to_owned(), description: None, - category_id: 1, creator_id: inserted_user.id, removed: None, deleted: None, diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index ddb3702c2..1c19e53d0 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -271,7 +271,6 @@ mod tests { name: "test community_3".to_string(), title: "nada".to_owned(), description: None, - category_id: 1, creator_id: inserted_user.id, removed: None, deleted: None, diff --git a/crates/db_queries/src/source/user_mention.rs b/crates/db_queries/src/source/user_mention.rs index 93f0b86d0..b0c97572f 100644 --- a/crates/db_queries/src/source/user_mention.rs +++ b/crates/db_queries/src/source/user_mention.rs @@ -152,7 +152,6 @@ mod tests { name: "test community lake".to_string(), title: "nada".to_owned(), description: None, - category_id: 1, creator_id: inserted_user.id, removed: None, deleted: None, diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 71232ebdb..3786e00ca 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -10,13 +10,6 @@ table! { } } -table! { - category (id) { - id -> Int4, - name -> Varchar, - } -} - table! { comment (id) { id -> Int4, @@ -85,7 +78,6 @@ table! { name -> Varchar, title -> Varchar, description -> Nullable, - category_id -> Int4, creator_id -> Int4, removed -> Bool, published -> Timestamp, @@ -546,7 +538,6 @@ joinable!(comment_like -> user_ (user_id)); joinable!(comment_report -> comment (comment_id)); joinable!(comment_saved -> comment (comment_id)); joinable!(comment_saved -> user_ (user_id)); -joinable!(community -> category (category_id)); joinable!(community -> user_ (creator_id)); joinable!(community_aggregates -> community (community_id)); joinable!(community_follower -> community (community_id)); @@ -587,7 +578,6 @@ joinable!(user_mention -> user_ (recipient_id)); allow_tables_to_appear_in_same_query!( activity, - category, comment, comment_aggregates, comment_like, diff --git a/crates/db_schema/src/source/category.rs b/crates/db_schema/src/source/category.rs deleted file mode 100644 index ea2ff1238..000000000 --- a/crates/db_schema/src/source/category.rs +++ /dev/null @@ -1,15 +0,0 @@ -use crate::schema::category; -use serde::Serialize; - -#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Clone)] -#[table_name = "category"] -pub struct Category { - pub id: i32, - pub name: String, -} - -#[derive(Insertable, AsChangeset)] -#[table_name = "category"] -pub struct CategoryForm { - pub name: String, -} diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index e05abf1b3..b8702ca97 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -11,7 +11,6 @@ pub struct Community { pub name: String, pub title: String, pub description: Option, - pub category_id: i32, pub creator_id: i32, pub removed: bool, pub published: chrono::NaiveDateTime, @@ -38,7 +37,6 @@ pub struct CommunitySafe { pub name: String, pub title: String, pub description: Option, - pub category_id: i32, pub creator_id: i32, pub removed: bool, pub published: chrono::NaiveDateTime, @@ -57,7 +55,6 @@ pub struct CommunityForm { pub name: String, pub title: String, pub description: Option, - pub category_id: i32, pub creator_id: i32, pub removed: Option, pub published: Option, diff --git a/crates/db_schema/src/source/mod.rs b/crates/db_schema/src/source/mod.rs index 211194a44..a39dc1108 100644 --- a/crates/db_schema/src/source/mod.rs +++ b/crates/db_schema/src/source/mod.rs @@ -1,5 +1,4 @@ pub mod activity; -pub mod category; pub mod comment; pub mod comment_report; pub mod community; diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index b2a9902a4..4f9a6a5f7 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -483,7 +483,6 @@ mod tests { name: "test community 5".to_string(), title: "nada".to_owned(), description: None, - category_id: 1, creator_id: inserted_user.id, removed: None, deleted: None, @@ -625,7 +624,6 @@ mod tests { title: "nada".to_owned(), description: None, creator_id: inserted_user.id, - category_id: 1, updated: None, banner: None, published: inserted_community.published, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 54e28de17..ed1ef4ce1 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -479,7 +479,6 @@ mod tests { title: "nada".to_owned(), description: None, creator_id: inserted_user.id, - category_id: 1, removed: None, deleted: None, updated: None, @@ -614,7 +613,6 @@ mod tests { title: "nada".to_owned(), description: None, creator_id: inserted_user.id, - category_id: 1, updated: None, banner: None, published: inserted_community.published, diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 714fd65e8..9187696db 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -12,9 +12,8 @@ use lemmy_db_queries::{ ViewToVec, }; use lemmy_db_schema::{ - schema::{category, community, community_aggregates, community_follower, user_}, + schema::{community, community_aggregates, community_follower, user_}, source::{ - category::Category, community::{Community, CommunityFollower, CommunitySafe}, user::{UserSafe, User_}, }, @@ -25,7 +24,6 @@ use serde::Serialize; pub struct CommunityView { pub community: CommunitySafe, pub creator: UserSafe, - pub category: Category, pub subscribed: bool, pub counts: CommunityAggregates, } @@ -33,7 +31,6 @@ pub struct CommunityView { type CommunityViewTuple = ( CommunitySafe, UserSafe, - Category, CommunityAggregates, Option, ); @@ -47,10 +44,9 @@ impl CommunityView { // The left join below will return None in this case let user_id_join = my_user_id.unwrap_or(-1); - let (community, creator, category, counts, follower) = community::table + let (community, creator, counts, follower) = community::table .find(community_id) .inner_join(user_::table) - .inner_join(category::table) .inner_join(community_aggregates::table) .left_join( community_follower::table.on( @@ -62,7 +58,6 @@ impl CommunityView { .select(( Community::safe_columns_tuple(), User_::safe_columns_tuple(), - category::all_columns, community_aggregates::all_columns, community_follower::all_columns.nullable(), )) @@ -71,7 +66,6 @@ impl CommunityView { Ok(CommunityView { community, creator, - category, subscribed: follower.is_some(), counts, }) @@ -162,7 +156,6 @@ impl<'a> CommunityQueryBuilder<'a> { let mut query = community::table .inner_join(user_::table) - .inner_join(category::table) .inner_join(community_aggregates::table) .left_join( community_follower::table.on( @@ -174,7 +167,6 @@ impl<'a> CommunityQueryBuilder<'a> { .select(( Community::safe_columns_tuple(), User_::safe_columns_tuple(), - category::all_columns, community_aggregates::all_columns, community_follower::all_columns.nullable(), )) @@ -235,9 +227,8 @@ impl ViewToVec for CommunityView { .map(|a| Self { community: a.0.to_owned(), creator: a.1.to_owned(), - category: a.2.to_owned(), - counts: a.3.to_owned(), - subscribed: a.4.is_some(), + counts: a.2.to_owned(), + subscribed: a.3.is_some(), }) .collect::>() } diff --git a/crates/structs/src/site.rs b/crates/structs/src/site.rs index 22b44d73c..ef878ba52 100644 --- a/crates/structs/src/site.rs +++ b/crates/structs/src/site.rs @@ -1,4 +1,4 @@ -use lemmy_db_schema::source::{category::*, user::UserSafeSettings}; +use lemmy_db_schema::source::user::UserSafeSettings; use lemmy_db_views::{comment_view::CommentView, post_view::PostView, site_view::SiteView}; use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe}; use lemmy_db_views_moderator::{ @@ -14,14 +14,6 @@ use lemmy_db_views_moderator::{ }; use serde::{Deserialize, Serialize}; -#[derive(Deserialize)] -pub struct ListCategories {} - -#[derive(Serialize)] -pub struct ListCategoriesResponse { - pub categories: Vec, -} - #[derive(Deserialize, Debug)] pub struct Search { pub q: String, diff --git a/crates/websocket/src/lib.rs b/crates/websocket/src/lib.rs index 2144ffefb..4723c7141 100644 --- a/crates/websocket/src/lib.rs +++ b/crates/websocket/src/lib.rs @@ -88,7 +88,6 @@ pub enum UserOperation { CreateCommunity, CreatePost, ListCommunities, - ListCategories, GetPost, GetCommunity, CreateComment, diff --git a/migrations/2021-02-25-112959_remove-categories/down.sql b/migrations/2021-02-25-112959_remove-categories/down.sql new file mode 100644 index 000000000..9f1837b42 --- /dev/null +++ b/migrations/2021-02-25-112959_remove-categories/down.sql @@ -0,0 +1,34 @@ +create table category ( + id serial primary key, + name varchar(100) not null unique +); + +insert into category (name) values +('Discussion'), +('Humor/Memes'), +('Gaming'), +('Movies'), +('TV'), +('Music'), +('Literature'), +('Comics'), +('Photography'), +('Art'), +('Learning'), +('DIY'), +('Lifestyle'), +('News'), +('Politics'), +('Society'), +('Gender/Identity/Sexuality'), +('Race/Colonisation'), +('Religion'), +('Science/Technology'), +('Programming/Software'), +('Health/Sports/Fitness'), +('Porn'), +('Places'), +('Meta'), +('Other'); + +ALTER TABLE community ADD category_id int references category on update cascade on delete cascade not null; \ No newline at end of file diff --git a/migrations/2021-02-25-112959_remove-categories/up.sql b/migrations/2021-02-25-112959_remove-categories/up.sql new file mode 100644 index 000000000..ebe83e541 --- /dev/null +++ b/migrations/2021-02-25-112959_remove-categories/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE community DROP COLUMN category_id; +DROP TABLE category; diff --git a/src/code_migrations.rs b/src/code_migrations.rs index 7478d5af7..ea11e32d3 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -109,7 +109,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(), - category_id: ccommunity.category_id, creator_id: ccommunity.creator_id, removed: None, deleted: None, diff --git a/tests/integration_test.rs b/tests/integration_test.rs index f205ceb51..5f92dc6b7 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -127,7 +127,6 @@ fn create_community(conn: &PgConnection, creator_id: i32) -> Community { creator_id, title: "test_community".to_owned(), description: None, - category_id: 1, nsfw: false, removed: None, deleted: None, From 72783edb1756f19405e26f5fa591bacd5548a61c Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 25 Feb 2021 16:16:02 +0100 Subject: [PATCH 3/3] In remove categories down migration, add default for category --- migrations/2021-02-25-112959_remove-categories/down.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/2021-02-25-112959_remove-categories/down.sql b/migrations/2021-02-25-112959_remove-categories/down.sql index 9f1837b42..35386f795 100644 --- a/migrations/2021-02-25-112959_remove-categories/down.sql +++ b/migrations/2021-02-25-112959_remove-categories/down.sql @@ -31,4 +31,4 @@ insert into category (name) values ('Meta'), ('Other'); -ALTER TABLE community ADD category_id int references category on update cascade on delete cascade not null; \ No newline at end of file +ALTER TABLE community ADD category_id int references category on update cascade on delete cascade not null default 1; \ No newline at end of file