]> Untitled Git - lemmy.git/commitdiff
Merge remote-tracking branch 'origin/split-db-workspace' into move_views_to_diesel_split
authorDessalines <tyhou13@gmx.com>
Mon, 21 Dec 2020 14:28:20 +0000 (09:28 -0500)
committerDessalines <tyhou13@gmx.com>
Mon, 21 Dec 2020 14:28:20 +0000 (09:28 -0500)
30 files changed:
1  2 
Cargo.lock
Cargo.toml
lemmy_api/src/comment.rs
lemmy_api/src/community.rs
lemmy_api/src/lib.rs
lemmy_api/src/post.rs
lemmy_api/src/site.rs
lemmy_api/src/user.rs
lemmy_apub/src/activities/receive/private_message.rs
lemmy_apub/src/activity_queue.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/inbox/receive_for_community.rs
lemmy_apub/src/inbox/user_inbox.rs
lemmy_apub/src/objects/comment.rs
lemmy_db/Cargo.toml
lemmy_db/src/aggregates/comment_aggregates.rs
lemmy_db/src/aggregates/site_aggregates.rs
lemmy_db/src/lib.rs
lemmy_db/src/source/post.rs
lemmy_db/src/source/site.rs
lemmy_db/src/views/comment_view.rs
lemmy_db/src/views/post_view.rs
lemmy_db/src/views/site_view.rs
lemmy_db_schema/src/schema.rs
lemmy_db_schema/src/source/comment_report.rs
lemmy_db_schema/src/source/post_report.rs
lemmy_structs/src/lib.rs
lemmy_structs/src/site.rs
src/code_migrations.rs
tests/integration_test.rs

diff --cc Cargo.lock
index 815cd20f69d4e55b5ca064fba84937a6302418a4,6cc79feddc9a7d301c5290f5644c42018253d29f..060fa8913c3d463c35566fbdb67862e8403381b3
@@@ -1788,8 -1790,8 +1790,9 @@@ dependencies = 
   "bcrypt",
   "chrono",
   "diesel",
 + "diesel_migrations",
   "lazy_static",
+  "lemmy_db_schema",
   "lemmy_utils",
   "log",
   "regex",
diff --cc Cargo.toml
Simple merge
index e5f079ad2ae395aa556d41315ac5eedc2117e2dc,2f0f8a6198d7a34f33ccef51d472298183ec6518..bafde6bfbeb67d3d0736e97e5e88b7039e90cfd6
@@@ -27,6 -23,7 +23,7 @@@ use lemmy_db::
    Saveable,
    SortType,
  };
 -use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*, post::Post, user::*};
++use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*};
  use lemmy_structs::{blocking, comment::*, send_local_notifs};
  use lemmy_utils::{
    apub::{make_apub_endpoint, EndpointType},
Simple merge
index eadb0d1ac9278e8e58318b09662173d61510daba,fc484c32393bec6e9af42ab3b6624e90d2d74a47..4b61539b4d9853b0af3048e31e70124e66a8f45f
@@@ -1,16 -1,16 +1,20 @@@
  use crate::claims::Claims;
  use actix_web::{web, web::Data};
  use lemmy_db::{
 -  source::community::{CommunityModerator_, Community_},
 +  source::{
-     community::{Community, CommunityModerator},
-     post::Post,
-     site::Site,
-     user::User_,
++    community::{CommunityModerator_, Community_},
++    site::Site_,
 +  },
    views::community::community_user_ban_view::CommunityUserBanView,
    Crud,
    DbPool,
  };
+ use lemmy_db_schema::source::{
+   community::{Community, CommunityModerator},
+   post::Post,
++  site::Site,
+   user::User_,
+ };
  use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
  use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
  use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
index f021b0d7ce2bc4545e423f11b392fcaf6fc34ff2,2dd834be99805ed37fcdb6ba86cf43124727bdef..20b5b8d556e1e6f77fef4a1f137675adc0858526
@@@ -11,17 -10,13 +11,12 @@@ use crate::
  use actix_web::web::Data;
  use lemmy_apub::{ApubLikeableType, ApubObjectType};
  use lemmy_db::{
-   naive_now,
-   source::{
-     moderator::*,
-     post::*,
-     post_report::{PostReport, PostReportForm},
-   },
+   source::post::Post_,
    views::{
      comment_view::CommentQueryBuilder,
 -    community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
 +    community::community_moderator_view::CommunityModeratorView,
      post_report_view::{PostReportQueryBuilder, PostReportView},
      post_view::{PostQueryBuilder, PostView},
 -    site_view::SiteView,
    },
    Crud,
    Likeable,
index 16c6ecec9bd7063a440ac791be5148f695858669,05cac0ae648f9fd7256f5947bbb1efee08cd99d7..e30e62303213683d5496352b47dd753686b42163
@@@ -10,9 -10,9 +10,8 @@@ use actix_web::web::Data
  use anyhow::Context;
  use lemmy_apub::fetcher::search_by_apub_id;
  use lemmy_db::{
 -  aggregates::site_aggregates::SiteAggregates,
    diesel_option_overwrite,
-   naive_now,
-   source::{category::*, moderator::*, site::*},
+   source::{category::Category_, site::Site_},
    views::{
      comment_view::CommentQueryBuilder,
      community::community_view::CommunityQueryBuilder,
index cca8dffb8909225d06ecb23c12ce5f9fef75ea60,98a186c316b9627fe69bb448a6203bcfd236aad0..34ef5022e17f470ed1ceada4a1dc81de2ea52e18
@@@ -16,17 -16,14 +16,15 @@@ use chrono::Duration
  use lemmy_apub::ApubObjectType;
  use lemmy_db::{
    diesel_option_overwrite,
-   naive_now,
    source::{
-     comment::*,
-     community::*,
-     moderator::*,
-     password_reset_request::*,
-     post::*,
-     private_message::*,
-     site::*,
-     user::*,
-     user_mention::*,
+     comment::Comment_,
+     community::Community_,
+     password_reset_request::PasswordResetRequest_,
+     post::Post_,
+     private_message::PrivateMessage_,
++    site::Site_,
+     user::User,
+     user_mention::UserMention_,
    },
    views::{
      comment_report_view::CommentReportView,
Simple merge
Simple merge
Simple merge
index 5963f32cc331e8c81f77691417db884704627337,0442d0145ebcf885f7a3cc6a38545b65ee6dd45e..15dd749acaff940c7f98c68fea09fdf348be038f
@@@ -9,8 -9,8 +9,9 @@@ path = "src/lib.rs
  
  [dependencies]
  lemmy_utils = { path = "../lemmy_utils" }
+ lemmy_db_schema = { path = "../lemmy_db_schema" }
  diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
 +diesel_migrations = "1.4.0"
  chrono = { version = "0.4.19", features = ["serde"] }
  serde = { version = "1.0.118", features = ["derive"] }
  serde_json = { version = "1.0.60", features = ["preserve_order"] }
index df3cad6f1ecff77fdc06c1d80728e41255c90ad3,52890d8144fa3a6bb8afe542914553b31a9e9fe7..70997a66a77dd7427216a49901afe49ad6e40e95
@@@ -1,8 -1,8 +1,8 @@@
- use crate::schema::site_aggregates;
  use diesel::{result::Error, *};
+ use lemmy_db_schema::schema::site_aggregates;
  use serde::Serialize;
  
 -#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
 +#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
  #[table_name = "site_aggregates"]
  pub struct SiteAggregates {
    pub id: i32,
index 4df69ca432fb9da21e4d20a34a2c7afe4a2ebae4,9afb76191accc0f738fa4355eca1b6ca76189e84..8e3521478dcdf9eacb42149c5c286b9f451d6073
@@@ -4,12 -4,7 +4,11 @@@ extern crate diesel
  extern crate strum_macros;
  #[macro_use]
  extern crate lazy_static;
 +// this is used in tests
 +#[allow(unused_imports)]
 +#[macro_use]
 +extern crate diesel_migrations;
  
- use chrono::NaiveDateTime;
  use diesel::{result::Error, *};
  use regex::Regex;
  use serde::{Deserialize, Serialize};
index 948791ea4ae1f8abfd75b40a06a8a0e30e5113d1,81f09e722de2098b1c1b3442f81ed7b30a4f1200..c681adbe47bf1282b7c5e188c63d0852121bc258
@@@ -88,29 -38,33 +38,27 @@@ impl Crud<PostForm> for Post 
    }
  }
  
- impl ApubObject<PostForm> for Post {
-   fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
-     use crate::schema::post::dsl::*;
-     post.filter(ap_id.eq(object_id)).first::<Self>(conn)
-   }
-   fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
-     use crate::schema::post::dsl::*;
-     insert_into(post)
-       .values(post_form)
-       .on_conflict(ap_id)
-       .do_update()
-       .set(post_form)
-       .get_result::<Self>(conn)
-   }
+ pub trait Post_ {
+   //fn read(conn: &PgConnection, post_id: i32) -> Result<Post, Error>;
+   fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result<Vec<Post>, Error>;
+   fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Post, Error>;
+   fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Post>, Error>;
+   fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result<Post, Error>;
+   fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result<Post, Error>;
+   fn update_removed_for_creator(
+     conn: &PgConnection,
+     for_creator_id: i32,
+     for_community_id: Option<i32>,
+     new_removed: bool,
+   ) -> Result<Vec<Post>, Error>;
+   fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Post, Error>;
+   fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Post, Error>;
+   fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool;
  }
  
- impl Post {
-   pub fn list_for_community(
-     conn: &PgConnection,
-     the_community_id: i32,
-   ) -> Result<Vec<Self>, Error> {
-     use crate::schema::post::dsl::*;
+ impl Post_ for Post {
 -  // TODO: this is a duplicate?
 -  //fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
 -  //  use lemmy_db_schema::schema::post::dsl::*;
 -  //  post.filter(id.eq(post_id)).first::<Self>(conn)
 -  //}
 -
+   fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result<Vec<Self>, Error> {
+     use lemmy_db_schema::schema::post::dsl::*;
      post
        .filter(community_id.eq(the_community_id))
        .then_order_by(published.desc())
index 8775191e1b3bf2773c38db16375f8434d6457524,2e0e99dfabe04b0736973584da6bfb773fab9c71..2510f46c9d4d4f76d7031ed573ab5c429348ef01
@@@ -50,22 -19,17 +19,27 @@@ impl Crud<SiteForm> for Site 
        .set(new_site)
        .get_result::<Self>(conn)
    }
-     use crate::schema::site::dsl::*;
 +  fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
++    use lemmy_db_schema::schema::site::dsl::*;
 +    diesel::delete(site.find(site_id)).execute(conn)
 +  }
  }
  
- impl Site {
-   pub fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Self, Error> {
-     use crate::schema::site::dsl::*;
+ pub trait Site_ {
+   fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error>;
++  fn read_simple(conn: &PgConnection) -> Result<Site, Error>;
+ }
+ impl Site_ for Site {
+   fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error> {
+     use lemmy_db_schema::schema::site::dsl::*;
      diesel::update(site.find(1))
        .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
        .get_result::<Self>(conn)
    }
-   pub fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
-     use crate::schema::site::dsl::*;
 +
++  fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
++    use lemmy_db_schema::schema::site::dsl::*;
 +    site.first::<Self>(conn)
 +  }
  }
Simple merge
Simple merge
index 3c605277e10e646f16c35967da86771e26439e38,a56c8fe30169d74cee6acf73a18c5c5ff78e783e..7772ccdcef6b37da0ad2e81e25bc6a2c691a614a
@@@ -1,6 -1,7 +1,7 @@@
- use crate::{
-   aggregates::site_aggregates::SiteAggregates,
 -use crate::ToSafe;
++use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
+ use diesel::{result::Error, *};
+ use lemmy_db_schema::{
 -  schema::{site, user_},
 +  schema::{site, site_aggregates, user_},
    source::{
      site::Site,
      user::{UserSafe, User_},
Simple merge
index 0000000000000000000000000000000000000000,d94fed578cc38bbc35b35471e16a82d2bc0fa41e..ec53408d125a13e677a8df257d7e9af856418695
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,26 +1,28 @@@
 -#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
+ use crate::{schema::comment_report, source::comment::Comment};
+ use serde::{Deserialize, Serialize};
++#[derive(
++  Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
++)]
+ #[belongs_to(Comment)]
+ #[table_name = "comment_report"]
+ pub struct CommentReport {
+   pub id: i32,
+   pub creator_id: i32,
+   pub comment_id: i32,
+   pub original_comment_text: String,
+   pub reason: String,
+   pub resolved: bool,
+   pub resolver_id: Option<i32>,
+   pub published: chrono::NaiveDateTime,
+   pub updated: Option<chrono::NaiveDateTime>,
+ }
+ #[derive(Insertable, AsChangeset, Clone)]
+ #[table_name = "comment_report"]
+ pub struct CommentReportForm {
+   pub creator_id: i32,
+   pub comment_id: i32,
+   pub original_comment_text: String,
+   pub reason: String,
+ }
index 0000000000000000000000000000000000000000,608104dbc90dcf14bf8796f54d1de1919a6ea98a..b75fb954a078cc1a6bc77b01d8a2836523d68298
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,30 +1,32 @@@
 -#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
+ use crate::{schema::post_report, source::post::Post};
+ use serde::{Deserialize, Serialize};
++#[derive(
++  Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
++)]
+ #[belongs_to(Post)]
+ #[table_name = "post_report"]
+ pub struct PostReport {
+   pub id: i32,
+   pub creator_id: i32,
+   pub post_id: i32,
+   pub original_post_name: String,
+   pub original_post_url: Option<String>,
+   pub original_post_body: Option<String>,
+   pub reason: String,
+   pub resolved: bool,
+   pub resolver_id: Option<i32>,
+   pub published: chrono::NaiveDateTime,
+   pub updated: Option<chrono::NaiveDateTime>,
+ }
+ #[derive(Insertable, AsChangeset, Clone)]
+ #[table_name = "post_report"]
+ pub struct PostReportForm {
+   pub creator_id: i32,
+   pub post_id: i32,
+   pub original_post_name: String,
+   pub original_post_url: Option<String>,
+   pub original_post_body: Option<String>,
+   pub reason: String,
+ }
index d19127384b773ab04864fd6e821aba4a4c5df388,d344f452959d0b0419a401818aaf433fe1faae17..080cb38521618761c8c1bdef1587747a99ba4cc9
@@@ -3,17 -3,15 +3,14 @@@ pub mod community
  pub mod post;
  pub mod site;
  pub mod user;
 -pub mod websocket;
  
  use diesel::PgConnection;
- use lemmy_db::{
-   source::{
-     comment::Comment,
-     post::Post,
-     user::User_,
-     user_mention::{UserMention, UserMentionForm},
-   },
-   Crud,
-   DbPool,
+ use lemmy_db::{source::user::User, Crud, DbPool};
+ use lemmy_db_schema::source::{
+   comment::Comment,
+   post::Post,
+   user::User_,
+   user_mention::{UserMention, UserMentionForm},
  };
  use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
  use log::error;
index ff6c8a3912cb81a40b713043202d18ea8f89cea4,5011d84fffe6dcbedf57aba77896a68788ec3db0..f24d9f49ee42db21292b2d09f40a253653b4beea
@@@ -1,24 -1,25 +1,22 @@@
--use lemmy_db::{
-   source::{category::*, user::*},
 -  aggregates::site_aggregates::SiteAggregates,
--  views::{
--    comment_view::CommentView,
--    community::community_view::CommunityView,
--    moderator::{
--      mod_add_community_view::ModAddCommunityView,
--      mod_add_view::ModAddView,
--      mod_ban_from_community_view::ModBanFromCommunityView,
--      mod_ban_view::ModBanView,
--      mod_lock_post_view::ModLockPostView,
--      mod_remove_comment_view::ModRemoveCommentView,
--      mod_remove_community_view::ModRemoveCommunityView,
--      mod_remove_post_view::ModRemovePostView,
--      mod_sticky_post_view::ModStickyPostView,
--    },
--    post_view::PostView,
--    site_view::SiteView,
--    user_view::UserViewSafe,
++use lemmy_db::views::{
++  comment_view::CommentView,
++  community::community_view::CommunityView,
++  moderator::{
++    mod_add_community_view::ModAddCommunityView,
++    mod_add_view::ModAddView,
++    mod_ban_from_community_view::ModBanFromCommunityView,
++    mod_ban_view::ModBanView,
++    mod_lock_post_view::ModLockPostView,
++    mod_remove_comment_view::ModRemoveCommentView,
++    mod_remove_community_view::ModRemoveCommunityView,
++    mod_remove_post_view::ModRemovePostView,
++    mod_sticky_post_view::ModStickyPostView,
    },
++  post_view::PostView,
++  site_view::SiteView,
++  user_view::UserViewSafe,
  };
+ use lemmy_db_schema::source::{category::*, user::User_};
  use serde::{Deserialize, Serialize};
  
  #[derive(Deserialize)]
Simple merge
Simple merge