From 3141ad31de1eea105bc0d6b41da0b0878d1222ab Mon Sep 17 00:00:00 2001 From: Felix Ableitner <me@nutomic.com> Date: Thu, 25 Feb 2021 13:16:58 +0100 Subject: [PATCH] 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 fcfe7913..128d8b30 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 7f6fcb02..5642c4b9 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::<TransferSite>(context, id, op, data).await } - UserOperation::ListCategories => { - do_websocket_operation::<ListCategories>(context, id, op, data).await - } // Community ops UserOperation::GetCommunity => { diff --git a/crates/api/src/routes.rs b/crates/api/src/routes.rs index a55dec5f..7ca609f1 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::<GetSiteConfig>)) .route("/config", web::put().to(route_post::<SaveSiteConfig>)), ) - .service( - web::resource("/categories") - .wrap(rate_limit.message()) - .route(web::get().to(route_get::<ListCategories>)), - ) .service( web::resource("/modlog") .wrap(rate_limit.message()) diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index d9ed835e..b545a72e 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<LemmyContext>, - _websocket_id: Option<ConnectionId>, - ) -> Result<ListCategoriesResponse, LemmyError> { - 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 dfe527db..c6877fe0 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 891cb26c..face43ca 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<GroupCategory>, pub sensitive: Option<bool>, } -#[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<GroupExtension, LemmyError> { - 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<GroupExtension, LemmyError> { Ok(GroupExtension { - category: Some(group_category), sensitive: Some(sensitive), }) } @@ -49,13 +27,11 @@ where fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> { 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 c6189f9c..827eae29 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<GroupExt> for CommunityForm { name, title, description, - category_id: group - .ext_one - .category - .clone() - .map(|c| c.identifier.parse::<i32>().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 61984727..a4db471b 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 baeaa759..f5cd577e 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 ffee93be..fa8b6925 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 12551365..46db2f0c 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 8d232268..fcda1d46 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 2d9eeb37..00000000 --- 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<CategoryForm> for Category { - fn read(conn: &PgConnection, category_id: i32) -> Result<Self, Error> { - category.find(category_id).first::<Self>(conn) - } - - fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> { - insert_into(category) - .values(new_category) - .get_result::<Self>(conn) - } - - fn update( - conn: &PgConnection, - category_id: i32, - new_category: &CategoryForm, - ) -> Result<Self, Error> { - diesel::update(category.find(category_id)) - .set(new_category) - .get_result::<Self>(conn) - } -} - -pub trait Category_ { - fn list_all(conn: &PgConnection) -> Result<Vec<Category>, Error>; -} - -impl Category_ for Category { - fn list_all(conn: &PgConnection) -> Result<Vec<Category>, Error> { - category.load::<Self>(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 3abff1c5..709a8aa3 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 c2809a78..08421bd5 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 211194a4..a39dc110 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 e3ee7632..9b6e58ed 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 ddb3702c..1c19e53d 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 93f0b86d..b0c97572 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 71232ebd..3786e00c 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<Text>, - 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 ea2ff123..00000000 --- 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 e05abf1b..b8702ca9 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<String>, - 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<String>, - 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<String>, - pub category_id: i32, pub creator_id: i32, pub removed: Option<bool>, pub published: Option<chrono::NaiveDateTime>, diff --git a/crates/db_schema/src/source/mod.rs b/crates/db_schema/src/source/mod.rs index 211194a4..a39dc110 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 b2a9902a..4f9a6a5f 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 54e28de1..ed1ef4ce 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 714fd65e..9187696d 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<CommunityFollower>, ); @@ -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::<Vec<Self>>() } diff --git a/crates/structs/src/site.rs b/crates/structs/src/site.rs index 22b44d73..ef878ba5 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<Category>, -} - #[derive(Deserialize, Debug)] pub struct Search { pub q: String, diff --git a/crates/websocket/src/lib.rs b/crates/websocket/src/lib.rs index 2144ffef..4723c714 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 00000000..9f1837b4 --- /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 00000000..ebe83e54 --- /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 7478d5af..ea11e32d 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 f205ceb5..5f92dc6b 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, -- 2.44.1