]> 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)
109 files changed:
Cargo.lock
Cargo.toml
lemmy_api/Cargo.toml
lemmy_api/src/claims.rs
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/Cargo.toml
lemmy_apub/src/activities/receive/comment.rs
lemmy_apub/src/activities/receive/comment_undo.rs
lemmy_apub/src/activities/receive/community.rs
lemmy_apub/src/activities/receive/mod.rs
lemmy_apub/src/activities/receive/post.rs
lemmy_apub/src/activities/receive/post_undo.rs
lemmy_apub/src/activities/receive/private_message.rs
lemmy_apub/src/activities/send/comment.rs
lemmy_apub/src/activities/send/community.rs
lemmy_apub/src/activities/send/post.rs
lemmy_apub/src/activities/send/private_message.rs
lemmy_apub/src/activities/send/user.rs
lemmy_apub/src/activity_queue.rs
lemmy_apub/src/extensions/group_extensions.rs
lemmy_apub/src/fetcher.rs
lemmy_apub/src/http/comment.rs
lemmy_apub/src/http/community.rs
lemmy_apub/src/http/mod.rs
lemmy_apub/src/http/post.rs
lemmy_apub/src/http/user.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/inbox/mod.rs
lemmy_apub/src/inbox/receive_for_community.rs
lemmy_apub/src/inbox/shared_inbox.rs
lemmy_apub/src/inbox/user_inbox.rs
lemmy_apub/src/lib.rs
lemmy_apub/src/objects/comment.rs
lemmy_apub/src/objects/community.rs
lemmy_apub/src/objects/post.rs
lemmy_apub/src/objects/private_message.rs
lemmy_apub/src/objects/user.rs
lemmy_db/Cargo.toml
lemmy_db/src/aggregates/comment_aggregates.rs
lemmy_db/src/aggregates/community_aggregates.rs
lemmy_db/src/aggregates/post_aggregates.rs
lemmy_db/src/aggregates/site_aggregates.rs
lemmy_db/src/aggregates/user_aggregates.rs
lemmy_db/src/lib.rs
lemmy_db/src/source/activity.rs
lemmy_db/src/source/category.rs
lemmy_db/src/source/comment.rs
lemmy_db/src/source/comment_report.rs
lemmy_db/src/source/community.rs
lemmy_db/src/source/moderator.rs
lemmy_db/src/source/password_reset_request.rs
lemmy_db/src/source/post.rs
lemmy_db/src/source/post_report.rs
lemmy_db/src/source/private_message.rs
lemmy_db/src/source/site.rs
lemmy_db/src/source/user.rs
lemmy_db/src/source/user_mention.rs
lemmy_db/src/views/comment_report_view.rs
lemmy_db/src/views/comment_view.rs
lemmy_db/src/views/community/community_follower_view.rs
lemmy_db/src/views/community/community_moderator_view.rs
lemmy_db/src/views/community/community_user_ban_view.rs
lemmy_db/src/views/community/community_view.rs
lemmy_db/src/views/moderator/mod_add_community_view.rs
lemmy_db/src/views/moderator/mod_add_view.rs
lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
lemmy_db/src/views/moderator/mod_ban_view.rs
lemmy_db/src/views/moderator/mod_lock_post_view.rs
lemmy_db/src/views/moderator/mod_remove_comment_view.rs
lemmy_db/src/views/moderator/mod_remove_community_view.rs
lemmy_db/src/views/moderator/mod_remove_post_view.rs
lemmy_db/src/views/moderator/mod_sticky_post_view.rs
lemmy_db/src/views/post_report_view.rs
lemmy_db/src/views/post_view.rs
lemmy_db/src/views/private_message_view.rs
lemmy_db/src/views/site_view.rs
lemmy_db/src/views/user_mention_view.rs
lemmy_db/src/views/user_view.rs
lemmy_db_schema/Cargo.toml [new file with mode: 0644]
lemmy_db_schema/src/lib.rs [new file with mode: 0644]
lemmy_db_schema/src/schema.rs [moved from lemmy_db/src/schema.rs with 100% similarity]
lemmy_db_schema/src/source/activity.rs [new file with mode: 0644]
lemmy_db_schema/src/source/category.rs [new file with mode: 0644]
lemmy_db_schema/src/source/comment.rs [new file with mode: 0644]
lemmy_db_schema/src/source/comment_report.rs [new file with mode: 0644]
lemmy_db_schema/src/source/community.rs [new file with mode: 0644]
lemmy_db_schema/src/source/mod.rs [new file with mode: 0644]
lemmy_db_schema/src/source/moderator.rs [new file with mode: 0644]
lemmy_db_schema/src/source/password_reset_request.rs [new file with mode: 0644]
lemmy_db_schema/src/source/post.rs [new file with mode: 0644]
lemmy_db_schema/src/source/post_report.rs [new file with mode: 0644]
lemmy_db_schema/src/source/private_message.rs [new file with mode: 0644]
lemmy_db_schema/src/source/site.rs [new file with mode: 0644]
lemmy_db_schema/src/source/user.rs [new file with mode: 0644]
lemmy_db_schema/src/source/user_mention.rs [new file with mode: 0644]
lemmy_structs/Cargo.toml
lemmy_structs/src/lib.rs
lemmy_structs/src/site.rs
lemmy_websocket/Cargo.toml
lemmy_websocket/src/handlers.rs
src/code_migrations.rs
src/routes/feeds.rs
src/routes/webfinger.rs
tests/integration_test.rs

index 815cd20f69d4e55b5ca064fba84937a6302418a4..060fa8913c3d463c35566fbdb67862e8403381b3 100644 (file)
@@ -1718,6 +1718,7 @@ dependencies = [
  "lazy_static",
  "lemmy_apub",
  "lemmy_db",
+ "lemmy_db_schema",
  "lemmy_rate_limit",
  "lemmy_structs",
  "lemmy_utils",
@@ -1762,6 +1763,7 @@ dependencies = [
  "itertools",
  "lazy_static",
  "lemmy_db",
+ "lemmy_db_schema",
  "lemmy_structs",
  "lemmy_utils",
  "lemmy_websocket",
@@ -1790,6 +1792,7 @@ dependencies = [
  "diesel",
  "diesel_migrations",
  "lazy_static",
+ "lemmy_db_schema",
  "lemmy_utils",
  "log",
  "regex",
@@ -1801,6 +1804,18 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "lemmy_db_schema"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "diesel",
+ "log",
+ "serde 1.0.118",
+ "serde_json",
+ "url",
+]
+
 [[package]]
 name = "lemmy_rate_limit"
 version = "0.1.0"
@@ -1836,6 +1851,7 @@ dependencies = [
  "lemmy_api",
  "lemmy_apub",
  "lemmy_db",
+ "lemmy_db_schema",
  "lemmy_rate_limit",
  "lemmy_structs",
  "lemmy_utils",
@@ -1860,6 +1876,7 @@ dependencies = [
  "chrono",
  "diesel",
  "lemmy_db",
+ "lemmy_db_schema",
  "lemmy_utils",
  "log",
  "serde 1.0.118",
@@ -1901,6 +1918,7 @@ dependencies = [
  "chrono",
  "diesel",
  "lemmy_db",
+ "lemmy_db_schema",
  "lemmy_rate_limit",
  "lemmy_structs",
  "lemmy_utils",
index 40b28677591cdb631bbd1a5d0c390b2200664280..7bed59d1e9899fde53779a432dbcf17bcf9d83a1 100644 (file)
@@ -12,6 +12,7 @@ members = [
     "lemmy_apub",
     "lemmy_utils",
     "lemmy_db",
+    "lemmy_db_schema",
     "lemmy_structs",
     "lemmy_rate_limit",
     "lemmy_websocket",
@@ -21,6 +22,7 @@ members = [
 lemmy_api = { path = "./lemmy_api" }
 lemmy_apub = { path = "./lemmy_apub" }
 lemmy_utils = { path = "./lemmy_utils" }
+lemmy_db_schema = { path = "./lemmy_db_schema" }
 lemmy_db = { path = "./lemmy_db" }
 lemmy_structs = { path = "./lemmy_structs" }
 lemmy_rate_limit = { path = "./lemmy_rate_limit" }
index 94fd2d500892b73360ed9c34cbe86bc945c4adaa..f4a10924c6d4c7acc98bb9bd9fc70331b4cae79f 100644 (file)
@@ -12,6 +12,7 @@ path = "src/lib.rs"
 lemmy_apub = { path = "../lemmy_apub" }
 lemmy_utils = { path = "../lemmy_utils" }
 lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
 lemmy_structs = { path = "../lemmy_structs" }
 lemmy_rate_limit = { path = "../lemmy_rate_limit" }
 lemmy_websocket = { path = "../lemmy_websocket" }
index 4a0ab12b81c93509b983af031df54c3354e74ed6..f99730bdd3e1f0292a6b9b0ff629b655b7d09534 100644 (file)
@@ -1,5 +1,5 @@
 use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
-use lemmy_db::source::user::User_;
+use lemmy_db_schema::source::user::User_;
 use lemmy_utils::settings::Settings;
 use serde::{Deserialize, Serialize};
 
index e5f079ad2ae395aa556d41315ac5eedc2117e2dc..bafde6bfbeb67d3d0736e97e5e88b7039e90cfd6 100644 (file)
@@ -11,11 +11,7 @@ use crate::{
 use actix_web::web::Data;
 use lemmy_apub::{ApubLikeableType, ApubObjectType};
 use lemmy_db::{
-  source::{
-    comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm},
-    comment_report::{CommentReport, CommentReportForm},
-    moderator::{ModRemoveComment, ModRemoveCommentForm},
-  },
+  source::comment::Comment_,
   views::{
     comment_report_view::{CommentReportQueryBuilder, CommentReportView},
     comment_view::{CommentQueryBuilder, CommentView},
@@ -27,6 +23,7 @@ use lemmy_db::{
   Saveable,
   SortType,
 };
+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},
index c5ac408295f47a251e34cb17755f6292922868cc..405491bd2a2f8da76a28d75fe835677fc5f43e4c 100644 (file)
@@ -11,8 +11,11 @@ use anyhow::Context;
 use lemmy_apub::ActorType;
 use lemmy_db::{
   diesel_option_overwrite,
-  naive_now,
-  source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
+  source::{
+    comment::Comment_,
+    community::{CommunityModerator_, Community_},
+    post::Post_,
+  },
   views::{
     comment_view::CommentQueryBuilder,
     community::{
@@ -29,6 +32,10 @@ use lemmy_db::{
   Joinable,
   SortType,
 };
+use lemmy_db_schema::{
+  naive_now,
+  source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
+};
 use lemmy_structs::{blocking, community::*};
 use lemmy_utils::{
   apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
index eadb0d1ac9278e8e58318b09662173d61510daba..4b61539b4d9853b0af3048e31e70124e66a8f45f 100644 (file)
@@ -2,15 +2,19 @@ use crate::claims::Claims;
 use actix_web::{web, web::Data};
 use lemmy_db::{
   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..20b5b8d556e1e6f77fef4a1f137675adc0858526 100644 (file)
@@ -11,12 +11,7 @@ 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,
@@ -30,6 +25,14 @@ use lemmy_db::{
   Saveable,
   SortType,
 };
+use lemmy_db_schema::{
+  naive_now,
+  source::{
+    moderator::*,
+    post::*,
+    post_report::{PostReport, PostReportForm},
+  },
+};
 use lemmy_structs::{blocking, post::*};
 use lemmy_utils::{
   apub::{make_apub_endpoint, EndpointType},
index 16c6ecec9bd7063a440ac791be5148f695858669..e30e62303213683d5496352b47dd753686b42163 100644 (file)
@@ -11,8 +11,7 @@ use anyhow::Context;
 use lemmy_apub::fetcher::search_by_apub_id;
 use lemmy_db::{
   diesel_option_overwrite,
-  naive_now,
-  source::{category::*, moderator::*, site::*},
+  source::{category::Category_, site::Site_},
   views::{
     comment_view::CommentQueryBuilder,
     community::community_view::CommunityQueryBuilder,
@@ -35,6 +34,14 @@ use lemmy_db::{
   SearchType,
   SortType,
 };
+use lemmy_db_schema::{
+  naive_now,
+  source::{
+    category::Category,
+    moderator::*,
+    site::{Site, *},
+  },
+};
 use lemmy_structs::{blocking, site::*, user::Register};
 use lemmy_utils::{
   location_info,
index cca8dffb8909225d06ecb23c12ce5f9fef75ea60..34ef5022e17f470ed1ceada4a1dc81de2ea52e18 100644 (file)
@@ -16,17 +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,
@@ -47,6 +45,20 @@ use lemmy_db::{
   ListingType,
   SortType,
 };
+use lemmy_db_schema::{
+  naive_now,
+  source::{
+    comment::Comment,
+    community::*,
+    moderator::*,
+    password_reset_request::*,
+    post::Post,
+    private_message::*,
+    site::*,
+    user::*,
+    user_mention::*,
+  },
+};
 use lemmy_structs::{blocking, send_email_to_user, user::*};
 use lemmy_utils::{
   apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
index 2dd9a64a47bf45e5e16ac6546e2623d56168f120..e62ae9f0ca9b3b007181c111c3156d9d86e1efa7 100644 (file)
@@ -11,6 +11,7 @@ path = "src/lib.rs"
 [dependencies]
 lemmy_utils = { path = "../lemmy_utils" }
 lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
 lemmy_structs = { path = "../lemmy_structs" }
 lemmy_websocket = { path = "../lemmy_websocket" }
 diesel = "1.4.5"
index 32eb8c0ca5290b5028032e2ac1fdbe284b46820f..0149e9313307adc7d3062be4b467bc73f0608e60 100644 (file)
@@ -4,14 +4,10 @@ use activitystreams::{
   base::ExtendsExt,
 };
 use anyhow::Context;
-use lemmy_db::{
-  source::{
-    comment::{Comment, CommentLike, CommentLikeForm},
-    post::Post,
-  },
-  views::comment_view::CommentView,
-  Crud,
-  Likeable,
+use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Crud, Likeable};
+use lemmy_db_schema::source::{
+  comment::{Comment, CommentLike, CommentLikeForm},
+  post::Post,
 };
 use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
 use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
index 85dcc143d8989e60c7badb68773ef18cfbf3dfff..7e67204578c03e66b751cfc4425f43a0bf3e8989 100644 (file)
@@ -1,10 +1,7 @@
 use crate::activities::receive::get_actor_as_user;
 use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{
-  source::comment::{Comment, CommentLike},
-  views::comment_view::CommentView,
-  Likeable,
-};
+use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Likeable};
+use lemmy_db_schema::source::comment::{Comment, CommentLike};
 use lemmy_structs::{blocking, comment::CommentResponse};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
index 534da5cb70dda19f00fe12e2d143182422304714..932917b1e570fb2d213cc5c693abcc72319eb1a2 100644 (file)
@@ -5,10 +5,11 @@ use activitystreams::{
 };
 use anyhow::Context;
 use lemmy_db::{
-  source::community::Community,
+  source::community::Community_,
   views::community::community_view::CommunityView,
   ApubObject,
 };
+use lemmy_db_schema::source::community::Community;
 use lemmy_structs::{blocking, community::CommunityResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
index a66ddfb950a2bb6ac2c1a8181c92e181058074a2..f52bbea1a310704b8a196746f99fdd10947407ab 100644 (file)
@@ -5,7 +5,7 @@ use activitystreams::{
   error::DomainError,
 };
 use anyhow::{anyhow, Context};
-use lemmy_db::source::user::User_;
+use lemmy_db_schema::source::user::User_;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
 use log::debug;
index f09071129773077dcde6506cb992b9888f0c0017..8e20da75fb905084360b2db385df77e6d66e382a 100644 (file)
@@ -4,11 +4,8 @@ use activitystreams::{
   prelude::*,
 };
 use anyhow::Context;
-use lemmy_db::{
-  source::post::{Post, PostLike, PostLikeForm},
-  views::post_view::PostView,
-  Likeable,
-};
+use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm};
 use lemmy_structs::{blocking, post::PostResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
index 6827ded05f325bd8c8c95e1f9b092904c7f2d459..facaf65f193730be0dead566430bd2c19bbfbdf3 100644 (file)
@@ -1,10 +1,7 @@
 use crate::activities::receive::get_actor_as_user;
 use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{
-  source::post::{Post, PostLike},
-  views::post_view::PostView,
-  Likeable,
-};
+use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db_schema::source::post::{Post, PostLike};
 use lemmy_structs::{blocking, post::PostResponse};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
index 8f7952b6b067fa5bdf93a6039b75fe97217baad7..09c234cac2e9a2e93e46c2340886561a9e23cc79 100644 (file)
@@ -14,9 +14,10 @@ use activitystreams::{
 };
 use anyhow::{anyhow, Context};
 use lemmy_db::{
-  source::private_message::PrivateMessage,
+  source::private_message::PrivateMessage_,
   views::private_message_view::PrivateMessageView,
 };
+use lemmy_db_schema::source::private_message::PrivateMessage;
 use lemmy_structs::{blocking, user::PrivateMessageResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation};
index 6b417c2591b7062eee496370aef6f35f109a86b4..4ddd2d3217c60d38232abacd5a0e965c56a1347d 100644 (file)
@@ -26,11 +26,8 @@ use activitystreams::{
 };
 use anyhow::anyhow;
 use itertools::Itertools;
-use lemmy_db::{
-  source::{comment::Comment, community::Community, post::Post, user::User_},
-  Crud,
-  DbPool,
-};
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post, user::User_};
 use lemmy_structs::{blocking, WebFingerResponse};
 use lemmy_utils::{
   request::{retry, RecvError},
index 96152fa0d4b9d1e43caf84cc23a47ea5a27c4c40..035a8dfed8e0bde1c6aec6cf370316d8a08105d1 100644 (file)
@@ -23,11 +23,8 @@ use activitystreams::{
 };
 use anyhow::Context;
 use itertools::Itertools;
-use lemmy_db::{
-  source::community::Community,
-  views::community::community_follower_view::CommunityFollowerView,
-  DbPool,
-};
+use lemmy_db::{views::community::community_follower_view::CommunityFollowerView, DbPool};
+use lemmy_db_schema::source::community::Community;
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
index ec1ca67deb97f36f7a7b0fb9b947568d3db5d539..732a53c33fecb188fb1dcb7e52e6cf3be8619a39 100644 (file)
@@ -21,10 +21,8 @@ use activitystreams::{
   prelude::*,
   public,
 };
-use lemmy_db::{
-  source::{community::Community, post::Post, user::User_},
-  Crud,
-};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::{community::Community, post::Post, user::User_};
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 9abe70d663ec4d9955c86525b866f5ac8053bafb..bcbb303bc5f83d7197b552c7446be1e3c1c270c0 100644 (file)
@@ -16,10 +16,8 @@ use activitystreams::{
   },
   prelude::*,
 };
-use lemmy_db::{
-  source::{private_message::PrivateMessage, user::User_},
-  Crud,
-};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::{private_message::PrivateMessage, user::User_};
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 26c5a5d5611c23bd53976c05e96bed234f8675b6..cad20e9d95edd7f65a4ed7ac08ae97936d51cea9 100644 (file)
@@ -13,14 +13,10 @@ use activitystreams::{
   base::{AnyBase, BaseExt, ExtendsExt},
   object::ObjectExt,
 };
-use lemmy_db::{
-  source::{
-    community::{Community, CommunityFollower, CommunityFollowerForm},
-    user::User_,
-  },
-  ApubObject,
-  DbPool,
-  Followable,
+use lemmy_db::{ApubObject, DbPool, Followable};
+use lemmy_db_schema::source::{
+  community::{Community, CommunityFollower, CommunityFollowerForm},
+  user::User_,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
index d94c7cbf75bed9ba207bc0e8d8d63c043b5b3dc9..fe70d8e8bdae6e412074056d770b7b2408b08ce6 100644 (file)
@@ -19,10 +19,8 @@ use background_jobs::{
   WorkerConfig,
 };
 use itertools::Itertools;
-use lemmy_db::{
-  source::{community::Community, user::User_},
-  DbPool,
-};
+use lemmy_db::DbPool;
+use lemmy_db_schema::source::{community::Community, user::User_};
 use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
 use log::{debug, warn};
index ab7acf337d8c69672dce2caa06434218a720bcc1..2d8cfe799afc0100835f9311aa4843add1cb95bf 100644 (file)
@@ -1,7 +1,8 @@
 use activitystreams::unparsed::UnparsedMutExt;
 use activitystreams_ext::UnparsedExtension;
 use diesel::PgConnection;
-use lemmy_db::{source::category::Category, Crud};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::category::Category;
 use lemmy_utils::LemmyError;
 use serde::{Deserialize, Serialize};
 
index 39188f138e361d51360562accfe8694b6b3553e3..608302fabd4d444cce4e412a2eae06fe6502144a 100644 (file)
@@ -13,13 +13,7 @@ use anyhow::{anyhow, Context};
 use chrono::NaiveDateTime;
 use diesel::result::Error::NotFound;
 use lemmy_db::{
-  naive_now,
-  source::{
-    comment::Comment,
-    community::{Community, CommunityModerator, CommunityModeratorForm},
-    post::Post,
-    user::User_,
-  },
+  source::user::User,
   views::{
     comment_view::CommentView,
     community::community_view::CommunityView,
@@ -31,6 +25,15 @@ use lemmy_db::{
   Joinable,
   SearchType,
 };
+use lemmy_db_schema::{
+  naive_now,
+  source::{
+    comment::Comment,
+    community::{Community, CommunityModerator, CommunityModeratorForm},
+    post::Post,
+    user::User_,
+  },
+};
 use lemmy_structs::{blocking, site::SearchResponse};
 use lemmy_utils::{
   location_info,
index 16f4119027dafda6cfadd6b8a02f29630d9191f6..f71d542b063f85fb957c08b01028af7abab0b6ca 100644 (file)
@@ -4,7 +4,8 @@ use crate::{
 };
 use actix_web::{body::Body, web, web::Path, HttpResponse};
 use diesel::result::Error::NotFound;
-use lemmy_db::{source::comment::Comment, Crud};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::comment::Comment;
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index a17e2abf91e5b71bccbbe7a2a173e1d9a7feec80..45c576d24c09f8794dcf98bcdff223db0759fa59 100644 (file)
@@ -10,9 +10,10 @@ use activitystreams::{
 };
 use actix_web::{body::Body, web, HttpResponse};
 use lemmy_db::{
-  source::{community::Community, post::Post},
+  source::{community::Community_, post::Post_},
   views::community::community_follower_view::CommunityFollowerView,
 };
+use lemmy_db_schema::source::{community::Community, post::Post};
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index fee15b773594c11ba85904ad43ffa4d6b77fb706..5d45a725f3731f73291424f0c6554dd36b5792b7 100644 (file)
@@ -1,6 +1,7 @@
 use crate::APUB_JSON_CONTENT_TYPE;
 use actix_web::{body::Body, web, HttpResponse};
-use lemmy_db::source::activity::Activity;
+use lemmy_db::source::activity::Activity_;
+use lemmy_db_schema::source::activity::Activity;
 use lemmy_structs::blocking;
 use lemmy_utils::{settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
index 3d0c6ff8eb98a3c77e51c468c34b426732412ab7..8ade352960ca753525af8df68686a09c8c87f4be 100644 (file)
@@ -4,7 +4,8 @@ use crate::{
 };
 use actix_web::{body::Body, web, HttpResponse};
 use diesel::result::Error::NotFound;
-use lemmy_db::{source::post::Post, Crud};
+use lemmy_db::Crud;
+use lemmy_db_schema::source::post::Post;
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 8dcc8edabf7a889bd92176c21cb1046bcff13779..b01347e0d31f0e1f1297b6c32932434f62233b6d 100644 (file)
@@ -9,7 +9,8 @@ use activitystreams::{
   collection::{CollectionExt, OrderedCollection},
 };
 use actix_web::{body::Body, web, HttpResponse};
-use lemmy_db::source::user::User_;
+use lemmy_db::source::user::User;
+use lemmy_db_schema::source::user::User_;
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index ec4d30ae8f06f8c08f2e056c75eb0a44291485a3..f82da236bd176aaa3b6d74bb9e58847c78f7aa9f 100644 (file)
@@ -27,15 +27,16 @@ use activitystreams::{
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::{anyhow, Context};
 use lemmy_db::{
-  source::{
-    community::{Community, CommunityFollower, CommunityFollowerForm},
-    user::User_,
-  },
+  source::community::Community_,
   views::community::community_user_ban_view::CommunityUserBanView,
   ApubObject,
   DbPool,
   Followable,
 };
+use lemmy_db_schema::source::{
+  community::{Community, CommunityFollower, CommunityFollowerForm},
+  user::User_,
+};
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
index 415851883d8bc78a652cabf5d8d6eb2cbf413517..9b20093420cb842b660920bea0a6725af04958fb 100644 (file)
@@ -12,11 +12,8 @@ use activitystreams::{
 };
 use actix_web::HttpRequest;
 use anyhow::{anyhow, Context};
-use lemmy_db::{
-  source::{activity::Activity, community::Community, user::User_},
-  ApubObject,
-  DbPool,
-};
+use lemmy_db::{source::activity::Activity_, ApubObject, DbPool};
+use lemmy_db_schema::source::{activity::Activity, community::Community, user::User_};
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
index ff160144fb06214d3f347e4c71466185f9f2e3ec..31c5efba148df32cb3fc48baa678b25041d3c885 100644 (file)
@@ -41,11 +41,8 @@ use activitystreams::{
 };
 use anyhow::Context;
 use diesel::result::Error::NotFound;
-use lemmy_db::{
-  source::{comment::Comment, post::Post, site::Site},
-  ApubObject,
-  Crud,
-};
+use lemmy_db::{ApubObject, Crud};
+use lemmy_db_schema::source::{comment::Comment, post::Post, site::Site};
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
index d94c54f253a0284f9b3a8bb16db9dc56f49375c4..d6c08a3101533f5ad37a2aeefabd50a98edcf667 100644 (file)
@@ -15,7 +15,8 @@ use crate::{
 use activitystreams::{activity::ActorAndObject, prelude::*};
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::Context;
-use lemmy_db::{source::community::Community, ApubObject, DbPool};
+use lemmy_db::{ApubObject, DbPool};
+use lemmy_db_schema::source::community::Community;
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
index dc387739b582d58dac9ed4fd9b509b90d04e3d61..a9ca4b9444a938c8861a222c05043f8c865ea87d 100644 (file)
@@ -48,14 +48,11 @@ use activitystreams::{
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::{anyhow, Context};
 use diesel::NotFound;
-use lemmy_db::{
-  source::{
-    community::{Community, CommunityFollower},
-    private_message::PrivateMessage,
-    user::User_,
-  },
-  ApubObject,
-  Followable,
+use lemmy_db::{source::user::User, ApubObject, Followable};
+use lemmy_db_schema::source::{
+  community::{Community, CommunityFollower},
+  private_message::PrivateMessage,
+  user::User_,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, LemmyError};
index 78224c32ebd1ed867b970d6bcf176863ded76578..44786d1713a25318c24fae836c6a63db99522ce7 100644 (file)
@@ -22,10 +22,8 @@ use activitystreams::{
 };
 use activitystreams_ext::{Ext1, Ext2};
 use anyhow::{anyhow, Context};
-use lemmy_db::{
-  source::{activity::Activity, user::User_},
-  DbPool,
-};
+use lemmy_db::{source::activity::Activity_, DbPool};
+use lemmy_db_schema::source::{activity::Activity, user::User_};
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
index 0d1f6db80d442c1fa4852f5b8c49dea7a2d24140..e922724856be9b768e1c5ccf2d8a6b8d83fda88a 100644 (file)
@@ -23,15 +23,12 @@ use activitystreams::{
   prelude::*,
 };
 use anyhow::{anyhow, Context};
-use lemmy_db::{
-  source::{
-    comment::{Comment, CommentForm},
-    community::Community,
-    post::Post,
-    user::User_,
-  },
-  Crud,
-  DbPool,
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{
+  comment::{Comment, CommentForm},
+  community::Community,
+  post::Post,
+  user::User_,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::{
index 9d8210a6ac0112ce466868c12179ee1022fab67e..b408f7737ba3c6a3d848449903cce151b578bbff 100644 (file)
@@ -22,11 +22,10 @@ use activitystreams::{
 };
 use activitystreams_ext::Ext2;
 use anyhow::Context;
-use lemmy_db::{
+use lemmy_db::{views::community::community_moderator_view::CommunityModeratorView, DbPool};
+use lemmy_db_schema::{
   naive_now,
   source::community::{Community, CommunityForm},
-  views::community::community_moderator_view::CommunityModeratorView,
-  DbPool,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::{
index 9c9df5b1962cb3a2a97519f59d34d46b3bbcea90..499ac8020a97ef5daed0511ae3296a78f6b1db19 100644 (file)
@@ -20,14 +20,11 @@ use activitystreams::{
 };
 use activitystreams_ext::Ext1;
 use anyhow::Context;
-use lemmy_db::{
-  source::{
-    community::Community,
-    post::{Post, PostForm},
-    user::User_,
-  },
-  Crud,
-  DbPool,
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{
+  community::Community,
+  post::{Post, PostForm},
+  user::User_,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::{
index e69c28110d4dee60a8912cedf933733146cdbf2f..34f37c4cd1c6a2bbcfd412065823c1fe353566a6 100644 (file)
@@ -19,13 +19,10 @@ use activitystreams::{
   prelude::*,
 };
 use anyhow::Context;
-use lemmy_db::{
-  source::{
-    private_message::{PrivateMessage, PrivateMessageForm},
-    user::User_,
-  },
-  Crud,
-  DbPool,
+use lemmy_db::{Crud, DbPool};
+use lemmy_db_schema::source::{
+  private_message::{PrivateMessage, PrivateMessageForm},
+  user::User_,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, utils::convert_datetime, LemmyError};
index 8c3312d1f8f8a27ac79e303f4ae479f5fb94e8c1..3ec1548d4a1b272d40a75ba948916fc88e89a88a 100644 (file)
@@ -18,11 +18,10 @@ use activitystreams::{
 };
 use activitystreams_ext::Ext1;
 use anyhow::Context;
-use lemmy_db::{
+use lemmy_db::{ApubObject, DbPool};
+use lemmy_db_schema::{
   naive_now,
   source::user::{UserForm, User_},
-  ApubObject,
-  DbPool,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::{
index 5963f32cc331e8c81f77691417db884704627337..15dd749acaff940c7f98c68fea09fdf348be038f 100644 (file)
@@ -9,6 +9,7 @@ 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"] }
@@ -18,7 +19,7 @@ strum = "0.20.0"
 strum_macros = "0.20.1"
 log = "0.4.11"
 sha2 = "0.9.2"
-bcrypt = "0.9.0"
 url = { version = "2.2.0", features = ["serde"] }
 lazy_static = "1.4.0"
 regex = "1.4.2"
+bcrypt = "0.9.0"
index 7304dacc212b9f61fff16ccb61b0f0c27bf86132..c6b726755a99383b96e6a0b2075140dc0e8592a0 100644 (file)
@@ -1,5 +1,5 @@
-use crate::schema::comment_aggregates;
 use diesel::{result::Error, *};
+use lemmy_db_schema::schema::comment_aggregates;
 use serde::Serialize;
 
 #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
index 8c977bf0ca26056e46ecb79a9cf0e1c1e5a14dae..229652f00037d54925c813fc15e1c06e32bcdb1a 100644 (file)
@@ -1,5 +1,5 @@
-use crate::schema::community_aggregates;
 use diesel::{result::Error, *};
+use lemmy_db_schema::schema::community_aggregates;
 use serde::Serialize;
 
 #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
@@ -24,18 +24,18 @@ impl CommunityAggregates {
 mod tests {
   use crate::{
     aggregates::community_aggregates::CommunityAggregates,
-    source::{
-      comment::{Comment, CommentForm},
-      community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
-      post::{Post, PostForm},
-      user::{UserForm, User_},
-    },
     tests::establish_unpooled_connection,
     Crud,
     Followable,
     ListingType,
     SortType,
   };
+  use lemmy_db_schema::source::{
+    comment::{Comment, CommentForm},
+    community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
+    post::{Post, PostForm},
+    user::{UserForm, User_},
+  };
 
   #[test]
   fn test_crud() {
index dff16f9b102bcc7d0644a511d7bead2dd6626e92..01082ca06b226e0af6de60d8b1a7d3df7641cbc5 100644 (file)
@@ -1,5 +1,5 @@
-use crate::schema::post_aggregates;
 use diesel::{result::Error, *};
+use lemmy_db_schema::schema::post_aggregates;
 use serde::Serialize;
 
 #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
@@ -26,18 +26,18 @@ impl PostAggregates {
 mod tests {
   use crate::{
     aggregates::post_aggregates::PostAggregates,
-    source::{
-      comment::{Comment, CommentForm},
-      community::{Community, CommunityForm},
-      post::{Post, PostForm, PostLike, PostLikeForm},
-      user::{UserForm, User_},
-    },
     tests::establish_unpooled_connection,
     Crud,
     Likeable,
     ListingType,
     SortType,
   };
+  use lemmy_db_schema::source::{
+    comment::{Comment, CommentForm},
+    community::{Community, CommunityForm},
+    post::{Post, PostForm, PostLike, PostLikeForm},
+    user::{UserForm, User_},
+  };
 
   #[test]
   fn test_crud() {
index df3cad6f1ecff77fdc06c1d80728e41255c90ad3..70997a66a77dd7427216a49901afe49ad6e40e95 100644 (file)
@@ -1,5 +1,5 @@
-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, Clone)]
@@ -23,18 +23,17 @@ impl SiteAggregates {
 mod tests {
   use crate::{
     aggregates::site_aggregates::SiteAggregates,
-    source::{
-      comment::{Comment, CommentForm},
-      community::{Community, CommunityForm},
-      post::{Post, PostForm},
-      site::{Site, SiteForm},
-      user::{UserForm, User_},
-    },
     tests::establish_unpooled_connection,
     Crud,
     ListingType,
     SortType,
   };
+  use lemmy_db_schema::source::{
+    comment::{Comment, CommentForm},
+    community::{Community, CommunityForm},
+    post::{Post, PostForm},
+    user::{UserForm, User_},
+  };
 
   #[test]
   fn test_crud() {
index 104bf6f7dfc9350647a33d03dafe360c0c7e2fc4..e8981fd62f93a15026f3a2fd037e5f8ed6467c50 100644 (file)
@@ -1,5 +1,5 @@
-use crate::schema::user_aggregates;
 use diesel::{result::Error, *};
+use lemmy_db_schema::schema::user_aggregates;
 use serde::Serialize;
 
 #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
@@ -25,18 +25,18 @@ impl UserAggregates {
 mod tests {
   use crate::{
     aggregates::user_aggregates::UserAggregates,
-    source::{
-      comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
-      community::{Community, CommunityForm},
-      post::{Post, PostForm, PostLike, PostLikeForm},
-      user::{UserForm, User_},
-    },
     tests::establish_unpooled_connection,
     Crud,
     Likeable,
     ListingType,
     SortType,
   };
+  use lemmy_db_schema::source::{
+    comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+    community::{Community, CommunityForm},
+    post::{Post, PostForm, PostLike, PostLikeForm},
+    user::{UserForm, User_},
+  };
 
   #[test]
   fn test_crud() {
index 4df69ca432fb9da21e4d20a34a2c7afe4a2ebae4..8e3521478dcdf9eacb42149c5c286b9f451d6073 100644 (file)
@@ -9,14 +9,12 @@ extern crate lazy_static;
 #[macro_use]
 extern crate diesel_migrations;
 
-use chrono::NaiveDateTime;
 use diesel::{result::Error, *};
 use regex::Regex;
 use serde::{Deserialize, Serialize};
 use std::{env, env::VarError};
 
 pub mod aggregates;
-pub mod schema;
 pub mod source;
 pub mod views;
 
@@ -186,10 +184,6 @@ pub fn limit_and_offset(page: Option<i64>, limit: Option<i64>) -> (i64, i64) {
   (limit, offset)
 }
 
-pub fn naive_now() -> NaiveDateTime {
-  chrono::prelude::Utc::now().naive_utc()
-}
-
 pub fn is_email_regex(test: &str) -> bool {
   EMAIL_REGEX.is_match(test)
 }
index b4b54c6ed293ad2681af14e75b16bfad4102eeaa..d63b3b6bf861900efb1d91ca71aa738ccdd5e00e 100644 (file)
@@ -1,43 +1,21 @@
-use crate::{schema::activity, Crud};
+use crate::Crud;
 use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::source::activity::*;
 use log::debug;
 use serde::Serialize;
-use serde_json::Value;
 use std::{
   fmt::Debug,
   io::{Error as IoError, ErrorKind},
 };
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
-#[table_name = "activity"]
-pub struct Activity {
-  pub id: i32,
-  pub data: Value,
-  pub local: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub ap_id: Option<String>,
-  pub sensitive: Option<bool>,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "activity"]
-pub struct ActivityForm {
-  pub data: Value,
-  pub local: bool,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub ap_id: String,
-  pub sensitive: bool,
-}
-
 impl Crud<ActivityForm> for Activity {
   fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
-    use crate::schema::activity::dsl::*;
+    use lemmy_db_schema::schema::activity::dsl::*;
     activity.find(activity_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
-    use crate::schema::activity::dsl::*;
+    use lemmy_db_schema::schema::activity::dsl::*;
     insert_into(activity)
       .values(new_activity)
       .get_result::<Self>(conn)
@@ -48,25 +26,38 @@ impl Crud<ActivityForm> for Activity {
     activity_id: i32,
     new_activity: &ActivityForm,
   ) -> Result<Self, Error> {
-    use crate::schema::activity::dsl::*;
+    use lemmy_db_schema::schema::activity::dsl::*;
     diesel::update(activity.find(activity_id))
       .set(new_activity)
       .get_result::<Self>(conn)
   }
   fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
-    use crate::schema::activity::dsl::*;
+    use lemmy_db_schema::schema::activity::dsl::*;
     diesel::delete(activity.find(activity_id)).execute(conn)
   }
 }
 
-impl Activity {
-  pub fn insert<T>(
+pub trait Activity_ {
+  fn insert<T>(
+    conn: &PgConnection,
+    ap_id: String,
+    data: &T,
+    local: bool,
+    sensitive: bool,
+  ) -> Result<Activity, IoError>
+  where
+    T: Serialize + Debug;
+  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Activity, Error>;
+}
+
+impl Activity_ for Activity {
+  fn insert<T>(
     conn: &PgConnection,
     ap_id: String,
     data: &T,
     local: bool,
     sensitive: bool,
-  ) -> Result<Self, IoError>
+  ) -> Result<Activity, IoError>
   where
     T: Serialize + Debug,
   {
@@ -88,23 +79,18 @@ impl Activity {
     }
   }
 
-  pub fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
-    use crate::schema::activity::dsl::*;
+  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Activity, Error> {
+    use lemmy_db_schema::schema::activity::dsl::*;
     activity.filter(ap_id.eq(object_id)).first::<Self>(conn)
   }
 }
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    source::{
-      activity::{Activity, ActivityForm},
-      user::{UserForm, User_},
-    },
-    tests::establish_unpooled_connection,
-    Crud,
-    ListingType,
-    SortType,
+  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use lemmy_db_schema::source::{
+    activity::{Activity, ActivityForm},
+    user::{UserForm, User_},
   };
   use serde_json::Value;
 
index 95b65dc823ea31dc51f0bd8e6aafdb3193948565..c190ddf8ffa925e0e8723d9b50085beb3e0e9756 100644 (file)
@@ -1,22 +1,6 @@
-use crate::{
-  schema::{category, category::dsl::*},
-  Crud,
-};
+use crate::Crud;
 use diesel::{dsl::*, result::Error, *};
-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,
-}
+use lemmy_db_schema::{schema::category::dsl::*, source::category::*};
 
 impl Crud<CategoryForm> for Category {
   fn read(conn: &PgConnection, category_id: i32) -> Result<Self, Error> {
@@ -40,15 +24,20 @@ impl Crud<CategoryForm> for Category {
   }
 }
 
-impl Category {
-  pub fn list_all(conn: &PgConnection) -> Result<Vec<Self>, Error> {
+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::{source::category::Category, tests::establish_unpooled_connection};
+  use crate::tests::establish_unpooled_connection;
+  use lemmy_db_schema::source::category::Category;
 
   #[test]
   fn test_crud() {
index 380bdb3d157db6b1a259cc81dcf8416549c3cfa3..d70d7b6998763454eac1644be22878cf8ac2a8fd 100644 (file)
-use super::post::Post;
-use crate::{
+use crate::{ApubObject, Crud, Likeable, Saveable};
+use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
   naive_now,
-  schema::{comment, comment_alias_1, comment_like, comment_saved},
-  ApubObject,
-  Crud,
-  Likeable,
-  Saveable,
+  source::comment::{
+    Comment,
+    CommentForm,
+    CommentLike,
+    CommentLikeForm,
+    CommentSaved,
+    CommentSavedForm,
+  },
 };
-use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-use url::{ParseError, Url};
-
-// WITH RECURSIVE MyTree AS (
-//     SELECT * FROM comment WHERE parent_id IS NULL
-//     UNION ALL
-//     SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
-// )
-// SELECT * FROM MyTree;
-
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-#[belongs_to(Post)]
-#[table_name = "comment"]
-pub struct Comment {
-  pub id: i32,
-  pub creator_id: i32,
-  pub post_id: i32,
-  pub parent_id: Option<i32>,
-  pub content: String,
-  pub removed: bool,
-  pub read: bool, // Whether the recipient has read the comment or not
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: bool,
-  pub ap_id: String,
-  pub local: bool,
-}
-
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-#[belongs_to(Post)]
-#[table_name = "comment_alias_1"]
-pub struct CommentAlias1 {
-  pub id: i32,
-  pub creator_id: i32,
-  pub post_id: i32,
-  pub parent_id: Option<i32>,
-  pub content: String,
-  pub removed: bool,
-  pub read: bool, // Whether the recipient has read the comment or not
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: bool,
-  pub ap_id: String,
-  pub local: bool,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "comment"]
-pub struct CommentForm {
-  pub creator_id: i32,
-  pub post_id: i32,
-  pub parent_id: Option<i32>,
-  pub content: String,
-  pub removed: Option<bool>,
-  pub read: Option<bool>,
-  pub published: Option<chrono::NaiveDateTime>,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: Option<bool>,
-  pub ap_id: Option<String>,
-  pub local: bool,
-}
 
-impl CommentForm {
-  pub fn get_ap_id(&self) -> Result<Url, ParseError> {
-    Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
-  }
-}
-
-impl Crud<CommentForm> for Comment {
-  fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    comment.find(comment_id).first::<Self>(conn)
-  }
-
-  fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
-    use crate::schema::comment::dsl::*;
-    diesel::delete(comment.find(comment_id)).execute(conn)
-  }
-
-  fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    insert_into(comment)
-      .values(comment_form)
-      .get_result::<Self>(conn)
-  }
-
-  fn update(
+pub trait Comment_ {
+  fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result<Comment, Error>;
+  fn permadelete_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+  ) -> Result<Vec<Comment>, Error>;
+  fn update_deleted(
     conn: &PgConnection,
     comment_id: i32,
-    comment_form: &CommentForm,
-  ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    diesel::update(comment.find(comment_id))
-      .set(comment_form)
-      .get_result::<Self>(conn)
-  }
-}
-
-impl ApubObject<CommentForm> for Comment {
-  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
-  }
-
-  fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    insert_into(comment)
-      .values(comment_form)
-      .on_conflict(ap_id)
-      .do_update()
-      .set(comment_form)
-      .get_result::<Self>(conn)
-  }
-}
-
-impl Comment {
-  pub fn update_ap_id(
+    new_deleted: bool,
+  ) -> Result<Comment, Error>;
+  fn update_removed(
     conn: &PgConnection,
     comment_id: i32,
-    apub_id: String,
-  ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
+    new_removed: bool,
+  ) -> Result<Comment, Error>;
+  fn update_removed_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+    new_removed: bool,
+  ) -> Result<Vec<Comment>, Error>;
+  fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Comment, Error>;
+  fn update_content(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_content: &str,
+  ) -> Result<Comment, Error>;
+}
+
+impl Comment_ for Comment {
+  fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
 
     diesel::update(comment.find(comment_id))
       .set(ap_id.eq(apub_id))
       .get_result::<Self>(conn)
   }
 
-  pub fn permadelete_for_creator(
-    conn: &PgConnection,
-    for_creator_id: i32,
-  ) -> Result<Vec<Self>, Error> {
-    use crate::schema::comment::dsl::*;
+  fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Self>, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
     diesel::update(comment.filter(creator_id.eq(for_creator_id)))
       .set((
         content.eq("*Permananently Deleted*"),
@@ -150,82 +61,108 @@ impl Comment {
       .get_results::<Self>(conn)
   }
 
-  pub fn update_deleted(
+  fn update_deleted(
     conn: &PgConnection,
     comment_id: i32,
     new_deleted: bool,
   ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
+    use lemmy_db_schema::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set((deleted.eq(new_deleted), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_removed(
+  fn update_removed(
     conn: &PgConnection,
     comment_id: i32,
     new_removed: bool,
   ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
+    use lemmy_db_schema::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_removed_for_creator(
+  fn update_removed_for_creator(
     conn: &PgConnection,
     for_creator_id: i32,
     new_removed: bool,
   ) -> Result<Vec<Self>, Error> {
-    use crate::schema::comment::dsl::*;
+    use lemmy_db_schema::schema::comment::dsl::*;
     diesel::update(comment.filter(creator_id.eq(for_creator_id)))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_results::<Self>(conn)
   }
 
-  pub fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
+  fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set(read.eq(new_read))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_content(
+  fn update_content(
     conn: &PgConnection,
     comment_id: i32,
     new_content: &str,
   ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
+    use lemmy_db_schema::schema::comment::dsl::*;
     diesel::update(comment.find(comment_id))
       .set((content.eq(new_content), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
-#[belongs_to(Comment)]
-#[table_name = "comment_like"]
-pub struct CommentLike {
-  pub id: i32,
-  pub user_id: i32,
-  pub comment_id: i32,
-  pub post_id: i32, // TODO this is redundant
-  pub score: i16,
-  pub published: chrono::NaiveDateTime,
+impl Crud<CommentForm> for Comment {
+  fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    comment.find(comment_id).first::<Self>(conn)
+  }
+
+  fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    diesel::delete(comment.find(comment_id)).execute(conn)
+  }
+
+  fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    insert_into(comment)
+      .values(comment_form)
+      .get_result::<Self>(conn)
+  }
+
+  fn update(
+    conn: &PgConnection,
+    comment_id: i32,
+    comment_form: &CommentForm,
+  ) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    diesel::update(comment.find(comment_id))
+      .set(comment_form)
+      .get_result::<Self>(conn)
+  }
 }
 
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "comment_like"]
-pub struct CommentLikeForm {
-  pub user_id: i32,
-  pub comment_id: i32,
-  pub post_id: i32, // TODO this is redundant
-  pub score: i16,
+impl ApubObject<CommentForm> for Comment {
+  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
+  }
+
+  fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    insert_into(comment)
+      .values(comment_form)
+      .on_conflict(ap_id)
+      .do_update()
+      .set(comment_form)
+      .get_result::<Self>(conn)
+  }
 }
 
 impl Likeable<CommentLikeForm> for CommentLike {
   fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
-    use crate::schema::comment_like::dsl::*;
+    use lemmy_db_schema::schema::comment_like::dsl::*;
     insert_into(comment_like)
       .values(comment_like_form)
       .on_conflict((comment_id, user_id))
@@ -234,7 +171,7 @@ impl Likeable<CommentLikeForm> for CommentLike {
       .get_result::<Self>(conn)
   }
   fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result<usize, Error> {
-    use crate::schema::comment_like::dsl;
+    use lemmy_db_schema::schema::comment_like::dsl;
     diesel::delete(
       dsl::comment_like
         .filter(dsl::comment_id.eq(comment_id))
@@ -244,26 +181,9 @@ impl Likeable<CommentLikeForm> for CommentLike {
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Comment)]
-#[table_name = "comment_saved"]
-pub struct CommentSaved {
-  pub id: i32,
-  pub comment_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "comment_saved"]
-pub struct CommentSavedForm {
-  pub comment_id: i32,
-  pub user_id: i32,
-}
-
 impl Saveable<CommentSavedForm> for CommentSaved {
   fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
-    use crate::schema::comment_saved::dsl::*;
+    use lemmy_db_schema::schema::comment_saved::dsl::*;
     insert_into(comment_saved)
       .values(comment_saved_form)
       .on_conflict((comment_id, user_id))
@@ -272,7 +192,7 @@ impl Saveable<CommentSavedForm> for CommentSaved {
       .get_result::<Self>(conn)
   }
   fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
-    use crate::schema::comment_saved::dsl::*;
+    use lemmy_db_schema::schema::comment_saved::dsl::*;
     diesel::delete(
       comment_saved
         .filter(comment_id.eq(comment_saved_form.comment_id))
@@ -285,12 +205,19 @@ impl Saveable<CommentSavedForm> for CommentSaved {
 #[cfg(test)]
 mod tests {
   use crate::{
-    source::{comment::*, community::*, post::*, user::*},
     tests::establish_unpooled_connection,
     Crud,
+    Likeable,
     ListingType,
+    Saveable,
     SortType,
   };
+  use lemmy_db_schema::source::{
+    comment::*,
+    community::{Community, CommunityForm},
+    post::*,
+    user::{UserForm, User_},
+  };
 
   #[test]
   fn test_crud() {
index 7a28089f251e5a416b55006b77d037e5a614a3f7..bf42704eaa0ed69580e2ca9f047a457d52ec1e9c 100644 (file)
@@ -1,33 +1,9 @@
+use crate::Reportable;
 use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-
-use crate::{naive_now, schema::comment_report, source::comment::Comment, Reportable};
-
-#[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,
-}
+use lemmy_db_schema::{
+  naive_now,
+  source::comment_report::{CommentReport, CommentReportForm},
+};
 
 impl Reportable<CommentReportForm> for CommentReport {
   /// creates a comment report and returns it
@@ -35,7 +11,7 @@ impl Reportable<CommentReportForm> for CommentReport {
   /// * `conn` - the postgres connection
   /// * `comment_report_form` - the filled CommentReportForm to insert
   fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
-    use crate::schema::comment_report::dsl::*;
+    use lemmy_db_schema::schema::comment_report::dsl::*;
     insert_into(comment_report)
       .values(comment_report_form)
       .get_result::<Self>(conn)
@@ -47,7 +23,7 @@ impl Reportable<CommentReportForm> for CommentReport {
   /// * `report_id` - the id of the report to resolve
   /// * `by_resolver_id` - the id of the user resolving the report
   fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
-    use crate::schema::comment_report::dsl::*;
+    use lemmy_db_schema::schema::comment_report::dsl::*;
     update(comment_report.find(report_id))
       .set((
         resolved.eq(true),
@@ -63,7 +39,7 @@ impl Reportable<CommentReportForm> for CommentReport {
   /// * `report_id` - the id of the report to unresolve
   /// * `by_resolver_id` - the id of the user unresolving the report
   fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
-    use crate::schema::comment_report::dsl::*;
+    use lemmy_db_schema::schema::comment_report::dsl::*;
     update(comment_report.find(report_id))
       .set((
         resolved.eq(false),
index 0ad90da287c9f99fd1c6c691f80f5cdd562196cd..9a30ca4cde390c22c78c1c9e774a88ed023520ba 100644 (file)
@@ -1,6 +1,4 @@
 use crate::{
-  naive_now,
-  schema::{community, community_follower, community_moderator, community_user_ban},
   views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
   ApubObject,
   Bannable,
@@ -9,54 +7,24 @@ use crate::{
   Joinable,
 };
 use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "community"]
-pub struct Community {
-  pub id: i32,
-  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,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: bool,
-  pub nsfw: bool,
-  pub actor_id: String,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub icon: Option<String>,
-  pub banner: Option<String>,
-}
-
-/// A safe representation of community, without the sensitive info
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "community"]
-pub struct CommunitySafe {
-  pub id: i32,
-  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,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: bool,
-  pub nsfw: bool,
-  pub actor_id: String,
-  pub local: bool,
-  pub icon: Option<String>,
-  pub banner: Option<String>,
-}
+use lemmy_db_schema::{
+  naive_now,
+  source::community::{
+    Community,
+    CommunityFollower,
+    CommunityFollowerForm,
+    CommunityForm,
+    CommunityModerator,
+    CommunityModeratorForm,
+    CommunityUserBan,
+    CommunityUserBanForm,
+  },
+};
 
 mod safe_type {
-  use crate::{schema::community::columns::*, source::community::Community, ToSafe};
+  use crate::{source::community::Community, ToSafe};
+  use lemmy_db_schema::schema::community::*;
+
   type Columns = (
     id,
     name,
@@ -99,41 +67,19 @@ mod safe_type {
   }
 }
 
-#[derive(Insertable, AsChangeset, Debug)]
-#[table_name = "community"]
-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>,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: Option<bool>,
-  pub nsfw: bool,
-  pub actor_id: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: Option<chrono::NaiveDateTime>,
-  pub icon: Option<Option<String>>,
-  pub banner: Option<Option<String>>,
-}
-
 impl Crud<CommunityForm> for Community {
   fn read(conn: &PgConnection, community_id: i32) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+    use lemmy_db_schema::schema::community::dsl::*;
     community.find(community_id).first::<Self>(conn)
   }
 
   fn delete(conn: &PgConnection, community_id: i32) -> Result<usize, Error> {
-    use crate::schema::community::dsl::*;
+    use lemmy_db_schema::schema::community::dsl::*;
     diesel::delete(community.find(community_id)).execute(conn)
   }
 
   fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+    use lemmy_db_schema::schema::community::dsl::*;
     insert_into(community)
       .values(new_community)
       .get_result::<Self>(conn)
@@ -144,7 +90,7 @@ impl Crud<CommunityForm> for Community {
     community_id: i32,
     new_community: &CommunityForm,
   ) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+    use lemmy_db_schema::schema::community::dsl::*;
     diesel::update(community.find(community_id))
       .set(new_community)
       .get_result::<Self>(conn)
@@ -153,14 +99,14 @@ impl Crud<CommunityForm> for Community {
 
 impl ApubObject<CommunityForm> for Community {
   fn read_from_apub_id(conn: &PgConnection, for_actor_id: &str) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+    use lemmy_db_schema::schema::community::dsl::*;
     community
       .filter(actor_id.eq(for_actor_id))
       .first::<Self>(conn)
   }
 
   fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
-    use crate::schema::community::dsl::*;
+    use lemmy_db_schema::schema::community::dsl::*;
     insert_into(community)
       .values(community_form)
       .on_conflict(actor_id)
@@ -170,54 +116,81 @@ impl ApubObject<CommunityForm> for Community {
   }
 }
 
-impl Community {
-  pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+pub trait Community_ {
+  fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error>;
+  fn update_deleted(
+    conn: &PgConnection,
+    community_id: i32,
+    new_deleted: bool,
+  ) -> Result<Community, Error>;
+  fn update_removed(
+    conn: &PgConnection,
+    community_id: i32,
+    new_removed: bool,
+  ) -> Result<Community, Error>;
+  fn update_removed_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+    new_removed: bool,
+  ) -> Result<Vec<Community>, Error>;
+  fn update_creator(
+    conn: &PgConnection,
+    community_id: i32,
+    new_creator_id: i32,
+  ) -> Result<Community, Error>;
+  fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error>;
+  fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
+  fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool;
+}
+
+impl Community_ for Community {
+  fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
+    use lemmy_db_schema::schema::community::dsl::*;
     community
       .filter(local.eq(true))
       .filter(name.eq(community_name))
       .first::<Self>(conn)
   }
 
-  pub fn update_deleted(
+  fn update_deleted(
     conn: &PgConnection,
     community_id: i32,
     new_deleted: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+  ) -> Result<Community, Error> {
+    use lemmy_db_schema::schema::community::dsl::*;
     diesel::update(community.find(community_id))
       .set((deleted.eq(new_deleted), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_removed(
+  fn update_removed(
     conn: &PgConnection,
     community_id: i32,
     new_removed: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+  ) -> Result<Community, Error> {
+    use lemmy_db_schema::schema::community::dsl::*;
     diesel::update(community.find(community_id))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_removed_for_creator(
+  fn update_removed_for_creator(
     conn: &PgConnection,
     for_creator_id: i32,
     new_removed: bool,
-  ) -> Result<Vec<Self>, Error> {
-    use crate::schema::community::dsl::*;
+  ) -> 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)
   }
 
-  pub fn update_creator(
+  fn update_creator(
     conn: &PgConnection,
     community_id: i32,
     new_creator_id: i32,
-  ) -> Result<Self, Error> {
-    use crate::schema::community::dsl::*;
+  ) -> 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)
@@ -234,41 +207,24 @@ impl Community {
     Ok(mods_and_admins)
   }
 
-  pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
-    use crate::schema::community::dsl::*;
+  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)
   }
 
-  pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
+  fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
     Self::community_mods_and_admins(conn, community_id)
       .unwrap_or_default()
       .contains(&user_id)
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Community)]
-#[table_name = "community_moderator"]
-pub struct CommunityModerator {
-  pub id: i32,
-  pub community_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "community_moderator"]
-pub struct CommunityModeratorForm {
-  pub community_id: i32,
-  pub user_id: i32,
-}
-
 impl Joinable<CommunityModeratorForm> for CommunityModerator {
   fn join(
     conn: &PgConnection,
     community_user_form: &CommunityModeratorForm,
   ) -> Result<Self, Error> {
-    use crate::schema::community_moderator::dsl::*;
+    use lemmy_db_schema::schema::community_moderator::dsl::*;
     insert_into(community_moderator)
       .values(community_user_form)
       .get_result::<Self>(conn)
@@ -278,7 +234,7 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
     conn: &PgConnection,
     community_user_form: &CommunityModeratorForm,
   ) -> Result<usize, Error> {
-    use crate::schema::community_moderator::dsl::*;
+    use lemmy_db_schema::schema::community_moderator::dsl::*;
     diesel::delete(
       community_moderator
         .filter(community_id.eq(community_user_form.community_id))
@@ -288,17 +244,25 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
   }
 }
 
-impl CommunityModerator {
-  pub fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error> {
-    use crate::schema::community_moderator::dsl::*;
+pub trait CommunityModerator_ {
+  fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error>;
+  fn get_user_moderated_communities(
+    conn: &PgConnection,
+    for_user_id: i32,
+  ) -> Result<Vec<i32>, Error>;
+}
+
+impl CommunityModerator_ for CommunityModerator {
+  fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error> {
+    use lemmy_db_schema::schema::community_moderator::dsl::*;
     diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
   }
 
-  pub fn get_user_moderated_communities(
+  fn get_user_moderated_communities(
     conn: &PgConnection,
     for_user_id: i32,
   ) -> Result<Vec<i32>, Error> {
-    use crate::schema::community_moderator::dsl::*;
+    use lemmy_db_schema::schema::community_moderator::dsl::*;
     community_moderator
       .filter(user_id.eq(for_user_id))
       .select(community_id)
@@ -306,29 +270,12 @@ impl CommunityModerator {
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Community)]
-#[table_name = "community_user_ban"]
-pub struct CommunityUserBan {
-  pub id: i32,
-  pub community_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "community_user_ban"]
-pub struct CommunityUserBanForm {
-  pub community_id: i32,
-  pub user_id: i32,
-}
-
 impl Bannable<CommunityUserBanForm> for CommunityUserBan {
   fn ban(
     conn: &PgConnection,
     community_user_ban_form: &CommunityUserBanForm,
   ) -> Result<Self, Error> {
-    use crate::schema::community_user_ban::dsl::*;
+    use lemmy_db_schema::schema::community_user_ban::dsl::*;
     insert_into(community_user_ban)
       .values(community_user_ban_form)
       .get_result::<Self>(conn)
@@ -338,7 +285,7 @@ impl Bannable<CommunityUserBanForm> for CommunityUserBan {
     conn: &PgConnection,
     community_user_ban_form: &CommunityUserBanForm,
   ) -> Result<usize, Error> {
-    use crate::schema::community_user_ban::dsl::*;
+    use lemmy_db_schema::schema::community_user_ban::dsl::*;
     diesel::delete(
       community_user_ban
         .filter(community_id.eq(community_user_ban_form.community_id))
@@ -348,31 +295,12 @@ impl Bannable<CommunityUserBanForm> for CommunityUserBan {
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Community)]
-#[table_name = "community_follower"]
-pub struct CommunityFollower {
-  pub id: i32,
-  pub community_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-  pub pending: Option<bool>,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "community_follower"]
-pub struct CommunityFollowerForm {
-  pub community_id: i32,
-  pub user_id: i32,
-  pub pending: bool,
-}
-
 impl Followable<CommunityFollowerForm> for CommunityFollower {
   fn follow(
     conn: &PgConnection,
     community_follower_form: &CommunityFollowerForm,
   ) -> Result<Self, Error> {
-    use crate::schema::community_follower::dsl::*;
+    use lemmy_db_schema::schema::community_follower::dsl::*;
     insert_into(community_follower)
       .values(community_follower_form)
       .on_conflict((community_id, user_id))
@@ -384,7 +312,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
   where
     Self: Sized,
   {
-    use crate::schema::community_follower::dsl::*;
+    use lemmy_db_schema::schema::community_follower::dsl::*;
     diesel::update(
       community_follower
         .filter(community_id.eq(community_id_))
@@ -397,7 +325,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
     conn: &PgConnection,
     community_follower_form: &CommunityFollowerForm,
   ) -> Result<usize, Error> {
-    use crate::schema::community_follower::dsl::*;
+    use lemmy_db_schema::schema::community_follower::dsl::*;
     diesel::delete(
       community_follower
         .filter(community_id.eq(&community_follower_form.community_id))
@@ -408,7 +336,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
   // TODO: this function name only makes sense if you call it with a remote community. for a local
   //       community, it will also return true if only remote followers exist
   fn has_local_followers(conn: &PgConnection, community_id_: i32) -> Result<bool, Error> {
-    use crate::schema::community_follower::dsl::*;
+    use lemmy_db_schema::schema::community_follower::dsl::*;
     diesel::select(exists(
       community_follower.filter(community_id.eq(community_id_)),
     ))
@@ -419,11 +347,15 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
 #[cfg(test)]
 mod tests {
   use crate::{
-    source::{community::*, user::*},
     tests::establish_unpooled_connection,
+    Bannable,
+    Crud,
+    Followable,
+    Joinable,
     ListingType,
     SortType,
   };
+  use lemmy_db_schema::source::{community::*, user::*};
 
   #[test]
   fn test_crud() {
index 766c17fc57860dbafff4752206acab85b13ce1fe..b0a17d6d5f89edcf65431ca46b458deb0c038e66 100644 (file)
-use crate::{
-  schema::{
-    mod_add,
-    mod_add_community,
-    mod_ban,
-    mod_ban_from_community,
-    mod_lock_post,
-    mod_remove_comment,
-    mod_remove_community,
-    mod_remove_post,
-    mod_sticky_post,
-  },
-  Crud,
-};
+use crate::Crud;
 use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_remove_post"]
-pub struct ModRemovePost {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_remove_post"]
-pub struct ModRemovePostForm {
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-}
+use lemmy_db_schema::source::moderator::*;
 
 impl Crud<ModRemovePostForm> for ModRemovePost {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_remove_post::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_post::dsl::*;
     mod_remove_post.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
-    use crate::schema::mod_remove_post::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_post::dsl::*;
     insert_into(mod_remove_post)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
-    use crate::schema::mod_remove_post::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_post::dsl::*;
     diesel::update(mod_remove_post.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_lock_post"]
-pub struct ModLockPost {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub locked: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_lock_post"]
-pub struct ModLockPostForm {
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub locked: Option<bool>,
-}
-
 impl Crud<ModLockPostForm> for ModLockPost {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_lock_post::dsl::*;
+    use lemmy_db_schema::schema::mod_lock_post::dsl::*;
     mod_lock_post.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
-    use crate::schema::mod_lock_post::dsl::*;
+    use lemmy_db_schema::schema::mod_lock_post::dsl::*;
     insert_into(mod_lock_post)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
-    use crate::schema::mod_lock_post::dsl::*;
+    use lemmy_db_schema::schema::mod_lock_post::dsl::*;
     diesel::update(mod_lock_post.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_sticky_post"]
-pub struct ModStickyPost {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub stickied: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_sticky_post"]
-pub struct ModStickyPostForm {
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub stickied: Option<bool>,
-}
-
 impl Crud<ModStickyPostForm> for ModStickyPost {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_sticky_post::dsl::*;
+    use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
     mod_sticky_post.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
-    use crate::schema::mod_sticky_post::dsl::*;
+    use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
     insert_into(mod_sticky_post)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
-    use crate::schema::mod_sticky_post::dsl::*;
+    use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
     diesel::update(mod_sticky_post.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_remove_comment"]
-pub struct ModRemoveComment {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub comment_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_remove_comment"]
-pub struct ModRemoveCommentForm {
-  pub mod_user_id: i32,
-  pub comment_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-}
-
 impl Crud<ModRemoveCommentForm> for ModRemoveComment {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_remove_comment::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
     mod_remove_comment.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
-    use crate::schema::mod_remove_comment::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
     insert_into(mod_remove_comment)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
-    use crate::schema::mod_remove_comment::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
     diesel::update(mod_remove_comment.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_remove_community"]
-pub struct ModRemoveCommunity {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub community_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_remove_community"]
-pub struct ModRemoveCommunityForm {
-  pub mod_user_id: i32,
-  pub community_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-}
-
 impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_remove_community::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_community::dsl::*;
     mod_remove_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
-    use crate::schema::mod_remove_community::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_community::dsl::*;
     insert_into(mod_remove_community)
       .values(form)
       .get_result::<Self>(conn)
@@ -215,45 +104,21 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
     from_id: i32,
     form: &ModRemoveCommunityForm,
   ) -> Result<Self, Error> {
-    use crate::schema::mod_remove_community::dsl::*;
+    use lemmy_db_schema::schema::mod_remove_community::dsl::*;
     diesel::update(mod_remove_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_ban_from_community"]
-pub struct ModBanFromCommunity {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub community_id: i32,
-  pub reason: Option<String>,
-  pub banned: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_ban_from_community"]
-pub struct ModBanFromCommunityForm {
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub community_id: i32,
-  pub reason: Option<String>,
-  pub banned: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-}
-
 impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_ban_from_community::dsl::*;
+    use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
     mod_ban_from_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
-    use crate::schema::mod_ban_from_community::dsl::*;
+    use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
     insert_into(mod_ban_from_community)
       .values(form)
       .get_result::<Self>(conn)
@@ -264,126 +129,66 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
     from_id: i32,
     form: &ModBanFromCommunityForm,
   ) -> Result<Self, Error> {
-    use crate::schema::mod_ban_from_community::dsl::*;
+    use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
     diesel::update(mod_ban_from_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_ban"]
-pub struct ModBan {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub reason: Option<String>,
-  pub banned: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_ban"]
-pub struct ModBanForm {
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub reason: Option<String>,
-  pub banned: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-}
-
 impl Crud<ModBanForm> for ModBan {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_ban::dsl::*;
+    use lemmy_db_schema::schema::mod_ban::dsl::*;
     mod_ban.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
-    use crate::schema::mod_ban::dsl::*;
+    use lemmy_db_schema::schema::mod_ban::dsl::*;
     insert_into(mod_ban).values(form).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
-    use crate::schema::mod_ban::dsl::*;
+    use lemmy_db_schema::schema::mod_ban::dsl::*;
     diesel::update(mod_ban.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_add_community"]
-pub struct ModAddCommunity {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub community_id: i32,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_add_community"]
-pub struct ModAddCommunityForm {
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub community_id: i32,
-  pub removed: Option<bool>,
-}
-
 impl Crud<ModAddCommunityForm> for ModAddCommunity {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_add_community::dsl::*;
+    use lemmy_db_schema::schema::mod_add_community::dsl::*;
     mod_add_community.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
-    use crate::schema::mod_add_community::dsl::*;
+    use lemmy_db_schema::schema::mod_add_community::dsl::*;
     insert_into(mod_add_community)
       .values(form)
       .get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
-    use crate::schema::mod_add_community::dsl::*;
+    use lemmy_db_schema::schema::mod_add_community::dsl::*;
     diesel::update(mod_add_community.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "mod_add"]
-pub struct ModAdd {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "mod_add"]
-pub struct ModAddForm {
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub removed: Option<bool>,
-}
-
 impl Crud<ModAddForm> for ModAdd {
   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
-    use crate::schema::mod_add::dsl::*;
+    use lemmy_db_schema::schema::mod_add::dsl::*;
     mod_add.find(from_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
-    use crate::schema::mod_add::dsl::*;
+    use lemmy_db_schema::schema::mod_add::dsl::*;
     insert_into(mod_add).values(form).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
-    use crate::schema::mod_add::dsl::*;
+    use lemmy_db_schema::schema::mod_add::dsl::*;
     diesel::update(mod_add.find(from_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -392,12 +197,8 @@ impl Crud<ModAddForm> for ModAdd {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    source::{comment::*, community::*, moderator::*, post::*, user::*},
-    tests::establish_unpooled_connection,
-    ListingType,
-    SortType,
-  };
+  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
 
   // use Crud;
   #[test]
index 0cf0169f0ad4a18c79afd3d475d3ad5d5b0d428f..9ca8dab6821f62b18075d5cc91472101fd5089bd 100644 (file)
@@ -1,29 +1,10 @@
-use crate::{
-  schema::{password_reset_request, password_reset_request::dsl::*},
-  Crud,
-};
+use crate::Crud;
 use diesel::{dsl::*, result::Error, PgConnection, *};
+use lemmy_db_schema::{schema::password_reset_request::dsl::*, source::password_reset_request::*};
 use sha2::{Digest, Sha256};
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
-#[table_name = "password_reset_request"]
-pub struct PasswordResetRequest {
-  pub id: i32,
-  pub user_id: i32,
-  pub token_encrypted: String,
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "password_reset_request"]
-pub struct PasswordResetRequestForm {
-  pub user_id: i32,
-  pub token_encrypted: String,
-}
-
 impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
   fn read(conn: &PgConnection, password_reset_request_id: i32) -> Result<Self, Error> {
-    use crate::schema::password_reset_request::dsl::*;
     password_reset_request
       .find(password_reset_request_id)
       .first::<Self>(conn)
@@ -44,11 +25,24 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
   }
 }
 
-impl PasswordResetRequest {
-  pub fn create_token(conn: &PgConnection, from_user_id: i32, token: &str) -> Result<Self, Error> {
+pub trait PasswordResetRequest_ {
+  fn create_token(
+    conn: &PgConnection,
+    from_user_id: i32,
+    token: &str,
+  ) -> Result<PasswordResetRequest, Error>;
+  fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error>;
+}
+
+impl PasswordResetRequest_ for PasswordResetRequest {
+  fn create_token(
+    conn: &PgConnection,
+    from_user_id: i32,
+    token: &str,
+  ) -> Result<PasswordResetRequest, Error> {
     let mut hasher = Sha256::new();
     hasher.update(token);
-    let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.finalize().to_vec());
+    let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
 
     let form = PasswordResetRequestForm {
       user_id: from_user_id,
@@ -57,35 +51,29 @@ impl PasswordResetRequest {
 
     Self::create(&conn, &form)
   }
-  pub fn read_from_token(conn: &PgConnection, token: &str) -> Result<Self, Error> {
+  fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
     let mut hasher = Sha256::new();
     hasher.update(token);
-    let token_hash: String = PasswordResetRequest::bytes_to_hex(hasher.finalize().to_vec());
+    let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
     password_reset_request
       .filter(token_encrypted.eq(token_hash))
       .filter(published.gt(now - 1.days()))
       .first::<Self>(conn)
   }
+}
 
-  fn bytes_to_hex(bytes: Vec<u8>) -> String {
-    let mut str = String::new();
-    for byte in bytes {
-      str = format!("{}{:02x}", str, byte);
-    }
-    str
+fn bytes_to_hex(bytes: Vec<u8>) -> String {
+  let mut str = String::new();
+  for byte in bytes {
+    str = format!("{}{:02x}", str, byte);
   }
+  str
 }
 
 #[cfg(test)]
 mod tests {
-  use super::super::user::*;
-  use crate::{
-    source::password_reset_request::PasswordResetRequest,
-    tests::establish_unpooled_connection,
-    Crud,
-    ListingType,
-    SortType,
-  };
+  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
 
   #[test]
   fn test_crud() {
index 948791ea4ae1f8abfd75b40a06a8a0e30e5113d1..c681adbe47bf1282b7c5e188c63d0852121bc258 100644 (file)
-use crate::{
+use crate::{ApubObject, Crud, Likeable, Readable, Saveable};
+use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
   naive_now,
-  schema::{post, post_like, post_read, post_saved},
-  ApubObject,
-  Crud,
-  Likeable,
-  Readable,
-  Saveable,
+  source::post::{
+    Post,
+    PostForm,
+    PostLike,
+    PostLikeForm,
+    PostRead,
+    PostReadForm,
+    PostSaved,
+    PostSavedForm,
+  },
 };
-use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-use url::{ParseError, Url};
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "post"]
-pub struct Post {
-  pub id: i32,
-  pub name: String,
-  pub url: Option<String>,
-  pub body: Option<String>,
-  pub creator_id: i32,
-  pub community_id: i32,
-  pub removed: bool,
-  pub locked: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: bool,
-  pub nsfw: bool,
-  pub stickied: bool,
-  pub embed_title: Option<String>,
-  pub embed_description: Option<String>,
-  pub embed_html: Option<String>,
-  pub thumbnail_url: Option<String>,
-  pub ap_id: String,
-  pub local: bool,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "post"]
-pub struct PostForm {
-  pub name: String,
-  pub url: Option<String>,
-  pub body: Option<String>,
-  pub creator_id: i32,
-  pub community_id: i32,
-  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>,
-  pub embed_html: Option<String>,
-  pub thumbnail_url: Option<String>,
-  pub ap_id: Option<String>,
-  pub local: bool,
-}
-
-impl PostForm {
-  pub fn get_ap_id(&self) -> Result<Url, ParseError> {
-    Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
-  }
-}
 
 impl Crud<PostForm> for Post {
   fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+    use lemmy_db_schema::schema::post::dsl::*;
     post.find(post_id).first::<Self>(conn)
   }
 
   fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> {
-    use crate::schema::post::dsl::*;
+    use lemmy_db_schema::schema::post::dsl::*;
     diesel::delete(post.find(post_id)).execute(conn)
   }
 
   fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+    use lemmy_db_schema::schema::post::dsl::*;
     insert_into(post).values(new_post).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, post_id: i32, new_post: &PostForm) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+    use lemmy_db_schema::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set(new_post)
       .get_result::<Self>(conn)
   }
 }
 
-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 {
+  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())
@@ -119,19 +67,16 @@ impl Post {
       .load::<Self>(conn)
   }
 
-  pub fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+  fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
 
     diesel::update(post.find(post_id))
       .set(ap_id.eq(apub_id))
       .get_result::<Self>(conn)
   }
 
-  pub fn permadelete_for_creator(
-    conn: &PgConnection,
-    for_creator_id: i32,
-  ) -> Result<Vec<Self>, Error> {
-    use crate::schema::post::dsl::*;
+  fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Self>, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
 
     let perma_deleted = "*Permananently Deleted*";
     let perma_deleted_url = "https://deleted.com";
@@ -147,35 +92,27 @@ impl Post {
       .get_results::<Self>(conn)
   }
 
-  pub fn update_deleted(
-    conn: &PgConnection,
-    post_id: i32,
-    new_deleted: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+  fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set((deleted.eq(new_deleted), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_removed(
-    conn: &PgConnection,
-    post_id: i32,
-    new_removed: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+  fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set((removed.eq(new_removed), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_removed_for_creator(
+  fn update_removed_for_creator(
     conn: &PgConnection,
     for_creator_id: i32,
     for_community_id: Option<i32>,
     new_removed: bool,
   ) -> Result<Vec<Self>, Error> {
-    use crate::schema::post::dsl::*;
+    use lemmy_db_schema::schema::post::dsl::*;
 
     let mut update = diesel::update(post).into_boxed();
     update = update.filter(creator_id.eq(for_creator_id));
@@ -189,51 +126,45 @@ impl Post {
       .get_results::<Self>(conn)
   }
 
-  pub fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+  fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set(locked.eq(new_locked))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_stickied(
-    conn: &PgConnection,
-    post_id: i32,
-    new_stickied: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
+  fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
     diesel::update(post.find(post_id))
       .set(stickied.eq(new_stickied))
       .get_result::<Self>(conn)
   }
 
-  pub fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
+  fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
     user_id == post_creator_id
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Post)]
-#[table_name = "post_like"]
-pub struct PostLike {
-  pub id: i32,
-  pub post_id: i32,
-  pub user_id: i32,
-  pub score: i16,
-  pub published: chrono::NaiveDateTime,
-}
+impl ApubObject<PostForm> for Post {
+  fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    post.filter(ap_id.eq(object_id)).first::<Self>(conn)
+  }
 
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "post_like"]
-pub struct PostLikeForm {
-  pub post_id: i32,
-  pub user_id: i32,
-  pub score: i16,
+  fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    insert_into(post)
+      .values(post_form)
+      .on_conflict(ap_id)
+      .do_update()
+      .set(post_form)
+      .get_result::<Self>(conn)
+  }
 }
 
 impl Likeable<PostLikeForm> for PostLike {
   fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
-    use crate::schema::post_like::dsl::*;
+    use lemmy_db_schema::schema::post_like::dsl::*;
     insert_into(post_like)
       .values(post_like_form)
       .on_conflict((post_id, user_id))
@@ -242,7 +173,7 @@ impl Likeable<PostLikeForm> for PostLike {
       .get_result::<Self>(conn)
   }
   fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result<usize, Error> {
-    use crate::schema::post_like::dsl;
+    use lemmy_db_schema::schema::post_like::dsl;
     diesel::delete(
       dsl::post_like
         .filter(dsl::post_id.eq(post_id))
@@ -252,26 +183,9 @@ impl Likeable<PostLikeForm> for PostLike {
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Post)]
-#[table_name = "post_saved"]
-pub struct PostSaved {
-  pub id: i32,
-  pub post_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "post_saved"]
-pub struct PostSavedForm {
-  pub post_id: i32,
-  pub user_id: i32,
-}
-
 impl Saveable<PostSavedForm> for PostSaved {
   fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
-    use crate::schema::post_saved::dsl::*;
+    use lemmy_db_schema::schema::post_saved::dsl::*;
     insert_into(post_saved)
       .values(post_saved_form)
       .on_conflict((post_id, user_id))
@@ -280,7 +194,7 @@ impl Saveable<PostSavedForm> for PostSaved {
       .get_result::<Self>(conn)
   }
   fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
-    use crate::schema::post_saved::dsl::*;
+    use lemmy_db_schema::schema::post_saved::dsl::*;
     diesel::delete(
       post_saved
         .filter(post_id.eq(post_saved_form.post_id))
@@ -290,37 +204,16 @@ impl Saveable<PostSavedForm> for PostSaved {
   }
 }
 
-#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
-#[belongs_to(Post)]
-#[table_name = "post_read"]
-pub struct PostRead {
-  pub id: i32,
-
-  pub post_id: i32,
-
-  pub user_id: i32,
-
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "post_read"]
-pub struct PostReadForm {
-  pub post_id: i32,
-
-  pub user_id: i32,
-}
-
 impl Readable<PostReadForm> for PostRead {
   fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
-    use crate::schema::post_read::dsl::*;
+    use lemmy_db_schema::schema::post_read::dsl::*;
     insert_into(post_read)
       .values(post_read_form)
       .get_result::<Self>(conn)
   }
 
   fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
-    use crate::schema::post_read::dsl::*;
+    use lemmy_db_schema::schema::post_read::dsl::*;
     diesel::delete(
       post_read
         .filter(post_id.eq(post_read_form.post_id))
@@ -332,11 +225,10 @@ impl Readable<PostReadForm> for PostRead {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    source::{community::*, post::*, user::*},
-    tests::establish_unpooled_connection,
-    ListingType,
-    SortType,
+  use crate::{source::post::*, tests::establish_unpooled_connection, ListingType, SortType};
+  use lemmy_db_schema::source::{
+    community::{Community, CommunityForm},
+    user::*,
   };
 
   #[test]
index 0e597959a2d14c8be655c06ac527f8b38122cfe7..e81dc7c04be8f6d81fb1263dc92146b58cec27a5 100644 (file)
@@ -1,37 +1,6 @@
+use crate::Reportable;
 use diesel::{dsl::*, result::Error, *};
-use serde::{Deserialize, Serialize};
-
-use crate::{naive_now, schema::post_report, source::post::Post, Reportable};
-
-#[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,
-}
+use lemmy_db_schema::{naive_now, source::post_report::*};
 
 impl Reportable<PostReportForm> for PostReport {
   /// creates a post report and returns it
@@ -39,7 +8,7 @@ impl Reportable<PostReportForm> for PostReport {
   /// * `conn` - the postgres connection
   /// * `post_report_form` - the filled CommentReportForm to insert
   fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
-    use crate::schema::post_report::dsl::*;
+    use lemmy_db_schema::schema::post_report::dsl::*;
     insert_into(post_report)
       .values(post_report_form)
       .get_result::<Self>(conn)
@@ -51,7 +20,7 @@ impl Reportable<PostReportForm> for PostReport {
   /// * `report_id` - the id of the report to resolve
   /// * `by_resolver_id` - the id of the user resolving the report
   fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
-    use crate::schema::post_report::dsl::*;
+    use lemmy_db_schema::schema::post_report::dsl::*;
     update(post_report.find(report_id))
       .set((
         resolved.eq(true),
@@ -67,7 +36,7 @@ impl Reportable<PostReportForm> for PostReport {
   /// * `report_id` - the id of the report to unresolve
   /// * `by_resolver_id` - the id of the user unresolving the report
   fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
-    use crate::schema::post_report::dsl::*;
+    use lemmy_db_schema::schema::post_report::dsl::*;
     update(post_report.find(report_id))
       .set((
         resolved.eq(false),
index f474cf9ac303d3607b6a2de940151bcac0df116b..b49ed8f4f30c04f2dbc3cb036e98c46e9230b4d0 100644 (file)
@@ -1,44 +1,15 @@
-use crate::{naive_now, schema::private_message, ApubObject, Crud};
+use crate::{ApubObject, Crud};
 use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "private_message"]
-pub struct PrivateMessage {
-  pub id: i32,
-  pub creator_id: i32,
-  pub recipient_id: i32,
-  pub content: String,
-  pub deleted: bool,
-  pub read: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub ap_id: String,
-  pub local: bool,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "private_message"]
-pub struct PrivateMessageForm {
-  pub creator_id: i32,
-  pub recipient_id: i32,
-  pub content: String,
-  pub deleted: Option<bool>,
-  pub read: Option<bool>,
-  pub published: Option<chrono::NaiveDateTime>,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub ap_id: Option<String>,
-  pub local: bool,
-}
+use lemmy_db_schema::{naive_now, source::private_message::*};
 
 impl Crud<PrivateMessageForm> for PrivateMessage {
   fn read(conn: &PgConnection, private_message_id: i32) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+    use lemmy_db_schema::schema::private_message::dsl::*;
     private_message.find(private_message_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+    use lemmy_db_schema::schema::private_message::dsl::*;
     insert_into(private_message)
       .values(private_message_form)
       .get_result::<Self>(conn)
@@ -49,7 +20,7 @@ impl Crud<PrivateMessageForm> for PrivateMessage {
     private_message_id: i32,
     private_message_form: &PrivateMessageForm,
   ) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+    use lemmy_db_schema::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set(private_message_form)
       .get_result::<Self>(conn)
@@ -61,14 +32,14 @@ impl ApubObject<PrivateMessageForm> for PrivateMessage {
   where
     Self: Sized,
   {
-    use crate::schema::private_message::dsl::*;
+    use lemmy_db_schema::schema::private_message::dsl::*;
     private_message
       .filter(ap_id.eq(object_id))
       .first::<Self>(conn)
   }
 
   fn upsert(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+    use lemmy_db_schema::schema::private_message::dsl::*;
     insert_into(private_message)
       .values(private_message_form)
       .on_conflict(ap_id)
@@ -78,54 +49,84 @@ impl ApubObject<PrivateMessageForm> for PrivateMessage {
   }
 }
 
-impl PrivateMessage {
-  pub fn update_ap_id(
+pub trait PrivateMessage_ {
+  fn update_ap_id(
     conn: &PgConnection,
     private_message_id: i32,
     apub_id: String,
-  ) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+  ) -> Result<PrivateMessage, Error>;
+  fn update_content(
+    conn: &PgConnection,
+    private_message_id: i32,
+    new_content: &str,
+  ) -> Result<PrivateMessage, Error>;
+  fn update_deleted(
+    conn: &PgConnection,
+    private_message_id: i32,
+    new_deleted: bool,
+  ) -> Result<PrivateMessage, Error>;
+  fn update_read(
+    conn: &PgConnection,
+    private_message_id: i32,
+    new_read: bool,
+  ) -> Result<PrivateMessage, Error>;
+  fn mark_all_as_read(
+    conn: &PgConnection,
+    for_recipient_id: i32,
+  ) -> Result<Vec<PrivateMessage>, Error>;
+}
+
+impl PrivateMessage_ for PrivateMessage {
+  fn update_ap_id(
+    conn: &PgConnection,
+    private_message_id: i32,
+    apub_id: String,
+  ) -> Result<PrivateMessage, Error> {
+    use lemmy_db_schema::schema::private_message::dsl::*;
 
     diesel::update(private_message.find(private_message_id))
       .set(ap_id.eq(apub_id))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_content(
+  fn update_content(
     conn: &PgConnection,
     private_message_id: i32,
     new_content: &str,
-  ) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+  ) -> Result<PrivateMessage, Error> {
+    use lemmy_db_schema::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set((content.eq(new_content), updated.eq(naive_now())))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_deleted(
+  fn update_deleted(
     conn: &PgConnection,
     private_message_id: i32,
     new_deleted: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+  ) -> Result<PrivateMessage, Error> {
+    use lemmy_db_schema::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set(deleted.eq(new_deleted))
       .get_result::<Self>(conn)
   }
 
-  pub fn update_read(
+  fn update_read(
     conn: &PgConnection,
     private_message_id: i32,
     new_read: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::private_message::dsl::*;
+  ) -> Result<PrivateMessage, Error> {
+    use lemmy_db_schema::schema::private_message::dsl::*;
     diesel::update(private_message.find(private_message_id))
       .set(read.eq(new_read))
       .get_result::<Self>(conn)
   }
 
-  pub fn mark_all_as_read(conn: &PgConnection, for_recipient_id: i32) -> Result<Vec<Self>, Error> {
-    use crate::schema::private_message::dsl::*;
+  fn mark_all_as_read(
+    conn: &PgConnection,
+    for_recipient_id: i32,
+  ) -> Result<Vec<PrivateMessage>, Error> {
+    use lemmy_db_schema::schema::private_message::dsl::*;
     diesel::update(
       private_message
         .filter(recipient_id.eq(for_recipient_id))
@@ -138,12 +139,8 @@ impl PrivateMessage {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    source::{private_message::*, user::*},
-    tests::establish_unpooled_connection,
-    ListingType,
-    SortType,
-  };
+  use crate::{tests::establish_unpooled_connection, ListingType, SortType};
+  use lemmy_db_schema::source::{private_message::*, user::*};
 
   #[test]
   fn test_crud() {
index 8775191e1b3bf2773c38db16375f8434d6457524..2510f46c9d4d4f76d7031ed573ab5c429348ef01 100644 (file)
@@ -1,71 +1,45 @@
-use crate::{naive_now, schema::site, Crud};
+use crate::Crud;
 use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
-#[table_name = "site"]
-pub struct Site {
-  pub id: i32,
-  pub name: String,
-  pub description: Option<String>,
-  pub creator_id: i32,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub enable_downvotes: bool,
-  pub open_registration: bool,
-  pub enable_nsfw: bool,
-  pub icon: Option<String>,
-  pub banner: Option<String>,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "site"]
-pub struct SiteForm {
-  pub name: String,
-  pub description: Option<String>,
-  pub creator_id: i32,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub enable_downvotes: bool,
-  pub open_registration: bool,
-  pub enable_nsfw: bool,
-  // when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
-  pub icon: Option<Option<String>>,
-  pub banner: Option<Option<String>>,
-}
+use lemmy_db_schema::{naive_now, source::site::*};
 
 impl Crud<SiteForm> for Site {
   fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
-    use crate::schema::site::dsl::*;
+    use lemmy_db_schema::schema::site::dsl::*;
     site.first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
-    use crate::schema::site::dsl::*;
+    use lemmy_db_schema::schema::site::dsl::*;
     insert_into(site).values(new_site).get_result::<Self>(conn)
   }
 
   fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
-    use crate::schema::site::dsl::*;
+    use lemmy_db_schema::schema::site::dsl::*;
     diesel::update(site.find(site_id))
       .set(new_site)
       .get_result::<Self>(conn)
   }
   fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
-    use crate::schema::site::dsl::*;
+    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)
   }
 }
index 601e6e8c680f261f56a89d06329bf0bee9355417..7461f4b45675d1b979d965e71c1876bc40e87b94 100644 (file)
@@ -1,68 +1,17 @@
-use crate::{
-  is_email_regex,
-  naive_now,
-  schema::{user_, user_::dsl::*, user_alias_1, user_alias_2},
-  ApubObject,
-  Crud,
-};
+use crate::{is_email_regex, ApubObject, Crud};
 use bcrypt::{hash, DEFAULT_COST};
 use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
+  naive_now,
+  schema::user_::dsl::*,
+  source::user::{UserForm, User_},
+};
 use lemmy_utils::settings::Settings;
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_"]
-pub struct User_ {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub password_encrypted: String,
-  pub email: Option<String>,
-  pub avatar: Option<String>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub show_nsfw: bool,
-  pub theme: String,
-  pub default_sort_type: i16,
-  pub default_listing_type: i16,
-  pub lang: String,
-  pub show_avatars: bool,
-  pub send_notifications_to_email: bool,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<String>,
-  pub deleted: bool,
-}
-
-/// A safe representation of user, without the sensitive info
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_"]
-pub struct UserSafe {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub avatar: Option<String>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<String>,
-  pub deleted: bool,
-}
 
 mod safe_type {
-  use crate::{schema::user_::columns::*, source::user::User_, ToSafe};
+  use crate::ToSafe;
+  use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
+
   type Columns = (
     id,
     name,
@@ -103,58 +52,10 @@ mod safe_type {
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_1"]
-pub struct UserAlias1 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub password_encrypted: String,
-  pub email: Option<String>,
-  pub avatar: Option<String>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub show_nsfw: bool,
-  pub theme: String,
-  pub default_sort_type: i16,
-  pub default_listing_type: i16,
-  pub lang: String,
-  pub show_avatars: bool,
-  pub send_notifications_to_email: bool,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<String>,
-  pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_1"]
-pub struct UserSafeAlias1 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub avatar: Option<String>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<String>,
-  pub deleted: bool,
-}
-
 mod safe_type_alias_1 {
-  use crate::{schema::user_alias_1::columns::*, source::user::UserAlias1, ToSafe};
+  use crate::ToSafe;
+  use lemmy_db_schema::{schema::user_alias_1::columns::*, source::user::UserAlias1};
+
   type Columns = (
     id,
     name,
@@ -195,58 +96,10 @@ mod safe_type_alias_1 {
   }
 }
 
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_2"]
-pub struct UserAlias2 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub password_encrypted: String,
-  pub email: Option<String>,
-  pub avatar: Option<String>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub show_nsfw: bool,
-  pub theme: String,
-  pub default_sort_type: i16,
-  pub default_listing_type: i16,
-  pub lang: String,
-  pub show_avatars: bool,
-  pub send_notifications_to_email: bool,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<String>,
-  pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_2"]
-pub struct UserSafeAlias2 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub avatar: Option<String>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<String>,
-  pub deleted: bool,
-}
-
 mod safe_type_alias_2 {
-  use crate::{schema::user_alias_2::columns::*, source::user::UserAlias2, ToSafe};
+  use crate::ToSafe;
+  use lemmy_db_schema::{schema::user_alias_2::columns::*, source::user::UserAlias2};
+
   type Columns = (
     id,
     name,
@@ -287,35 +140,6 @@ mod safe_type_alias_2 {
   }
 }
 
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "user_"]
-pub struct UserForm {
-  pub name: String,
-  pub preferred_username: Option<Option<String>>,
-  pub password_encrypted: String,
-  pub admin: bool,
-  pub banned: Option<bool>,
-  pub email: Option<Option<String>>,
-  pub avatar: Option<Option<String>>,
-  pub published: Option<chrono::NaiveDateTime>,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub show_nsfw: bool,
-  pub theme: String,
-  pub default_sort_type: i16,
-  pub default_listing_type: i16,
-  pub lang: String,
-  pub show_avatars: bool,
-  pub send_notifications_to_email: bool,
-  pub matrix_user_id: Option<Option<String>>,
-  pub actor_id: Option<String>,
-  pub bio: Option<Option<String>>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: Option<chrono::NaiveDateTime>,
-  pub banner: Option<Option<String>>,
-}
-
 impl Crud<UserForm> for User_ {
   fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
     user_
@@ -338,7 +162,7 @@ impl Crud<UserForm> for User_ {
 
 impl ApubObject<UserForm> for User_ {
   fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
-    use crate::schema::user_::dsl::*;
+    use lemmy_db_schema::schema::user_::dsl::*;
     user_
       .filter(deleted.eq(false))
       .filter(actor_id.eq(object_id))
@@ -355,8 +179,26 @@ impl ApubObject<UserForm> for User_ {
   }
 }
 
-impl User_ {
-  pub fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
+pub trait User {
+  fn register(conn: &PgConnection, form: &UserForm) -> Result<User_, Error>;
+  fn update_password(conn: &PgConnection, user_id: i32, new_password: &str)
+    -> Result<User_, Error>;
+  fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<User_, Error>;
+  fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<User_, Error>;
+  fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<User_, Error>;
+  fn find_by_email_or_username(
+    conn: &PgConnection,
+    username_or_email: &str,
+  ) -> Result<User_, Error>;
+  fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error>;
+  fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error>;
+  fn get_profile_url(&self, hostname: &str) -> String;
+  fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
+  fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
+}
+
+impl User for User_ {
+  fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
     let mut edited_user = form.clone();
     let password_hash =
       hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
@@ -366,11 +208,7 @@ impl User_ {
   }
 
   // TODO do more individual updates like these
-  pub fn update_password(
-    conn: &PgConnection,
-    user_id: i32,
-    new_password: &str,
-  ) -> Result<Self, Error> {
+  fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) -> Result<Self, Error> {
     let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
 
     diesel::update(user_.find(user_id))
@@ -381,7 +219,7 @@ impl User_ {
       .get_result::<Self>(conn)
   }
 
-  pub fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
+  fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
     user_
       .filter(local.eq(true))
       .filter(deleted.eq(false))
@@ -389,19 +227,19 @@ impl User_ {
       .first::<Self>(conn)
   }
 
-  pub fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
+  fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
     diesel::update(user_.find(user_id))
       .set(admin.eq(added))
       .get_result::<Self>(conn)
   }
 
-  pub fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
+  fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
     diesel::update(user_.find(user_id))
       .set(banned.eq(ban))
       .get_result::<Self>(conn)
   }
 
-  pub fn find_by_email_or_username(
+  fn find_by_email_or_username(
     conn: &PgConnection,
     username_or_email: &str,
   ) -> Result<Self, Error> {
@@ -412,7 +250,7 @@ impl User_ {
     }
   }
 
-  pub fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
+  fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
     user_
       .filter(deleted.eq(false))
       .filter(local.eq(true))
@@ -420,7 +258,7 @@ impl User_ {
       .first::<User_>(conn)
   }
 
-  pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
+  fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
     user_
       .filter(deleted.eq(false))
       .filter(local.eq(true))
@@ -428,7 +266,7 @@ impl User_ {
       .first::<User_>(conn)
   }
 
-  pub fn get_profile_url(&self, hostname: &str) -> String {
+  fn get_profile_url(&self, hostname: &str) -> String {
     format!(
       "{}://{}/u/{}",
       Settings::get().get_protocol_string(),
@@ -437,13 +275,13 @@ impl User_ {
     )
   }
 
-  pub fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
+  fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
     diesel::update(user_.find(user_id))
       .set((last_refreshed_at.eq(naive_now()),))
       .get_result::<Self>(conn)
   }
 
-  pub fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
+  fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
     diesel::update(user_.find(user_id))
       .set((
         preferred_username.eq::<Option<String>>(None),
index bf53cb4200504854fbdaecce9515158fe1eec54a..64406f989f8c0db5116b4674e67298abad0a07df 100644 (file)
@@ -1,35 +1,15 @@
-use super::comment::Comment;
-use crate::{schema::user_mention, Crud};
+use crate::Crud;
 use diesel::{dsl::*, result::Error, *};
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
-#[belongs_to(Comment)]
-#[table_name = "user_mention"]
-pub struct UserMention {
-  pub id: i32,
-  pub recipient_id: i32,
-  pub comment_id: i32,
-  pub read: bool,
-  pub published: chrono::NaiveDateTime,
-}
-
-#[derive(Insertable, AsChangeset)]
-#[table_name = "user_mention"]
-pub struct UserMentionForm {
-  pub recipient_id: i32,
-  pub comment_id: i32,
-  pub read: Option<bool>,
-}
+use lemmy_db_schema::source::user_mention::*;
 
 impl Crud<UserMentionForm> for UserMention {
   fn read(conn: &PgConnection, user_mention_id: i32) -> Result<Self, Error> {
-    use crate::schema::user_mention::dsl::*;
+    use lemmy_db_schema::schema::user_mention::dsl::*;
     user_mention.find(user_mention_id).first::<Self>(conn)
   }
 
   fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
-    use crate::schema::user_mention::dsl::*;
+    use lemmy_db_schema::schema::user_mention::dsl::*;
     // since the return here isnt utilized, we dont need to do an update
     // but get_result doesnt return the existing row here
     insert_into(user_mention)
@@ -45,27 +25,42 @@ impl Crud<UserMentionForm> for UserMention {
     user_mention_id: i32,
     user_mention_form: &UserMentionForm,
   ) -> Result<Self, Error> {
-    use crate::schema::user_mention::dsl::*;
+    use lemmy_db_schema::schema::user_mention::dsl::*;
     diesel::update(user_mention.find(user_mention_id))
       .set(user_mention_form)
       .get_result::<Self>(conn)
   }
 }
 
-impl UserMention {
-  pub fn update_read(
+pub trait UserMention_ {
+  fn update_read(
     conn: &PgConnection,
     user_mention_id: i32,
     new_read: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::user_mention::dsl::*;
+  ) -> Result<UserMention, Error>;
+  fn mark_all_as_read(
+    conn: &PgConnection,
+    for_recipient_id: i32,
+  ) -> Result<Vec<UserMention>, Error>;
+}
+
+impl UserMention_ for UserMention {
+  fn update_read(
+    conn: &PgConnection,
+    user_mention_id: i32,
+    new_read: bool,
+  ) -> Result<UserMention, Error> {
+    use lemmy_db_schema::schema::user_mention::dsl::*;
     diesel::update(user_mention.find(user_mention_id))
       .set(read.eq(new_read))
       .get_result::<Self>(conn)
   }
 
-  pub fn mark_all_as_read(conn: &PgConnection, for_recipient_id: i32) -> Result<Vec<Self>, Error> {
-    use crate::schema::user_mention::dsl::*;
+  fn mark_all_as_read(
+    conn: &PgConnection,
+    for_recipient_id: i32,
+  ) -> Result<Vec<UserMention>, Error> {
+    use lemmy_db_schema::schema::user_mention::dsl::*;
     diesel::update(
       user_mention
         .filter(recipient_id.eq(for_recipient_id))
@@ -78,11 +73,13 @@ impl UserMention {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    source::{comment::*, community::*, post::*, user::*, user_mention::*},
-    tests::establish_unpooled_connection,
-    ListingType,
-    SortType,
+  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use lemmy_db_schema::source::{
+    comment::*,
+    community::{Community, CommunityForm},
+    post::*,
+    user::*,
+    user_mention::*,
   };
 
   #[test]
index 540bb756988b036f6b65389f82d10469c20f9101..7a260cd59bf3c5d14476c2df5897d2ec3c5f7e2f 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
   source::{
     comment::Comment,
@@ -8,11 +9,7 @@ use crate::{
     post::Post,
     user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
   },
-  views::ViewToVec,
-  MaybeOptional,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, PartialEq, Serialize, Clone)]
index 8c7584471914445333eeb4d09cdb4463889bbd5e..1b114e19057473e8deea406a01c3dee75895cba4 100644 (file)
@@ -3,6 +3,14 @@ use crate::{
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
+  views::ViewToVec,
+  ListingType,
+  MaybeOptional,
+  SortType,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{
     comment,
     comment_aggregates,
@@ -22,13 +30,7 @@ use crate::{
     post::Post,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  ListingType,
-  MaybeOptional,
-  SortType,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, PartialEq, Serialize, Clone)]
@@ -416,14 +418,8 @@ impl ViewToVec for CommentView {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    source::{comment::*, community::*, post::*, user::*},
-    tests::establish_unpooled_connection,
-    views::comment_view::*,
-    Crud,
-    Likeable,
-    *,
-  };
+  use crate::{tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *};
+  use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
 
   #[test]
   fn test_crud() {
index 7de9cc3a4b92fea761b20f7041323280051ba92e..e7ba0e4a6005c13ad6e9a5de0e8faf32f231b9d3 100644 (file)
@@ -1,13 +1,12 @@
-use crate::{
+use crate::{views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, community_follower, user_},
   source::{
     community::{Community, CommunitySafe},
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 751e46232c715a697f1afa16c0bf66652d146f80..6800853ea2a368bc13802543a0c2cb93b804763a 100644 (file)
@@ -1,13 +1,12 @@
-use crate::{
+use crate::{views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, community_moderator, user_},
   source::{
     community::{Community, CommunitySafe},
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 3358f01b2d0e5b42cc09706d7ecd3cea967eb4a2..1c26ebcf1bbce375d0a70503e1dd95a91fb0d22d 100644 (file)
@@ -1,12 +1,12 @@
-use crate::{
+use crate::ToSafe;
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, community_user_ban, user_},
   source::{
     community::{Community, CommunitySafe},
     user::{UserSafe, User_},
   },
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index fcc707c0682b0ae178630e5bf742a73bdb9e640b..11962d79a92098df5297abd786d569fcfa520d17 100644 (file)
@@ -3,18 +3,20 @@ use crate::{
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
+  views::ViewToVec,
+  MaybeOptional,
+  SortType,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{category, community, community_aggregates, community_follower, user_},
   source::{
     category::Category,
     community::{Community, CommunityFollower, CommunitySafe},
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  MaybeOptional,
-  SortType,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 402c5fe1b29d81df411c4d4e71636c8e1220e70b..302d37a0b347d8e2a615c56cae4c9a1c2c7cce6a 100644 (file)
@@ -1,15 +1,13 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, mod_add_community, user_, user_alias_1},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModAddCommunity,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index fc1993d4542865b3ebec7be3844e4f7fd4dde46c..8f586a6ff8b35c20042bfdd5406144d1f6794ee9 100644 (file)
@@ -1,14 +1,12 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{mod_add, user_, user_alias_1},
   source::{
     moderator::ModAdd,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 6ad232e875bda7460736b6efee15ebdb16e08537..0ed52dd25f83dfa96424690894ae9ee85d4354ca 100644 (file)
@@ -1,15 +1,13 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, mod_ban_from_community, user_, user_alias_1},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModBanFromCommunity,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 28214d2da1fe30086689bccb167c2bd02ab621b5..98cf1969f3dfa5d5f1b46278b0b5f4b8be22c6c7 100644 (file)
@@ -1,14 +1,12 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{mod_ban, user_, user_alias_1},
   source::{
     moderator::ModBan,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 8182b54f755e85f1a78b9e40076f0d595d5e37fb..dbe81c5c385e5991dfcbc8d3fb5943247bcc17fa 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, mod_lock_post, post, user_},
   source::{
     community::{Community, CommunitySafe},
@@ -7,10 +8,7 @@ use crate::{
     post::Post,
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index fb4b7772417e26512a61c3fa78edd823bfb49c53..04aab30af35e4f5f1b1463897380bb5fc9c2283f 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
   source::{
     comment::Comment,
@@ -8,10 +9,7 @@ use crate::{
     post::Post,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index daaf6d78f33c397d12a71a88f28b4ab028c2463b..37ffe540262fbb7e651b1186fc21ef11e17cd05b 100644 (file)
@@ -1,15 +1,13 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, mod_remove_community, user_},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModRemoveCommunity,
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 613a8a5414e275a44e60a48f286ed5aaa233f60c..21bf1b867a3b128778695321336a2846fc4f4a58 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, mod_remove_post, post, user_},
   source::{
     community::{Community, CommunitySafe},
@@ -7,10 +8,7 @@ use crate::{
     post::Post,
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 9a3d118b9f369d869010c007556f033a1cfbfb2b..8512e07935808fe345f6e96cbe699a567cba2cee 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, mod_sticky_post, post, user_},
   source::{
     community::{Community, CommunitySafe},
@@ -7,10 +8,7 @@ use crate::{
     post::Post,
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index d39adfd5ce67466992b70766b5de5fd6526340f3..37d6275cd0abb067711d9366681eff52cc83644c 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{community, post, post_report, user_, user_alias_1, user_alias_2},
   source::{
     community::{Community, CommunitySafe},
@@ -7,11 +8,7 @@ use crate::{
     post_report::PostReport,
     user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
   },
-  views::ViewToVec,
-  MaybeOptional,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, PartialEq, Serialize, Clone)]
index 9a4dbbadb5fe5039094182d8742d77dc191c1c1f..3cfee1b371300c14ec24e7e19c28a912209b73ac 100644 (file)
@@ -3,6 +3,14 @@ use crate::{
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
+  views::ViewToVec,
+  ListingType,
+  MaybeOptional,
+  SortType,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{
     community,
     community_follower,
@@ -19,13 +27,7 @@ use crate::{
     post::{Post, PostRead, PostSaved},
     user::{UserSafe, User_},
   },
-  views::ViewToVec,
-  ListingType,
-  MaybeOptional,
-  SortType,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, PartialEq, Serialize, Clone)]
@@ -406,13 +408,13 @@ impl ViewToVec for PostView {
 mod tests {
   use crate::{
     aggregates::post_aggregates::PostAggregates,
-    source::{community::*, post::*, user::*},
     tests::establish_unpooled_connection,
     views::post_view::{PostQueryBuilder, PostView},
     Crud,
     Likeable,
     *,
   };
+  use lemmy_db_schema::source::{community::*, post::*, user::*};
 
   #[test]
   fn test_crud() {
index 43d960a8af06c3180a7f8815ddff7c1511f507be..f439a75d54128f0235038e54cbc3ddbd36d995e9 100644 (file)
@@ -1,15 +1,12 @@
-use crate::{
-  limit_and_offset,
+use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{private_message, user_, user_alias_1},
   source::{
     private_message::PrivateMessage,
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
   },
-  views::ViewToVec,
-  MaybeOptional,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, PartialEq, Serialize, Clone)]
index 3c605277e10e646f16c35967da86771e26439e38..7772ccdcef6b37da0ad2e81e25bc6a2c691a614a 100644 (file)
@@ -1,13 +1,12 @@
-use crate::{
-  aggregates::site_aggregates::SiteAggregates,
+use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{site, site_aggregates, user_},
   source::{
     site::Site,
     user::{UserSafe, User_},
   },
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
index 67616fbc33bd76a697ca13ceae999506e5149cbc..2cd1cd3c87dca2426e6d4985f79c5ed38cb0aaa2 100644 (file)
@@ -2,6 +2,13 @@ use crate::{
   aggregates::comment_aggregates::CommentAggregates,
   functions::hot_rank,
   limit_and_offset,
+  views::ViewToVec,
+  MaybeOptional,
+  SortType,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use lemmy_db_schema::{
   schema::{
     comment,
     comment_aggregates,
@@ -22,12 +29,7 @@ use crate::{
     user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
     user_mention::UserMention,
   },
-  views::ViewToVec,
-  MaybeOptional,
-  SortType,
-  ToSafe,
 };
-use diesel::{result::Error, *};
 use serde::Serialize;
 
 #[derive(Debug, PartialEq, Serialize, Clone)]
index 587ebf617c8da777a0544d08d9be9a4d70339b85..f3109011e91a13d50c3f863da89b967c2ab65d92 100644 (file)
@@ -2,14 +2,16 @@ use crate::{
   aggregates::user_aggregates::UserAggregates,
   fuzzy_search,
   limit_and_offset,
-  schema::{user_, user_aggregates},
-  source::user::{UserSafe, User_},
   views::ViewToVec,
   MaybeOptional,
   SortType,
   ToSafe,
 };
 use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
+  schema::{user_, user_aggregates},
+  source::user::{UserSafe, User_},
+};
 use serde::Serialize;
 
 #[derive(Debug, Serialize, Clone)]
diff --git a/lemmy_db_schema/Cargo.toml b/lemmy_db_schema/Cargo.toml
new file mode 100644 (file)
index 0000000..99b7399
--- /dev/null
@@ -0,0 +1,12 @@
+[package]
+name = "lemmy_db_schema"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+chrono = { version = "0.4.19", features = ["serde"] }
+serde = { version = "1.0.118", features = ["derive"] }
+serde_json = { version = "1.0.60", features = ["preserve_order"] }
+log = "0.4.11"
+url = { version = "2.2.0", features = ["serde"] }
diff --git a/lemmy_db_schema/src/lib.rs b/lemmy_db_schema/src/lib.rs
new file mode 100644 (file)
index 0000000..3868a3b
--- /dev/null
@@ -0,0 +1,12 @@
+#[macro_use]
+extern crate diesel;
+
+use chrono::NaiveDateTime;
+
+pub mod schema;
+pub mod source;
+
+// TODO: can probably move this back to lemmy_db
+pub fn naive_now() -> NaiveDateTime {
+  chrono::prelude::Utc::now().naive_utc()
+}
diff --git a/lemmy_db_schema/src/source/activity.rs b/lemmy_db_schema/src/source/activity.rs
new file mode 100644 (file)
index 0000000..cf81ab8
--- /dev/null
@@ -0,0 +1,25 @@
+use crate::schema::activity;
+use serde_json::Value;
+use std::fmt::Debug;
+
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[table_name = "activity"]
+pub struct Activity {
+  pub id: i32,
+  pub data: Value,
+  pub local: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub ap_id: Option<String>,
+  pub sensitive: Option<bool>,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "activity"]
+pub struct ActivityForm {
+  pub data: Value,
+  pub local: bool,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub ap_id: String,
+  pub sensitive: bool,
+}
diff --git a/lemmy_db_schema/src/source/category.rs b/lemmy_db_schema/src/source/category.rs
new file mode 100644 (file)
index 0000000..ea2ff12
--- /dev/null
@@ -0,0 +1,15 @@
+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/lemmy_db_schema/src/source/comment.rs b/lemmy_db_schema/src/source/comment.rs
new file mode 100644 (file)
index 0000000..8c553a5
--- /dev/null
@@ -0,0 +1,109 @@
+use crate::{
+  schema::{comment, comment_alias_1, comment_like, comment_saved},
+  source::post::Post,
+};
+use serde::Serialize;
+use url::{ParseError, Url};
+
+// WITH RECURSIVE MyTree AS (
+//     SELECT * FROM comment WHERE parent_id IS NULL
+//     UNION ALL
+//     SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
+// )
+// SELECT * FROM MyTree;
+
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[belongs_to(Post)]
+#[table_name = "comment"]
+pub struct Comment {
+  pub id: i32,
+  pub creator_id: i32,
+  pub post_id: i32,
+  pub parent_id: Option<i32>,
+  pub content: String,
+  pub removed: bool,
+  pub read: bool, // Whether the recipient has read the comment or not
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: bool,
+  pub ap_id: String,
+  pub local: bool,
+}
+
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[belongs_to(Post)]
+#[table_name = "comment_alias_1"]
+pub struct CommentAlias1 {
+  pub id: i32,
+  pub creator_id: i32,
+  pub post_id: i32,
+  pub parent_id: Option<i32>,
+  pub content: String,
+  pub removed: bool,
+  pub read: bool, // Whether the recipient has read the comment or not
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: bool,
+  pub ap_id: String,
+  pub local: bool,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "comment"]
+pub struct CommentForm {
+  pub creator_id: i32,
+  pub post_id: i32,
+  pub parent_id: Option<i32>,
+  pub content: String,
+  pub removed: Option<bool>,
+  pub read: Option<bool>,
+  pub published: Option<chrono::NaiveDateTime>,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: Option<bool>,
+  pub ap_id: Option<String>,
+  pub local: bool,
+}
+
+impl CommentForm {
+  pub fn get_ap_id(&self) -> Result<Url, ParseError> {
+    Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
+  }
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
+#[belongs_to(Comment)]
+#[table_name = "comment_like"]
+pub struct CommentLike {
+  pub id: i32,
+  pub user_id: i32,
+  pub comment_id: i32,
+  pub post_id: i32, // TODO this is redundant
+  pub score: i16,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "comment_like"]
+pub struct CommentLikeForm {
+  pub user_id: i32,
+  pub comment_id: i32,
+  pub post_id: i32, // TODO this is redundant
+  pub score: i16,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Comment)]
+#[table_name = "comment_saved"]
+pub struct CommentSaved {
+  pub id: i32,
+  pub comment_id: i32,
+  pub user_id: i32,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "comment_saved"]
+pub struct CommentSavedForm {
+  pub comment_id: i32,
+  pub user_id: i32,
+}
diff --git a/lemmy_db_schema/src/source/comment_report.rs b/lemmy_db_schema/src/source/comment_report.rs
new file mode 100644 (file)
index 0000000..ec53408
--- /dev/null
@@ -0,0 +1,28 @@
+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,
+}
diff --git a/lemmy_db_schema/src/source/community.rs b/lemmy_db_schema/src/source/community.rs
new file mode 100644 (file)
index 0000000..af7fce0
--- /dev/null
@@ -0,0 +1,121 @@
+use crate::schema::{community, community_follower, community_moderator, community_user_ban};
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "community"]
+pub struct Community {
+  pub id: i32,
+  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,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: bool,
+  pub nsfw: bool,
+  pub actor_id: String,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+}
+
+/// A safe representation of community, without the sensitive info
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "community"]
+pub struct CommunitySafe {
+  pub id: i32,
+  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,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: bool,
+  pub nsfw: bool,
+  pub actor_id: String,
+  pub local: bool,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+}
+
+#[derive(Insertable, AsChangeset, Debug)]
+#[table_name = "community"]
+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>,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: Option<bool>,
+  pub nsfw: bool,
+  pub actor_id: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: Option<chrono::NaiveDateTime>,
+  pub icon: Option<Option<String>>,
+  pub banner: Option<Option<String>>,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Community)]
+#[table_name = "community_moderator"]
+pub struct CommunityModerator {
+  pub id: i32,
+  pub community_id: i32,
+  pub user_id: i32,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "community_moderator"]
+pub struct CommunityModeratorForm {
+  pub community_id: i32,
+  pub user_id: i32,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Community)]
+#[table_name = "community_user_ban"]
+pub struct CommunityUserBan {
+  pub id: i32,
+  pub community_id: i32,
+  pub user_id: i32,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "community_user_ban"]
+pub struct CommunityUserBanForm {
+  pub community_id: i32,
+  pub user_id: i32,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Community)]
+#[table_name = "community_follower"]
+pub struct CommunityFollower {
+  pub id: i32,
+  pub community_id: i32,
+  pub user_id: i32,
+  pub published: chrono::NaiveDateTime,
+  pub pending: Option<bool>,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "community_follower"]
+pub struct CommunityFollowerForm {
+  pub community_id: i32,
+  pub user_id: i32,
+  pub pending: bool,
+}
diff --git a/lemmy_db_schema/src/source/mod.rs b/lemmy_db_schema/src/source/mod.rs
new file mode 100644 (file)
index 0000000..211194a
--- /dev/null
@@ -0,0 +1,13 @@
+pub mod activity;
+pub mod category;
+pub mod comment;
+pub mod comment_report;
+pub mod community;
+pub mod moderator;
+pub mod password_reset_request;
+pub mod post;
+pub mod post_report;
+pub mod private_message;
+pub mod site;
+pub mod user;
+pub mod user_mention;
diff --git a/lemmy_db_schema/src/source/moderator.rs b/lemmy_db_schema/src/source/moderator.rs
new file mode 100644 (file)
index 0000000..d1a5d83
--- /dev/null
@@ -0,0 +1,194 @@
+use crate::schema::{
+  mod_add,
+  mod_add_community,
+  mod_ban,
+  mod_ban_from_community,
+  mod_lock_post,
+  mod_remove_comment,
+  mod_remove_community,
+  mod_remove_post,
+  mod_sticky_post,
+};
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_remove_post"]
+pub struct ModRemovePost {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub post_id: i32,
+  pub reason: Option<String>,
+  pub removed: Option<bool>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_remove_post"]
+pub struct ModRemovePostForm {
+  pub mod_user_id: i32,
+  pub post_id: i32,
+  pub reason: Option<String>,
+  pub removed: Option<bool>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_lock_post"]
+pub struct ModLockPost {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub post_id: i32,
+  pub locked: Option<bool>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_lock_post"]
+pub struct ModLockPostForm {
+  pub mod_user_id: i32,
+  pub post_id: i32,
+  pub locked: Option<bool>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_sticky_post"]
+pub struct ModStickyPost {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub post_id: i32,
+  pub stickied: Option<bool>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_sticky_post"]
+pub struct ModStickyPostForm {
+  pub mod_user_id: i32,
+  pub post_id: i32,
+  pub stickied: Option<bool>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_remove_comment"]
+pub struct ModRemoveComment {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub comment_id: i32,
+  pub reason: Option<String>,
+  pub removed: Option<bool>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_remove_comment"]
+pub struct ModRemoveCommentForm {
+  pub mod_user_id: i32,
+  pub comment_id: i32,
+  pub reason: Option<String>,
+  pub removed: Option<bool>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_remove_community"]
+pub struct ModRemoveCommunity {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub community_id: i32,
+  pub reason: Option<String>,
+  pub removed: Option<bool>,
+  pub expires: Option<chrono::NaiveDateTime>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_remove_community"]
+pub struct ModRemoveCommunityForm {
+  pub mod_user_id: i32,
+  pub community_id: i32,
+  pub reason: Option<String>,
+  pub removed: Option<bool>,
+  pub expires: Option<chrono::NaiveDateTime>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_ban_from_community"]
+pub struct ModBanFromCommunity {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub community_id: i32,
+  pub reason: Option<String>,
+  pub banned: Option<bool>,
+  pub expires: Option<chrono::NaiveDateTime>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_ban_from_community"]
+pub struct ModBanFromCommunityForm {
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub community_id: i32,
+  pub reason: Option<String>,
+  pub banned: Option<bool>,
+  pub expires: Option<chrono::NaiveDateTime>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_ban"]
+pub struct ModBan {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub reason: Option<String>,
+  pub banned: Option<bool>,
+  pub expires: Option<chrono::NaiveDateTime>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_ban"]
+pub struct ModBanForm {
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub reason: Option<String>,
+  pub banned: Option<bool>,
+  pub expires: Option<chrono::NaiveDateTime>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_add_community"]
+pub struct ModAddCommunity {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub community_id: i32,
+  pub removed: Option<bool>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_add_community"]
+pub struct ModAddCommunityForm {
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub community_id: i32,
+  pub removed: Option<bool>,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "mod_add"]
+pub struct ModAdd {
+  pub id: i32,
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub removed: Option<bool>,
+  pub when_: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "mod_add"]
+pub struct ModAddForm {
+  pub mod_user_id: i32,
+  pub other_user_id: i32,
+  pub removed: Option<bool>,
+}
diff --git a/lemmy_db_schema/src/source/password_reset_request.rs b/lemmy_db_schema/src/source/password_reset_request.rs
new file mode 100644 (file)
index 0000000..f81f28e
--- /dev/null
@@ -0,0 +1,17 @@
+use crate::schema::password_reset_request;
+
+#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[table_name = "password_reset_request"]
+pub struct PasswordResetRequest {
+  pub id: i32,
+  pub user_id: i32,
+  pub token_encrypted: String,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "password_reset_request"]
+pub struct PasswordResetRequestForm {
+  pub user_id: i32,
+  pub token_encrypted: String,
+}
diff --git a/lemmy_db_schema/src/source/post.rs b/lemmy_db_schema/src/source/post.rs
new file mode 100644 (file)
index 0000000..b0cc78e
--- /dev/null
@@ -0,0 +1,113 @@
+use crate::schema::{post, post_like, post_read, post_saved};
+use serde::Serialize;
+use url::{ParseError, Url};
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "post"]
+pub struct Post {
+  pub id: i32,
+  pub name: String,
+  pub url: Option<String>,
+  pub body: Option<String>,
+  pub creator_id: i32,
+  pub community_id: i32,
+  pub removed: bool,
+  pub locked: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub deleted: bool,
+  pub nsfw: bool,
+  pub stickied: bool,
+  pub embed_title: Option<String>,
+  pub embed_description: Option<String>,
+  pub embed_html: Option<String>,
+  pub thumbnail_url: Option<String>,
+  pub ap_id: String,
+  pub local: bool,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "post"]
+pub struct PostForm {
+  pub name: String,
+  pub url: Option<String>,
+  pub body: Option<String>,
+  pub creator_id: i32,
+  pub community_id: i32,
+  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>,
+  pub embed_html: Option<String>,
+  pub thumbnail_url: Option<String>,
+  pub ap_id: Option<String>,
+  pub local: bool,
+}
+
+impl PostForm {
+  pub fn get_ap_id(&self) -> Result<Url, ParseError> {
+    Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
+  }
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Post)]
+#[table_name = "post_like"]
+pub struct PostLike {
+  pub id: i32,
+  pub post_id: i32,
+  pub user_id: i32,
+  pub score: i16,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "post_like"]
+pub struct PostLikeForm {
+  pub post_id: i32,
+  pub user_id: i32,
+  pub score: i16,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Post)]
+#[table_name = "post_saved"]
+pub struct PostSaved {
+  pub id: i32,
+  pub post_id: i32,
+  pub user_id: i32,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "post_saved"]
+pub struct PostSavedForm {
+  pub post_id: i32,
+  pub user_id: i32,
+}
+
+#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
+#[belongs_to(Post)]
+#[table_name = "post_read"]
+pub struct PostRead {
+  pub id: i32,
+
+  pub post_id: i32,
+
+  pub user_id: i32,
+
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "post_read"]
+pub struct PostReadForm {
+  pub post_id: i32,
+
+  pub user_id: i32,
+}
diff --git a/lemmy_db_schema/src/source/post_report.rs b/lemmy_db_schema/src/source/post_report.rs
new file mode 100644 (file)
index 0000000..b75fb95
--- /dev/null
@@ -0,0 +1,32 @@
+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,
+}
diff --git a/lemmy_db_schema/src/source/private_message.rs b/lemmy_db_schema/src/source/private_message.rs
new file mode 100644 (file)
index 0000000..3410406
--- /dev/null
@@ -0,0 +1,31 @@
+use crate::schema::private_message;
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "private_message"]
+pub struct PrivateMessage {
+  pub id: i32,
+  pub creator_id: i32,
+  pub recipient_id: i32,
+  pub content: String,
+  pub deleted: bool,
+  pub read: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub ap_id: String,
+  pub local: bool,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "private_message"]
+pub struct PrivateMessageForm {
+  pub creator_id: i32,
+  pub recipient_id: i32,
+  pub content: String,
+  pub deleted: Option<bool>,
+  pub read: Option<bool>,
+  pub published: Option<chrono::NaiveDateTime>,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub ap_id: Option<String>,
+  pub local: bool,
+}
diff --git a/lemmy_db_schema/src/source/site.rs b/lemmy_db_schema/src/source/site.rs
new file mode 100644 (file)
index 0000000..6631954
--- /dev/null
@@ -0,0 +1,33 @@
+use crate::schema::site;
+use serde::Serialize;
+
+#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
+#[table_name = "site"]
+pub struct Site {
+  pub id: i32,
+  pub name: String,
+  pub description: Option<String>,
+  pub creator_id: i32,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub enable_downvotes: bool,
+  pub open_registration: bool,
+  pub enable_nsfw: bool,
+  pub icon: Option<String>,
+  pub banner: Option<String>,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "site"]
+pub struct SiteForm {
+  pub name: String,
+  pub description: Option<String>,
+  pub creator_id: i32,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub enable_downvotes: bool,
+  pub open_registration: bool,
+  pub enable_nsfw: bool,
+  // when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
+  pub icon: Option<Option<String>>,
+  pub banner: Option<Option<String>>,
+}
diff --git a/lemmy_db_schema/src/source/user.rs b/lemmy_db_schema/src/source/user.rs
new file mode 100644 (file)
index 0000000..3d9d9e5
--- /dev/null
@@ -0,0 +1,182 @@
+use crate::schema::{user_, user_alias_1, user_alias_2};
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_"]
+pub struct User_ {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub password_encrypted: String,
+  pub email: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub show_nsfw: bool,
+  pub theme: String,
+  pub default_sort_type: i16,
+  pub default_listing_type: i16,
+  pub lang: String,
+  pub show_avatars: bool,
+  pub send_notifications_to_email: bool,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
+/// A safe representation of user, without the sensitive info
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_"]
+pub struct UserSafe {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_1"]
+pub struct UserAlias1 {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub password_encrypted: String,
+  pub email: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub show_nsfw: bool,
+  pub theme: String,
+  pub default_sort_type: i16,
+  pub default_listing_type: i16,
+  pub lang: String,
+  pub show_avatars: bool,
+  pub send_notifications_to_email: bool,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_1"]
+pub struct UserSafeAlias1 {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_2"]
+pub struct UserAlias2 {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub password_encrypted: String,
+  pub email: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub show_nsfw: bool,
+  pub theme: String,
+  pub default_sort_type: i16,
+  pub default_listing_type: i16,
+  pub lang: String,
+  pub show_avatars: bool,
+  pub send_notifications_to_email: bool,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_alias_2"]
+pub struct UserSafeAlias2 {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
+#[derive(Insertable, AsChangeset, Clone)]
+#[table_name = "user_"]
+pub struct UserForm {
+  pub name: String,
+  pub preferred_username: Option<Option<String>>,
+  pub password_encrypted: String,
+  pub admin: bool,
+  pub banned: Option<bool>,
+  pub email: Option<Option<String>>,
+  pub avatar: Option<Option<String>>,
+  pub published: Option<chrono::NaiveDateTime>,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub show_nsfw: bool,
+  pub theme: String,
+  pub default_sort_type: i16,
+  pub default_listing_type: i16,
+  pub lang: String,
+  pub show_avatars: bool,
+  pub send_notifications_to_email: bool,
+  pub matrix_user_id: Option<Option<String>>,
+  pub actor_id: Option<String>,
+  pub bio: Option<Option<String>>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: Option<chrono::NaiveDateTime>,
+  pub banner: Option<Option<String>>,
+}
diff --git a/lemmy_db_schema/src/source/user_mention.rs b/lemmy_db_schema/src/source/user_mention.rs
new file mode 100644 (file)
index 0000000..64fd560
--- /dev/null
@@ -0,0 +1,21 @@
+use crate::{schema::user_mention, source::comment::Comment};
+use serde::Serialize;
+
+#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[belongs_to(Comment)]
+#[table_name = "user_mention"]
+pub struct UserMention {
+  pub id: i32,
+  pub recipient_id: i32,
+  pub comment_id: i32,
+  pub read: bool,
+  pub published: chrono::NaiveDateTime,
+}
+
+#[derive(Insertable, AsChangeset)]
+#[table_name = "user_mention"]
+pub struct UserMentionForm {
+  pub recipient_id: i32,
+  pub comment_id: i32,
+  pub read: Option<bool>,
+}
index e146230640265e4a8a4c697157043e6df8798ff4..329ef4139a125e9d5454498c299dce4091b11439 100644 (file)
@@ -10,6 +10,7 @@ path = "src/lib.rs"
 
 [dependencies]
 lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
 lemmy_utils = { path = "../lemmy_utils" }
 serde = { version = "1.0.118", features = ["derive"] }
 log = "0.4.11"
index d19127384b773ab04864fd6e821aba4a4c5df388..080cb38521618761c8c1bdef1587747a99ba4cc9 100644 (file)
@@ -5,15 +5,12 @@ pub mod site;
 pub mod user;
 
 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..f24d9f49ee42db21292b2d09f40a253653b4beea 100644 (file)
@@ -1,24 +1,22 @@
-use lemmy_db::{
-  source::{category::*, user::*},
-  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)]
index ed0ba4ce0dcd9f85fe5295a78d9568423379dab2..30dbe1fbd370b20d883c86b72ac5e9e9278227db 100644 (file)
@@ -12,6 +12,7 @@ path = "src/lib.rs"
 lemmy_utils = { path = "../lemmy_utils" }
 lemmy_structs = { path = "../lemmy_structs" }
 lemmy_db = { path = "../lemmy_db" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
 lemmy_rate_limit = { path = "../lemmy_rate_limit" }
 reqwest = { version = "0.10.10", features = ["json"] }
 log = "0.4.11"
index d95dfd57fab8d82b5d882badccfbe2970b81c7a2..0762b948541ef8c06373d266eeb3019e8b2cbbbc 100644 (file)
@@ -3,7 +3,7 @@ use crate::{
   messages::*,
 };
 use actix::{Actor, Context, Handler, ResponseFuture};
-use lemmy_db::naive_now;
+use lemmy_db_schema::naive_now;
 use log::{error, info};
 use rand::Rng;
 use serde::Serialize;
index af01982fc4a2e286640e7300af71a5fb529ad789..73b030cb22dc2f39e53165b1247b2bb6419acafc 100644 (file)
@@ -4,6 +4,10 @@ use diesel::{
   *,
 };
 use lemmy_db::{
+  source::{comment::Comment_, post::Post_, private_message::PrivateMessage_},
+  Crud,
+};
+use lemmy_db_schema::{
   naive_now,
   source::{
     comment::Comment,
@@ -12,7 +16,6 @@ use lemmy_db::{
     private_message::PrivateMessage,
     user::{UserForm, User_},
   },
-  Crud,
 };
 use lemmy_utils::{
   apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
@@ -33,7 +36,7 @@ pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
 }
 
 fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db::schema::user_::dsl::*;
+  use lemmy_db_schema::schema::user_::dsl::*;
 
   info!("Running user_updates_2020_04_02");
 
@@ -82,7 +85,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
 }
 
 fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db::schema::community::dsl::*;
+  use lemmy_db_schema::schema::community::dsl::*;
 
   info!("Running community_updates_2020_04_02");
 
@@ -124,7 +127,7 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
 }
 
 fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db::schema::post::dsl::*;
+  use lemmy_db_schema::schema::post::dsl::*;
 
   info!("Running post_updates_2020_04_03");
 
@@ -145,7 +148,7 @@ fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
 }
 
 fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db::schema::comment::dsl::*;
+  use lemmy_db_schema::schema::comment::dsl::*;
 
   info!("Running comment_updates_2020_04_03");
 
@@ -166,7 +169,7 @@ fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
 }
 
 fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db::schema::private_message::dsl::*;
+  use lemmy_db_schema::schema::private_message::dsl::*;
 
   info!("Running private_message_updates_2020_05_05");
 
@@ -187,7 +190,7 @@ fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyEr
 }
 
 fn post_thumbnail_url_updates_2020_07_27(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db::schema::post::dsl::*;
+  use lemmy_db_schema::schema::post::dsl::*;
 
   info!("Running post_thumbnail_url_updates_2020_07_27");
 
index 7a4801f403dd014f28a2b2606d39cdf4dfc4bdcb..fc397fff0e0be059a0b13b64af0f1ca9bb1212c4 100644 (file)
@@ -4,7 +4,7 @@ use chrono::{DateTime, NaiveDateTime, Utc};
 use diesel::PgConnection;
 use lemmy_api::claims::Claims;
 use lemmy_db::{
-  source::{community::Community, user::User_},
+  source::{community::Community_, user::User},
   views::{
     comment_view::{CommentQueryBuilder, CommentView},
     post_view::{PostQueryBuilder, PostView},
@@ -14,6 +14,7 @@ use lemmy_db::{
   ListingType,
   SortType,
 };
+use lemmy_db_schema::source::{community::Community, user::User_};
 use lemmy_structs::blocking;
 use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError};
 use lemmy_websocket::LemmyContext;
index d59b4e38909aec88f2bb5605339e97d87db23c14..2a03f5e2a6f1da28a41f88fb4abd49d33f708ab4 100644 (file)
@@ -1,6 +1,7 @@
 use actix_web::{error::ErrorBadRequest, web::Query, *};
 use anyhow::anyhow;
-use lemmy_db::source::{community::Community, user::User_};
+use lemmy_db::source::{community::Community_, user::User};
+use lemmy_db_schema::source::{community::Community, user::User_};
 use lemmy_structs::{blocking, WebFingerLink, WebFingerResponse};
 use lemmy_utils::{
   settings::Settings,
index c8986454405f07387bb989139e7365193cd382f3..c507af0670133117ac9c50e9f1d880c3303d602b 100644 (file)
@@ -28,14 +28,10 @@ use lemmy_apub::{
     user_inbox::user_inbox,
   },
 };
-use lemmy_db::{
-  source::{
-    community::{Community, CommunityForm},
-    user::{User_, *},
-  },
-  Crud,
-  ListingType,
-  SortType,
+use lemmy_db::{Crud, ListingType, SortType};
+use lemmy_db_schema::source::{
+  community::{Community, CommunityForm},
+  user::{UserForm, User_},
 };
 use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
 use lemmy_utils::{apub::generate_actor_keypair, settings::Settings};