]> Untitled Git - lemmy.git/commitdiff
Adding diesel enums for SortType and ListingType (#2808)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 17 Apr 2023 19:19:51 +0000 (15:19 -0400)
committerGitHub <noreply@github.com>
Mon, 17 Apr 2023 19:19:51 +0000 (15:19 -0400)
* Adding diesel enums for SortType and ListingType

- Uses diesel-derive-enum.
- Adds diesel.toml , so we can again use the auto-generated schema.rs
- Fixes a lot of DB null issues and column ordering issues.
- Fixes #1136
- Also replaces RegistrationMode boilerplate.

* Fixing unit tests 1.

* Remove comment line.

* Before patch.

* Before again.

* Using patch file to fix diesel_ltree issue with diesel.toml

* Adding some yalc ignores

* Fixing RegistrationMode enums

* Adding woodpecker diesel schema check.

* Try adding openssl 1.

* Try using diesel-cli image 1

* Try using diesel-cli image 2

* Try using diesel-cli image 3

* Try using diesel-cli image 4

* Try using diesel-cli image 5

* Try using diesel-cli image 6

* Try using diesel-cli image 7

* Try using diesel-cli image 8

* Try using diesel-cli image 9

* Try using diesel-cli image 10

* Try using diesel-cli image 11

* Try using diesel-cli image 12

* Try using diesel-cli image 13

39 files changed:
.gitignore
.woodpecker.yml
Cargo.lock
Cargo.toml
api_tests/package.json
api_tests/src/shared.ts
api_tests/src/user.spec.ts
api_tests/yarn.lock
crates/api/src/community/transfer.rs
crates/api/src/local_user/change_password_after_reset.rs
crates/api_common/src/person.rs
crates/api_common/src/site.rs
crates/api_common/src/utils.rs
crates/api_crud/src/site/create.rs
crates/api_crud/src/site/mod.rs
crates/api_crud/src/site/update.rs
crates/api_crud/src/user/create.rs
crates/apub/src/api/mod.rs
crates/apub/src/http/mod.rs
crates/db_schema/Cargo.toml
crates/db_schema/src/diesel_ltree.patch [new file with mode: 0644]
crates/db_schema/src/impls/activity.rs
crates/db_schema/src/impls/local_site.rs
crates/db_schema/src/impls/moderator.rs
crates/db_schema/src/impls/person.rs
crates/db_schema/src/lib.rs
crates/db_schema/src/schema.rs
crates/db_schema/src/source/activity.rs
crates/db_schema/src/source/community.rs
crates/db_schema/src/source/instance.rs
crates/db_schema/src/source/local_site.rs
crates/db_schema/src/source/local_user.rs
crates/db_schema/src/source/moderator.rs
crates/db_schema/src/source/post.rs
crates/db_views_actor/src/person_block_view.rs
crates/routes/src/nodeinfo.rs
diesel.toml [new file with mode: 0644]
migrations/2023-04-14-175955_add_listingtype_sorttype_enums/down.sql [new file with mode: 0644]
migrations/2023-04-14-175955_add_listingtype_sorttype_enums/up.sql [new file with mode: 0644]

index ea0a258595779dfb2aadf73de85176b09ea10ff7..2a689fe7006589af51094317c49f2705b873b1d7 100644 (file)
@@ -18,6 +18,8 @@ query_testing/**/reports/*.json
 
 # API tests
 api_tests/node_modules
+api_tests/.yalc
+api_tests/yalc.lock
 
 # pictrs data
 pictrs/
index 9bed578c83b74a9334b2fcb615c957983e2273bc..740614094c1a96761a8f01f7adc98ec4905cd9d0 100644 (file)
@@ -95,6 +95,16 @@ pipeline:
     # when:
     #   platform: linux/amd64
 
+  check_diesel_schema:
+    image: jameshiew/diesel-cli
+    environment:
+      CARGO_HOME: .cargo
+      DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
+    commands:
+      - diesel migration run
+      - diesel print-schema --config-file=diesel.toml > tmp.schema
+      - diff tmp.schema crates/db_schema/src/schema.rs
+
   cargo_test:
     image: *muslrust_image
     environment:
index b98acdc2be06f0ce3bdbdb6d4419b792ef76d658..77681962d0b88efa6853dcde3d60f6cee29e02ec 100644 (file)
@@ -1340,6 +1340,18 @@ dependencies = [
  "tokio-postgres",
 ]
 
+[[package]]
+name = "diesel-derive-enum"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6b10c03b954333d05bfd5be1d8a74eae2c9ca77b86e0f1c3a1ea29c49da1d6c2"
+dependencies = [
+ "heck 0.4.0",
+ "proc-macro2 1.0.47",
+ "quote 1.0.21",
+ "syn 1.0.103",
+]
+
 [[package]]
 name = "diesel-derive-newtype"
 version = "2.0.0-rc.0"
@@ -2505,6 +2517,7 @@ dependencies = [
  "deadpool",
  "diesel",
  "diesel-async",
+ "diesel-derive-enum",
  "diesel-derive-newtype",
  "diesel_ltree",
  "diesel_migrations",
index 52e1a8beb6452f891fd00f6d3afa01ca1b90bc8b..9c8dcab0a2e14f3a57fc6e51384747dfef8438f4 100644 (file)
@@ -93,6 +93,7 @@ sha2 = "0.10.6"
 regex = "1.6.0"
 once_cell = "1.15.0"
 diesel-derive-newtype = "2.0.0-rc.0"
+diesel-derive-enum = {version = "2.0.1", features = ["postgres"] }
 strum = "0.24.1"
 strum_macros = "0.24.3"
 itertools = "0.10.5"
index 2901a375085b837105ab9dff5061ee890f3ae9a4..3237d22a82d176c01e993a430783cdeb50994d98 100644 (file)
@@ -18,7 +18,7 @@
     "eslint": "^8.25.0",
     "eslint-plugin-prettier": "^4.0.0",
     "jest": "^27.0.6",
-    "lemmy-js-client": "0.17.2-rc.1",
+    "lemmy-js-client": "0.17.2-rc.6",
     "node-fetch": "^2.6.1",
     "prettier": "^2.7.1",
     "ts-jest": "^27.0.3",
index 835f119ceb8930fe3d19d870f78903e23cbdcef1..b8e97db0d37215979e29c3c33271674bd433bc33 100644 (file)
@@ -615,8 +615,8 @@ export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
   let form: SaveUserSettings = {
     show_nsfw: true,
     theme: "darkly",
-    default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
-    default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
+    default_sort_type: SortType.Active,
+    default_listing_type: ListingType.All,
     interface_language: "en",
     show_avatars: true,
     send_notifications_to_email: false,
@@ -634,8 +634,8 @@ export async function saveUserSettingsFederated(
   let bio = "a changed bio";
   let form: SaveUserSettings = {
     show_nsfw: false,
-    default_sort_type: Object.keys(SortType).indexOf(SortType.Hot),
-    default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
+    default_sort_type: SortType.Hot,
+    default_listing_type: ListingType.All,
     interface_language: "",
     avatar,
     banner,
index 4b4eaab3be2215d9d2f52075a3ac16086721f854..b2083c66c20e0a86386b7c968b6e9037fef8b199 100644 (file)
@@ -1,5 +1,5 @@
 jest.setTimeout(120000);
-import { PersonViewSafe } from "lemmy-js-client";
+import { PersonView } from "lemmy-js-client";
 
 import {
   alpha,
@@ -25,10 +25,7 @@ beforeAll(async () => {
 
 let apShortname: string;
 
-function assertUserFederation(
-  userOne?: PersonViewSafe,
-  userTwo?: PersonViewSafe
-) {
+function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
   expect(userOne?.person.name).toBe(userTwo?.person.name);
   expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
   expect(userOne?.person.bio).toBe(userTwo?.person.bio);
index 1a1d7979f617b54e68495203218d6b79f7ec14ac..eaab0c47dd43ea53fd8ae61cb28a32e418734fc0 100644 (file)
@@ -1134,6 +1134,13 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
   dependencies:
     safe-buffer "~5.1.1"
 
+cross-fetch@^3.1.5:
+  version "3.1.5"
+  resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
+  integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
+  dependencies:
+    node-fetch "2.6.7"
+
 cross-spawn@^7.0.2, cross-spawn@^7.0.3:
   version "7.0.3"
   resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@@ -1555,6 +1562,15 @@ form-data@^3.0.0:
     combined-stream "^1.0.8"
     mime-types "^2.1.12"
 
+form-data@^4.0.0:
+  version "4.0.0"
+  resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
+  integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
+  dependencies:
+    asynckit "^0.4.0"
+    combined-stream "^1.0.8"
+    mime-types "^2.1.12"
+
 fs.realpath@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -2363,12 +2379,13 @@ kleur@^3.0.3:
   resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
   integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
 
-lemmy-js-client@0.17.2-rc.1:
-  version "0.17.2-rc.1"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.1.tgz#fe8d1508311bbf245acc98c2c3e47e2165a95b14"
-  integrity sha512-YrOXuCofgkqp28krmPTQZAfUWL5zEDA0sRJ0abKcgf/I8YYkYkUkPS9TOORN5Lv3bc8RAAz4+2/zLHqYL/Tnow==
+lemmy-js-client@0.17.2-rc.6:
+  version "0.17.2-rc.6"
+  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.6.tgz#cd488bc30edf7b65a02b91f1bc295d1b958e9b86"
+  integrity sha512-/EdzpLJpYOq3ypCQA1MyI7sX0DmHUIA1ZUIda2XTCUUP7a5pltF7WHTicFrQ9j6JwCiFMTVkw6S/L8LzfD6cGA==
   dependencies:
-    node-fetch "2.6.6"
+    cross-fetch "^3.1.5"
+    form-data "^4.0.0"
 
 leven@^3.1.0:
   version "3.1.0"
@@ -2503,14 +2520,7 @@ natural-compare@^1.4.0:
   resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
   integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==
 
-node-fetch@2.6.6:
-  version "2.6.6"
-  resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89"
-  integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==
-  dependencies:
-    whatwg-url "^5.0.0"
-
-node-fetch@^2.6.1:
+node-fetch@2.6.7, node-fetch@^2.6.1:
   version "2.6.7"
   resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
   integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
index c163b1950a2e8926d0d3552c484b4c5d6039068d..a34dfb40d56f3064cc8e2ea96a4243fcfdf4402d 100644 (file)
@@ -76,7 +76,6 @@ impl Perform for TransferCommunity {
       mod_person_id: local_user_view.person.id,
       other_person_id: data.person_id,
       community_id: data.community_id,
-      removed: Some(false),
     };
 
     ModTransferCommunity::create(context.pool(), &form).await?;
index 392fcaa32d14dd9f71b9c4a66f267fa4631bae32..04571e47b05954b3aa740537cb95fcb72eb03f8a 100644 (file)
@@ -5,10 +5,9 @@ use lemmy_api_common::{
   person::{LoginResponse, PasswordChangeAfterReset},
   utils::password_length_check,
 };
-use lemmy_db_schema::source::{
-  local_site::RegistrationMode,
-  local_user::LocalUser,
-  password_reset_request::PasswordResetRequest,
+use lemmy_db_schema::{
+  source::{local_user::LocalUser, password_reset_request::PasswordResetRequest},
+  RegistrationMode,
 };
 use lemmy_db_views::structs::SiteView;
 use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
index b6a59ec4d916f081f277803e2fda4babba5228fa..10a0e806f7f3003df143849ab90885a0626dcc28 100644 (file)
@@ -2,6 +2,7 @@ use crate::sensitive::Sensitive;
 use lemmy_db_schema::{
   newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
   CommentSortType,
+  ListingType,
   SortType,
 };
 use lemmy_db_views::structs::{CommentView, PostView};
@@ -55,8 +56,8 @@ pub struct SaveUserSettings {
   pub show_nsfw: Option<bool>,
   pub show_scores: Option<bool>,
   pub theme: Option<String>,
-  pub default_sort_type: Option<i16>,
-  pub default_listing_type: Option<i16>,
+  pub default_sort_type: Option<SortType>,
+  pub default_listing_type: Option<ListingType>,
   pub interface_language: Option<String>,
   pub avatar: Option<String>,
   pub banner: Option<String>,
index a290beb1092121cb6328fab0ce1968b2aa4c2756..8e5595141587e089fa077d490d3516dccbc76faf 100644 (file)
@@ -1,14 +1,10 @@
 use crate::sensitive::Sensitive;
 use lemmy_db_schema::{
   newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
-  source::{
-    instance::Instance,
-    language::Language,
-    local_site::RegistrationMode,
-    tagline::Tagline,
-  },
+  source::{instance::Instance, language::Language, tagline::Tagline},
   ListingType,
   ModlogActionType,
+  RegistrationMode,
   SearchType,
   SortType,
 };
@@ -128,7 +124,7 @@ pub struct CreateSite {
   pub application_question: Option<String>,
   pub private_instance: Option<bool>,
   pub default_theme: Option<String>,
-  pub default_post_listing_type: Option<String>,
+  pub default_post_listing_type: Option<ListingType>,
   pub legal_information: Option<String>,
   pub application_email_admins: Option<bool>,
   pub hide_modlog_mod_names: Option<bool>,
@@ -173,7 +169,7 @@ pub struct EditSite {
   pub application_question: Option<String>,
   pub private_instance: Option<bool>,
   pub default_theme: Option<String>,
-  pub default_post_listing_type: Option<String>,
+  pub default_post_listing_type: Option<ListingType>,
   pub legal_information: Option<String>,
   pub application_email_admins: Option<bool>,
   pub hide_modlog_mod_names: Option<bool>,
index c94a799db2337df399487755160b7307537b2f43..ee3ee8449ebe8a04bff33b50c052cd0e5ca56513 100644 (file)
@@ -9,7 +9,7 @@ use lemmy_db_schema::{
     community::{Community, CommunityModerator, CommunityUpdateForm},
     email_verification::{EmailVerification, EmailVerificationForm},
     instance::Instance,
-    local_site::{LocalSite, RegistrationMode},
+    local_site::LocalSite,
     local_site_rate_limit::LocalSiteRateLimit,
     password_reset_request::PasswordResetRequest,
     person::{Person, PersonUpdateForm},
@@ -20,6 +20,7 @@ use lemmy_db_schema::{
   },
   traits::{Crud, Readable},
   utils::DbPool,
+  RegistrationMode,
 };
 use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
 use lemmy_db_views_actor::structs::{
index ecafa9b2c19e09dee413abe43a9ce677977f02d8..d45caaa8a4e8751ef0569ffacea6c06813ab02db 100644 (file)
@@ -112,7 +112,7 @@ impl PerformCrud for CreateSite {
       .application_question(application_question)
       .private_instance(data.private_instance)
       .default_theme(data.default_theme.clone())
-      .default_post_listing_type(data.default_post_listing_type.clone())
+      .default_post_listing_type(data.default_post_listing_type)
       .legal_information(diesel_option_overwrite(&data.legal_information))
       .application_email_admins(data.application_email_admins)
       .hide_modlog_mod_names(data.hide_modlog_mod_names)
index 5155e3d0e7b429e3fc7c7e16dbee9bb48fc2e980..d0c09b935dcbea8011eed311a537bfd2fd91caa5 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::source::local_site::RegistrationMode;
+use lemmy_db_schema::RegistrationMode;
 use lemmy_utils::error::LemmyError;
 
 mod create;
index eb29a6dad8cdb383d5323f10f74ac61b4a3efab2..03ff590132212fcdab812b1f8ed6728b0b0fbee2 100644 (file)
@@ -17,7 +17,7 @@ use lemmy_db_schema::{
     actor_language::SiteLanguage,
     federation_allowlist::FederationAllowList,
     federation_blocklist::FederationBlockList,
-    local_site::{LocalSite, LocalSiteUpdateForm, RegistrationMode},
+    local_site::{LocalSite, LocalSiteUpdateForm},
     local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
     local_user::LocalUser,
     site::{Site, SiteUpdateForm},
@@ -26,6 +26,7 @@ use lemmy_db_schema::{
   traits::Crud,
   utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
   ListingType,
+  RegistrationMode,
 };
 use lemmy_db_views::structs::SiteView;
 use lemmy_utils::{
@@ -33,7 +34,6 @@ use lemmy_utils::{
   utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
   ConnectionId,
 };
-use std::str::FromStr;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditSite {
@@ -74,10 +74,9 @@ impl PerformCrud for EditSite {
         .unwrap_or(local_site.registration_mode),
     )?;
 
-    if let Some(default_post_listing_type) = &data.default_post_listing_type {
+    if let Some(listing_type) = &data.default_post_listing_type {
       // only allow all or local as default listing types
-      let val = ListingType::from_str(default_post_listing_type);
-      if val != Ok(ListingType::All) && val != Ok(ListingType::Local) {
+      if listing_type != &ListingType::All && listing_type != &ListingType::Local {
         return Err(LemmyError::from_message(
           "invalid_default_post_listing_type",
         ));
@@ -113,7 +112,7 @@ impl PerformCrud for EditSite {
       .application_question(application_question)
       .private_instance(data.private_instance)
       .default_theme(data.default_theme.clone())
-      .default_post_listing_type(data.default_post_listing_type.clone())
+      .default_post_listing_type(data.default_post_listing_type)
       .legal_information(diesel_option_overwrite(&data.legal_information))
       .application_email_admins(data.application_email_admins)
       .hide_modlog_mod_names(data.hide_modlog_mod_names)
index f90393c2851034d4f127c75fdac70b6e255400f4..8ae6de3908337ff006f58caba549ec88126b1c4e 100644 (file)
@@ -20,12 +20,12 @@ use lemmy_api_common::{
 use lemmy_db_schema::{
   aggregates::structs::PersonAggregates,
   source::{
-    local_site::RegistrationMode,
     local_user::{LocalUser, LocalUserInsertForm},
     person::{Person, PersonInsertForm},
     registration_application::{RegistrationApplication, RegistrationApplicationInsertForm},
   },
   traits::Crud,
+  RegistrationMode,
 };
 use lemmy_db_views::structs::{LocalUserView, SiteView};
 use lemmy_utils::{
index 1b2217a8a72057390b68e60392e01e83e5b678cb..9099dbd09d04445bb83e25ef1ec28268182d5f00 100644 (file)
@@ -2,7 +2,6 @@ use activitypub_federation::config::Data;
 use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
 use lemmy_utils::{error::LemmyError, ConnectionId};
-use std::str::FromStr;
 
 mod list_comments;
 mod list_posts;
@@ -30,9 +29,7 @@ fn listing_type_with_default(
 ) -> Result<ListingType, LemmyError> {
   // On frontpage use listing type from param or admin configured default
   let listing_type = if community_id.is_none() {
-    type_.unwrap_or(ListingType::from_str(
-      &local_site.default_post_listing_type,
-    )?)
+    type_.unwrap_or(local_site.default_post_listing_type)
   } else {
     // inside of community show everything
     ListingType::All
index 7a4a362faa652360e526fb0ceaaf29a0c62f7a32..0b8c8f153178521f0934946c64d10d7bf148c704 100644 (file)
@@ -92,7 +92,7 @@ pub(crate) async fn get_activity(
   .into();
   let activity = Activity::read_from_apub_id(context.pool(), &activity_id).await?;
 
-  let sensitive = activity.sensitive.unwrap_or(true);
+  let sensitive = activity.sensitive;
   if !activity.local {
     Err(err_object_not_local())
   } else if sensitive {
index 87278a20903ef555d8b48551774dce9f33232ad6..8a390fe174516e3bf90b25cda847b41efff3c9ab 100644 (file)
@@ -14,7 +14,7 @@ path = "src/lib.rs"
 doctest = false
 
 [features]
-full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy_utils",
+full = ["diesel", "diesel-derive-newtype", "diesel-derive-enum", "diesel_migrations", "bcrypt", "lemmy_utils",
     "activitypub_federation", "sha2", "regex", "once_cell", "serde_json", "diesel_ltree",
     "diesel-async", "deadpool"]
 
@@ -30,6 +30,7 @@ lemmy_utils = { workspace = true, optional = true }
 bcrypt = { workspace = true, optional = true }
 diesel = { workspace = true, features = ["postgres","chrono", "serde_json"], optional = true }
 diesel-derive-newtype = { workspace = true, optional = true }
+diesel-derive-enum = { workspace = true, optional = true }
 diesel_migrations = { workspace = true, optional = true }
 diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true }
 sha2 = { workspace = true, optional = true }
diff --git a/crates/db_schema/src/diesel_ltree.patch b/crates/db_schema/src/diesel_ltree.patch
new file mode 100644 (file)
index 0000000..d7d49f0
--- /dev/null
@@ -0,0 +1,36 @@
+diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs
+index 255c6422..f2ccf5e2 100644
+--- a/crates/db_schema/src/schema.rs
++++ b/crates/db_schema/src/schema.rs
+@@ -2,16 +2,12 @@
+ pub mod sql_types {
+     #[derive(diesel::sql_types::SqlType)]
+     #[diesel(postgres_type(name = "listing_type_enum"))]
+     pub struct ListingTypeEnum;
+-    #[derive(diesel::sql_types::SqlType)]
+-    #[diesel(postgres_type(name = "ltree"))]
+-    pub struct Ltree;
+-
+     #[derive(diesel::sql_types::SqlType)]
+     #[diesel(postgres_type(name = "registration_mode_enum"))]
+     pub struct RegistrationModeEnum;
+     #[derive(diesel::sql_types::SqlType)]
+     #[diesel(postgres_type(name = "sort_type_enum"))]
+@@ -67,13 +63,13 @@ diesel::table! {
+         when_ -> Timestamp,
+     }
+ }
+ diesel::table! {
+     use diesel::sql_types::*;
+-    use super::sql_types::Ltree;
++    use diesel_ltree::sql_types::Ltree;
+     comment (id) {
+         id -> Int4,
+         creator_id -> Int4,
+         post_id -> Int4,
+         content -> Text,
index a19d20f3a6f73cfa81d208c0a944d3d4936e3707..9187e736c543386c7c9c59e955c3443bf1dfe966 100644 (file)
@@ -122,7 +122,7 @@ mod tests {
       id: inserted_activity.id,
       data: test_json,
       local: true,
-      sensitive: Some(false),
+      sensitive: false,
       published: inserted_activity.published,
       updated: None,
     };
index dd3d06d626fb37b06f4bceb6697c1cacd55f7f3c..b9e920d15aa140d5095161f0e47e4b18da75e364 100644 (file)
@@ -1,25 +1,10 @@
 use crate::{
   schema::local_site::dsl::local_site,
-  source::local_site::{
-    LocalSite,
-    LocalSiteInsertForm,
-    LocalSiteUpdateForm,
-    RegistrationMode,
-    RegistrationModeType,
-  },
+  source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
   utils::{get_conn, DbPool},
 };
-use diesel::{
-  deserialize,
-  deserialize::FromSql,
-  dsl::insert_into,
-  pg::{Pg, PgValue},
-  result::Error,
-  serialize,
-  serialize::{IsNull, Output, ToSql},
-};
+use diesel::{dsl::insert_into, result::Error};
 use diesel_async::RunQueryDsl;
-use std::io::Write;
 
 impl LocalSite {
   pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result<Self, Error> {
@@ -45,25 +30,3 @@ impl LocalSite {
     diesel::delete(local_site).execute(conn).await
   }
 }
-
-impl ToSql<RegistrationModeType, Pg> for RegistrationMode {
-  fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
-    match *self {
-      RegistrationMode::Closed => out.write_all(b"closed")?,
-      RegistrationMode::RequireApplication => out.write_all(b"require_application")?,
-      RegistrationMode::Open => out.write_all(b"open")?,
-    }
-    Ok(IsNull::No)
-  }
-}
-
-impl FromSql<RegistrationModeType, Pg> for RegistrationMode {
-  fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> {
-    match bytes.as_bytes() {
-      b"closed" => Ok(RegistrationMode::Closed),
-      b"require_application" => Ok(RegistrationMode::RequireApplication),
-      b"open" => Ok(RegistrationMode::Open),
-      _ => Err("Unrecognized enum variant".into()),
-    }
-  }
-}
index 7540e4871560e2882ca627afeece55d4f7b7bfcc..ab8398cf38eaca7b071fc6d19638178d28de41ba 100644 (file)
@@ -614,7 +614,7 @@ mod tests {
       post_id: inserted_post.id,
       mod_person_id: inserted_mod.id,
       reason: None,
-      removed: Some(true),
+      removed: true,
       when_: inserted_mod_remove_post.when_,
     };
 
@@ -635,7 +635,7 @@ mod tests {
       id: inserted_mod_lock_post.id,
       post_id: inserted_post.id,
       mod_person_id: inserted_mod.id,
-      locked: Some(true),
+      locked: true,
       when_: inserted_mod_lock_post.when_,
     };
 
@@ -681,7 +681,7 @@ mod tests {
       comment_id: inserted_comment.id,
       mod_person_id: inserted_mod.id,
       reason: None,
-      removed: Some(true),
+      removed: true,
       when_: inserted_mod_remove_comment.when_,
     };
 
@@ -707,7 +707,7 @@ mod tests {
       community_id: inserted_community.id,
       mod_person_id: inserted_mod.id,
       reason: None,
-      removed: Some(true),
+      removed: true,
       expires: None,
       when_: inserted_mod_remove_community.when_,
     };
@@ -736,7 +736,7 @@ mod tests {
       mod_person_id: inserted_mod.id,
       other_person_id: inserted_person.id,
       reason: None,
-      banned: Some(true),
+      banned: true,
       expires: None,
       when_: inserted_mod_ban_from_community.when_,
     };
@@ -757,7 +757,7 @@ mod tests {
       mod_person_id: inserted_mod.id,
       other_person_id: inserted_person.id,
       reason: None,
-      banned: Some(true),
+      banned: true,
       expires: None,
       when_: inserted_mod_ban.when_,
     };
@@ -781,7 +781,7 @@ mod tests {
       community_id: inserted_community.id,
       mod_person_id: inserted_mod.id,
       other_person_id: inserted_person.id,
-      removed: Some(false),
+      removed: false,
       when_: inserted_mod_add_community.when_,
     };
 
@@ -798,7 +798,7 @@ mod tests {
       id: inserted_mod_add.id,
       mod_person_id: inserted_mod.id,
       other_person_id: inserted_person.id,
-      removed: Some(false),
+      removed: false,
       when_: inserted_mod_add.when_,
     };
 
index 032e2e0179ab4cedaf26ed340e1cfa8fe0e2da74..2c315e9c8db28de30fe38d0277b583653211cab8 100644 (file)
@@ -23,7 +23,14 @@ use crate::{
   traits::{ApubActor, Crud, Followable},
   utils::{functions::lower, get_conn, naive_now, DbPool},
 };
-use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
+use diesel::{
+  dsl::insert_into,
+  result::Error,
+  ExpressionMethods,
+  JoinOnDsl,
+  QueryDsl,
+  TextExpressionMethods,
+};
 use diesel_async::RunQueryDsl;
 
 #[async_trait]
@@ -183,7 +190,7 @@ impl PersonFollower {
     use crate::schema::{person, person_follower, person_follower::person_id};
     let conn = &mut get_conn(pool).await?;
     person_follower::table
-      .inner_join(person::table)
+      .inner_join(person::table.on(person_follower::follower_id.eq(person::id)))
       .filter(person_id.eq(person_id_))
       .select(person::all_columns)
       .load(conn)
index b0e56393fc671354fd5d4d7dd1caef770b4f2bde..055c68e06ded3d5292ba9bff70e3ce51f07bea49 100644 (file)
@@ -6,6 +6,11 @@ extern crate diesel;
 #[cfg(feature = "full")]
 #[macro_use]
 extern crate diesel_derive_newtype;
+
+#[cfg(feature = "full")]
+#[macro_use]
+extern crate diesel_derive_enum;
+
 // this is used in tests
 #[cfg(feature = "full")]
 #[macro_use]
@@ -20,6 +25,7 @@ pub mod aggregates;
 pub mod impls;
 pub mod newtypes;
 #[cfg(feature = "full")]
+#[rustfmt::skip]
 pub mod schema;
 pub mod source;
 #[cfg(feature = "full")]
@@ -30,7 +36,13 @@ pub mod utils;
 use serde::{Deserialize, Serialize};
 use strum_macros::{Display, EnumString};
 
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
+#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "full", derive(DbEnum))]
+#[cfg_attr(
+  feature = "full",
+  ExistingTypePath = "crate::schema::sql_types::SortTypeEnum"
+)]
+#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
 pub enum SortType {
   Active,
   Hot,
@@ -54,12 +66,31 @@ pub enum CommentSortType {
 }
 
 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "full", derive(DbEnum))]
+#[cfg_attr(
+  feature = "full",
+  ExistingTypePath = "crate::schema::sql_types::ListingTypeEnum"
+)]
+#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
 pub enum ListingType {
   All,
   Local,
   Subscribed,
 }
 
+#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "full", derive(DbEnum))]
+#[cfg_attr(
+  feature = "full",
+  ExistingTypePath = "crate::schema::sql_types::RegistrationModeEnum"
+)]
+#[cfg_attr(feature = "full", DbValueStyle = "verbatim")]
+pub enum RegistrationMode {
+  Closed,
+  RequireApplication,
+  Open,
+}
+
 #[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
 pub enum SearchType {
   All,
index b4fbefe2e004bf5767acd447d5100af07b28e5ab..f2ccf5e2ac07ddfec913d4f3e6e6866480460ef3 100644 (file)
@@ -1,4 +1,20 @@
-table! {
+// @generated automatically by Diesel CLI.
+
+pub mod sql_types {
+    #[derive(diesel::sql_types::SqlType)]
+    #[diesel(postgres_type(name = "listing_type_enum"))]
+    pub struct ListingTypeEnum;
+
+    #[derive(diesel::sql_types::SqlType)]
+    #[diesel(postgres_type(name = "registration_mode_enum"))]
+    pub struct RegistrationModeEnum;
+
+    #[derive(diesel::sql_types::SqlType)]
+    #[diesel(postgres_type(name = "sort_type_enum"))]
+    pub struct SortTypeEnum;
+}
+
+diesel::table! {
     activity (id) {
         id -> Int4,
         data -> Jsonb,
@@ -6,13 +22,51 @@ table! {
         published -> Timestamp,
         updated -> Nullable<Timestamp>,
         ap_id -> Text,
-        sensitive -> Nullable<Bool>,
+        sensitive -> Bool,
+    }
+}
+
+diesel::table! {
+    admin_purge_comment (id) {
+        id -> Int4,
+        admin_person_id -> Int4,
+        post_id -> Int4,
+        reason -> Nullable<Text>,
+        when_ -> Timestamp,
+    }
+}
+
+diesel::table! {
+    admin_purge_community (id) {
+        id -> Int4,
+        admin_person_id -> Int4,
+        reason -> Nullable<Text>,
+        when_ -> Timestamp,
     }
 }
 
-table! {
-  use diesel_ltree::sql_types::Ltree;
-  use diesel::sql_types::*;
+diesel::table! {
+    admin_purge_person (id) {
+        id -> Int4,
+        admin_person_id -> Int4,
+        reason -> Nullable<Text>,
+        when_ -> Timestamp,
+    }
+}
+
+diesel::table! {
+    admin_purge_post (id) {
+        id -> Int4,
+        admin_person_id -> Int4,
+        community_id -> Int4,
+        reason -> Nullable<Text>,
+        when_ -> Timestamp,
+    }
+}
+
+diesel::table! {
+    use diesel::sql_types::*;
+    use diesel_ltree::sql_types::Ltree;
 
     comment (id) {
         id -> Int4,
@@ -31,7 +85,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     comment_aggregates (id) {
         id -> Int4,
         comment_id -> Int4,
@@ -39,11 +93,11 @@ table! {
         upvotes -> Int8,
         downvotes -> Int8,
         published -> Timestamp,
-        child_count ->  Int4,
+        child_count -> Int4,
     }
 }
 
-table! {
+diesel::table! {
     comment_like (id) {
         id -> Int4,
         person_id -> Int4,
@@ -54,7 +108,17 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
+    comment_reply (id) {
+        id -> Int4,
+        recipient_id -> Int4,
+        comment_id -> Int4,
+        read -> Bool,
+        published -> Timestamp,
+    }
+}
+
+diesel::table! {
     comment_report (id) {
         id -> Int4,
         creator_id -> Int4,
@@ -68,7 +132,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     comment_saved (id) {
         id -> Int4,
         comment_id -> Int4,
@@ -77,7 +141,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     community (id) {
         id -> Int4,
         name -> Varchar,
@@ -93,20 +157,20 @@ table! {
         private_key -> Nullable<Text>,
         public_key -> Text,
         last_refreshed_at -> Timestamp,
-        icon -> Nullable<Varchar>,
-        banner -> Nullable<Varchar>,
+        icon -> Nullable<Text>,
+        banner -> Nullable<Text>,
         followers_url -> Varchar,
         inbox_url -> Varchar,
         shared_inbox_url -> Nullable<Varchar>,
-        moderators_url -> Nullable<Varchar>,
-        featured_url -> Nullable<Varchar>,
         hidden -> Bool,
         posting_restricted_to_mods -> Bool,
         instance_id -> Int4,
+        moderators_url -> Nullable<Varchar>,
+        featured_url -> Nullable<Varchar>,
     }
 }
 
-table! {
+diesel::table! {
     community_aggregates (id) {
         id -> Int4,
         community_id -> Int4,
@@ -121,7 +185,16 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
+    community_block (id) {
+        id -> Int4,
+        person_id -> Int4,
+        community_id -> Int4,
+        published -> Timestamp,
+    }
+}
+
+diesel::table! {
     community_follower (id) {
         id -> Int4,
         community_id -> Int4,
@@ -131,7 +204,15 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
+    community_language (id) {
+        id -> Int4,
+        community_id -> Int4,
+        language_id -> Int4,
+    }
+}
+
+diesel::table! {
     community_moderator (id) {
         id -> Int4,
         community_id -> Int4,
@@ -140,7 +221,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     community_person_ban (id) {
         id -> Int4,
         community_id -> Int4,
@@ -150,7 +231,134 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
+    custom_emoji (id) {
+        id -> Int4,
+        local_site_id -> Int4,
+        shortcode -> Varchar,
+        image_url -> Text,
+        alt_text -> Text,
+        category -> Text,
+        published -> Timestamp,
+        updated -> Nullable<Timestamp>,
+    }
+}
+
+diesel::table! {
+    custom_emoji_keyword (id) {
+        id -> Int4,
+        custom_emoji_id -> Int4,
+        keyword -> Varchar,
+    }
+}
+
+diesel::table! {
+    email_verification (id) {
+        id -> Int4,
+        local_user_id -> Int4,
+        email -> Text,
+        verification_token -> Text,
+        published -> Timestamp,
+    }
+}
+
+diesel::table! {
+    federation_allowlist (id) {
+        id -> Int4,
+        instance_id -> Int4,
+        published -> Timestamp,
+        updated -> Nullable<Timestamp>,
+    }
+}
+
+diesel::table! {
+    federation_blocklist (id) {
+        id -> Int4,
+        instance_id -> Int4,
+        published -> Timestamp,
+        updated -> Nullable<Timestamp>,
+    }
+}
+
+diesel::table! {
+    instance (id) {
+        id -> Int4,
+        domain -> Varchar,
+        published -> Timestamp,
+        updated -> Nullable<Timestamp>,
+        software -> Nullable<Varchar>,
+        version -> Nullable<Varchar>,
+    }
+}
+
+diesel::table! {
+    language (id) {
+        id -> Int4,
+        code -> Varchar,
+        name -> Text,
+    }
+}
+
+diesel::table! {
+    use diesel::sql_types::*;
+    use super::sql_types::ListingTypeEnum;
+    use super::sql_types::RegistrationModeEnum;
+
+    local_site (id) {
+        id -> Int4,
+        site_id -> Int4,
+        site_setup -> Bool,
+        enable_downvotes -> Bool,
+        enable_nsfw -> Bool,
+        community_creation_admin_only -> Bool,
+        require_email_verification -> Bool,
+        application_question -> Nullable<Text>,
+        private_instance -> Bool,
+        default_theme -> Text,
+        default_post_listing_type -> ListingTypeEnum,
+        legal_information -> Nullable<Text>,
+        hide_modlog_mod_names -> Bool,
+        application_email_admins -> Bool,
+        slur_filter_regex -> Nullable<Text>,
+        actor_name_max_length -> Int4,
+        federation_enabled -> Bool,
+        federation_debug -> Bool,
+        federation_worker_count -> Int4,
+        captcha_enabled -> Bool,
+        captcha_difficulty -> Varchar,
+        published -> Timestamp,
+        updated -> Nullable<Timestamp>,
+        registration_mode -> RegistrationModeEnum,
+        reports_email_admins -> Bool,
+    }
+}
+
+diesel::table! {
+    local_site_rate_limit (id) {
+        id -> Int4,
+        local_site_id -> Int4,
+        message -> Int4,
+        message_per_second -> Int4,
+        post -> Int4,
+        post_per_second -> Int4,
+        register -> Int4,
+        register_per_second -> Int4,
+        image -> Int4,
+        image_per_second -> Int4,
+        comment -> Int4,
+        comment_per_second -> Int4,
+        search -> Int4,
+        search_per_second -> Int4,
+        published -> Timestamp,
+        updated -> Nullable<Timestamp>,
+    }
+}
+
+diesel::table! {
+    use diesel::sql_types::*;
+    use super::sql_types::SortTypeEnum;
+    use super::sql_types::ListingTypeEnum;
+
     local_user (id) {
         id -> Int4,
         person_id -> Int4,
@@ -158,14 +366,14 @@ table! {
         email -> Nullable<Text>,
         show_nsfw -> Bool,
         theme -> Varchar,
-        default_sort_type -> Int2,
-        default_listing_type -> Int2,
+        default_sort_type -> SortTypeEnum,
+        default_listing_type -> ListingTypeEnum,
         interface_language -> Varchar,
         show_avatars -> Bool,
         send_notifications_to_email -> Bool,
         validator_time -> Timestamp,
-        show_bot_accounts -> Bool,
         show_scores -> Bool,
+        show_bot_accounts -> Bool,
         show_read_posts -> Bool,
         show_new_post_notifs -> Bool,
         email_verified -> Bool,
@@ -175,119 +383,137 @@ table! {
     }
 }
 
-table! {
-    mod_add (id) {
+diesel::table! {
+    local_user_language (id) {
         id -> Int4,
-        mod_person_id -> Int4,
-        other_person_id -> Int4,
-        removed -> Nullable<Bool>,
-        when_ -> Timestamp,
+        local_user_id -> Int4,
+        language_id -> Int4,
     }
 }
 
-table! {
-    mod_add_community (id) {
+diesel::table! {
+    mod_add (id) {
         id -> Int4,
         mod_person_id -> Int4,
         other_person_id -> Int4,
-        community_id -> Int4,
-        removed -> Nullable<Bool>,
+        removed -> Bool,
         when_ -> Timestamp,
     }
 }
 
-table! {
-    mod_transfer_community (id) {
+diesel::table! {
+    mod_add_community (id) {
         id -> Int4,
         mod_person_id -> Int4,
         other_person_id -> Int4,
         community_id -> Int4,
-        removed -> Nullable<Bool>,
+        removed -> Bool,
         when_ -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
     mod_ban (id) {
         id -> Int4,
         mod_person_id -> Int4,
         other_person_id -> Int4,
         reason -> Nullable<Text>,
-        banned -> Nullable<Bool>,
+        banned -> Bool,
         expires -> Nullable<Timestamp>,
         when_ -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
     mod_ban_from_community (id) {
         id -> Int4,
         mod_person_id -> Int4,
         other_person_id -> Int4,
         community_id -> Int4,
         reason -> Nullable<Text>,
-        banned -> Nullable<Bool>,
+        banned -> Bool,
         expires -> Nullable<Timestamp>,
         when_ -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
+    mod_feature_post (id) {
+        id -> Int4,
+        mod_person_id -> Int4,
+        post_id -> Int4,
+        featured -> Bool,
+        when_ -> Timestamp,
+        is_featured_community -> Bool,
+    }
+}
+
+diesel::table! {
+    mod_hide_community (id) {
+        id -> Int4,
+        community_id -> Int4,
+        mod_person_id -> Int4,
+        when_ -> Timestamp,
+        reason -> Nullable<Text>,
+        hidden -> Bool,
+    }
+}
+
+diesel::table! {
     mod_lock_post (id) {
         id -> Int4,
         mod_person_id -> Int4,
         post_id -> Int4,
-        locked -> Nullable<Bool>,
+        locked -> Bool,
         when_ -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
     mod_remove_comment (id) {
         id -> Int4,
         mod_person_id -> Int4,
         comment_id -> Int4,
         reason -> Nullable<Text>,
-        removed -> Nullable<Bool>,
+        removed -> Bool,
         when_ -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
     mod_remove_community (id) {
         id -> Int4,
         mod_person_id -> Int4,
         community_id -> Int4,
         reason -> Nullable<Text>,
-        removed -> Nullable<Bool>,
+        removed -> Bool,
         expires -> Nullable<Timestamp>,
         when_ -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
     mod_remove_post (id) {
         id -> Int4,
         mod_person_id -> Int4,
         post_id -> Int4,
         reason -> Nullable<Text>,
-        removed -> Nullable<Bool>,
+        removed -> Bool,
         when_ -> Timestamp,
     }
 }
 
-table! {
-    mod_feature_post (id) {
+diesel::table! {
+    mod_transfer_community (id) {
         id -> Int4,
         mod_person_id -> Int4,
-        post_id -> Int4,
-        featured -> Bool,
+        other_person_id -> Int4,
+        community_id -> Int4,
         when_ -> Timestamp,
-        is_featured_community -> Bool,
     }
 }
 
-table! {
+diesel::table! {
     password_reset_request (id) {
         id -> Int4,
         token_encrypted -> Text,
@@ -296,12 +522,12 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     person (id) {
         id -> Int4,
         name -> Varchar,
         display_name -> Nullable<Varchar>,
-        avatar -> Nullable<Varchar>,
+        avatar -> Nullable<Text>,
         banned -> Bool,
         published -> Timestamp,
         updated -> Nullable<Timestamp>,
@@ -311,7 +537,7 @@ table! {
         private_key -> Nullable<Text>,
         public_key -> Text,
         last_refreshed_at -> Timestamp,
-        banner -> Nullable<Varchar>,
+        banner -> Nullable<Text>,
         deleted -> Bool,
         inbox_url -> Varchar,
         shared_inbox_url -> Nullable<Varchar>,
@@ -323,7 +549,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     person_aggregates (id) {
         id -> Int4,
         person_id -> Int4,
@@ -334,7 +560,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     person_ban (id) {
         id -> Int4,
         person_id -> Int4,
@@ -342,7 +568,26 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
+    person_block (id) {
+        id -> Int4,
+        person_id -> Int4,
+        target_id -> Int4,
+        published -> Timestamp,
+    }
+}
+
+diesel::table! {
+    person_follower (id) {
+        id -> Int4,
+        person_id -> Int4,
+        follower_id -> Int4,
+        published -> Timestamp,
+        pending -> Bool,
+    }
+}
+
+diesel::table! {
     person_mention (id) {
         id -> Int4,
         recipient_id -> Int4,
@@ -352,21 +597,21 @@ table! {
     }
 }
 
-table! {
-    comment_reply (id) {
+diesel::table! {
+    person_post_aggregates (id) {
         id -> Int4,
-        recipient_id -> Int4,
-        comment_id -> Int4,
-        read -> Bool,
+        person_id -> Int4,
+        post_id -> Int4,
+        read_comments -> Int8,
         published -> Timestamp,
     }
 }
 
-table! {
+diesel::table! {
     post (id) {
         id -> Int4,
         name -> Varchar,
-        url -> Nullable<Varchar>,
+        url -> Nullable<Text>,
         body -> Nullable<Text>,
         creator_id -> Int4,
         community_id -> Int4,
@@ -378,27 +623,17 @@ table! {
         nsfw -> Bool,
         embed_title -> Nullable<Text>,
         embed_description -> Nullable<Text>,
-        embed_video_url -> Nullable<Text>,
         thumbnail_url -> Nullable<Text>,
         ap_id -> Varchar,
         local -> Bool,
+        embed_video_url -> Nullable<Text>,
         language_id -> Int4,
         featured_community -> Bool,
         featured_local -> Bool,
     }
 }
 
-table! {
-    person_post_aggregates (id) {
-        id -> Int4,
-        person_id -> Int4,
-        post_id -> Int4,
-        read_comments -> Int8,
-        published -> Timestamp,
-    }
-}
-
-table! {
+diesel::table! {
     post_aggregates (id) {
         id -> Int4,
         post_id -> Int4,
@@ -414,7 +649,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     post_like (id) {
         id -> Int4,
         post_id -> Int4,
@@ -424,7 +659,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     post_read (id) {
         id -> Int4,
         post_id -> Int4,
@@ -433,7 +668,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     post_report (id) {
         id -> Int4,
         creator_id -> Int4,
@@ -449,7 +684,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     post_saved (id) {
         id -> Int4,
         post_id -> Int4,
@@ -458,7 +693,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     private_message (id) {
         id -> Int4,
         creator_id -> Int4,
@@ -473,7 +708,7 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
     private_message_report (id) {
         id -> Int4,
         creator_id -> Int4,
@@ -487,26 +722,44 @@ table! {
     }
 }
 
-table! {
+diesel::table! {
+    registration_application (id) {
+        id -> Int4,
+        local_user_id -> Int4,
+        answer -> Text,
+        admin_id -> Nullable<Int4>,
+        deny_reason -> Nullable<Text>,
+        published -> Timestamp,
+    }
+}
+
+diesel::table! {
+    secret (id) {
+        id -> Int4,
+        jwt_secret -> Varchar,
+    }
+}
+
+diesel::table! {
     site (id) {
         id -> Int4,
         name -> Varchar,
         sidebar -> Nullable<Text>,
         published -> Timestamp,
         updated -> Nullable<Timestamp>,
-        icon -> Nullable<Varchar>,
-        banner -> Nullable<Varchar>,
-        description -> Nullable<Text>,
-        actor_id -> Text,
+        icon -> Nullable<Text>,
+        banner -> Nullable<Text>,
+        description -> Nullable<Varchar>,
+        actor_id -> Varchar,
         last_refreshed_at -> Timestamp,
-        inbox_url -> Text,
+        inbox_url -> Varchar,
         private_key -> Nullable<Text>,
         public_key -> Text,
         instance_id -> Int4,
     }
 }
 
-table! {
+diesel::table! {
     site_aggregates (id) {
         id -> Int4,
         site_id -> Int4,
@@ -521,405 +774,168 @@ table! {
     }
 }
 
-table! {
-    person_block (id) {
-        id -> Int4,
-        person_id -> Int4,
-        target_id -> Int4,
-        published -> Timestamp,
-    }
-}
-
-table! {
-    community_block (id) {
-        id -> Int4,
-        person_id -> Int4,
-        community_id -> Int4,
-        published -> Timestamp,
-    }
-}
-
-table! {
-  secret(id) {
-    id -> Int4,
-    jwt_secret -> Varchar,
-  }
-}
-
-table! {
-  admin_purge_comment (id) {
-    id -> Int4,
-    admin_person_id -> Int4,
-    post_id -> Int4,
-    reason -> Nullable<Text>,
-    when_ -> Timestamp,
-  }
-}
-
-table! {
-  email_verification (id) {
-    id -> Int4,
-    local_user_id -> Int4,
-    email -> Text,
-    verification_token -> Varchar,
-    published -> Timestamp,
-  }
-}
-
-table! {
-  admin_purge_community (id) {
-    id -> Int4,
-    admin_person_id -> Int4,
-    reason -> Nullable<Text>,
-    when_ -> Timestamp,
-  }
-}
-
-table! {
-  admin_purge_person (id) {
-    id -> Int4,
-    admin_person_id -> Int4,
-    reason -> Nullable<Text>,
-    when_ -> Timestamp,
-  }
-}
-
-table! {
-  admin_purge_post (id) {
-    id -> Int4,
-    admin_person_id -> Int4,
-    community_id -> Int4,
-    reason -> Nullable<Text>,
-    when_ -> Timestamp,
-  }
-}
-
-table! {
-    registration_application (id) {
-        id -> Int4,
-        local_user_id -> Int4,
-        answer -> Text,
-        admin_id -> Nullable<Int4>,
-        deny_reason -> Nullable<Text>,
-        published -> Timestamp,
-    }
-}
-
-table! {
-    mod_hide_community (id) {
-        id -> Int4,
-        community_id -> Int4,
-        mod_person_id -> Int4,
-        reason -> Nullable<Text>,
-        hidden -> Nullable<Bool>,
-        when_ -> Timestamp,
-    }
-}
-
-table! {
-    language (id) {
-        id -> Int4,
-        code -> Text,
-        name -> Text,
-    }
-}
-
-table! {
-    local_user_language(id) {
-        id -> Int4,
-        local_user_id -> Int4,
-        language_id -> Int4,
-    }
-}
-
-table! {
-    site_language(id) {
+diesel::table! {
+    site_language (id) {
         id -> Int4,
         site_id -> Int4,
         language_id -> Int4,
     }
 }
 
-table! {
-    community_language(id) {
+diesel::table! {
+    tagline (id) {
         id -> Int4,
-        community_id -> Int4,
-        language_id -> Int4,
-    }
-}
-
-table! {
-  instance(id) {
-    id -> Int4,
-    domain -> Text,
-    software -> Nullable<Text>,
-    version -> Nullable<Text>,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-  }
-}
-
-table! {
-  federation_allowlist(id) {
-    id -> Int4,
-    instance_id -> Int4,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-  }
-}
-
-table! {
-  federation_blocklist(id) {
-    id -> Int4,
-    instance_id -> Int4,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-  }
-}
-
-table! {
-  use crate::source::local_site::RegistrationModeType;
-  use diesel::sql_types::*;
-
-  local_site(id) {
-    id -> Int4,
-    site_id -> Int4,
-    site_setup -> Bool,
-    enable_downvotes -> Bool,
-    enable_nsfw -> Bool,
-    community_creation_admin_only -> Bool,
-    require_email_verification -> Bool,
-    application_question -> Nullable<Text>,
-    private_instance -> Bool,
-    default_theme -> Text,
-    default_post_listing_type -> Text,
-    legal_information -> Nullable<Text>,
-    hide_modlog_mod_names -> Bool,
-    application_email_admins -> Bool,
-    slur_filter_regex -> Nullable<Text>,
-    actor_name_max_length -> Int4,
-    federation_enabled -> Bool,
-    federation_debug -> Bool,
-    federation_worker_count -> Int4,
-    captcha_enabled -> Bool,
-    captcha_difficulty -> Text,
-    registration_mode -> RegistrationModeType,
-    reports_email_admins -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-  }
-}
-
-table! {
-  local_site_rate_limit(id) {
-    id -> Int4,
-    local_site_id -> Int4,
-    message -> Int4,
-    message_per_second-> Int4,
-    post -> Int4,
-    post_per_second -> Int4,
-    register -> Int4,
-    register_per_second -> Int4,
-    image -> Int4,
-    image_per_second -> Int4,
-    comment -> Int4,
-    comment_per_second -> Int4,
-    search -> Int4,
-    search_per_second -> Int4,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-  }
-}
-
-table! {
-  tagline(id) {
-    id -> Int4,
-    local_site_id -> Int4,
-    content -> Text,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-  }
-}
-
-table! {
-    person_follower (id) {
-        id -> Int4,
-        person_id -> Int4,
-        follower_id -> Int4,
+        local_site_id -> Int4,
+        content -> Text,
         published -> Timestamp,
-        pending -> Bool,
+        updated -> Nullable<Timestamp>,
     }
 }
 
-table! {
-  custom_emoji (id) {
-    id -> Int4,
-    local_site_id -> Int4,
-    shortcode -> Varchar,
-    image_url -> Text,
-    alt_text -> Text,
-    category -> Text,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    }
-}
-
-table! {
-  custom_emoji_keyword (id) {
-    id -> Int4,
-    custom_emoji_id -> Int4,
-    keyword -> Varchar,
-    }
-}
-
-joinable!(person_block -> person (person_id));
-
-joinable!(comment -> person (creator_id));
-joinable!(comment -> post (post_id));
-joinable!(comment_aggregates -> comment (comment_id));
-joinable!(comment_like -> comment (comment_id));
-joinable!(comment_like -> person (person_id));
-joinable!(comment_like -> post (post_id));
-joinable!(comment_report -> comment (comment_id));
-joinable!(comment_saved -> comment (comment_id));
-joinable!(comment_saved -> person (person_id));
-joinable!(community_aggregates -> community (community_id));
-joinable!(community_block -> community (community_id));
-joinable!(community_block -> person (person_id));
-joinable!(community_follower -> community (community_id));
-joinable!(community_follower -> person (person_id));
-joinable!(community_moderator -> community (community_id));
-joinable!(community_moderator -> person (person_id));
-joinable!(community_person_ban -> community (community_id));
-joinable!(community_person_ban -> person (person_id));
-joinable!(local_user -> person (person_id));
-joinable!(mod_add_community -> community (community_id));
-joinable!(mod_transfer_community -> community (community_id));
-joinable!(mod_ban_from_community -> community (community_id));
-joinable!(mod_lock_post -> person (mod_person_id));
-joinable!(mod_lock_post -> post (post_id));
-joinable!(mod_remove_comment -> comment (comment_id));
-joinable!(mod_remove_comment -> person (mod_person_id));
-joinable!(mod_remove_community -> community (community_id));
-joinable!(mod_remove_community -> person (mod_person_id));
-joinable!(mod_remove_post -> person (mod_person_id));
-joinable!(mod_remove_post -> post (post_id));
-joinable!(mod_feature_post -> person (mod_person_id));
-joinable!(mod_feature_post -> post (post_id));
-joinable!(password_reset_request -> local_user (local_user_id));
-joinable!(person_aggregates -> person (person_id));
-joinable!(person_ban -> person (person_id));
-joinable!(person_mention -> comment (comment_id));
-joinable!(person_mention -> person (recipient_id));
-joinable!(comment_reply -> comment (comment_id));
-joinable!(comment_reply -> person (recipient_id));
-joinable!(post -> community (community_id));
-joinable!(post -> person (creator_id));
-joinable!(person_post_aggregates -> post (post_id));
-joinable!(person_post_aggregates -> person (person_id));
-joinable!(post_aggregates -> post (post_id));
-joinable!(post_like -> person (person_id));
-joinable!(post_like -> post (post_id));
-joinable!(post_read -> person (person_id));
-joinable!(post_read -> post (post_id));
-joinable!(post_report -> post (post_id));
-joinable!(post_saved -> person (person_id));
-joinable!(post_saved -> post (post_id));
-joinable!(site_aggregates -> site (site_id));
-joinable!(email_verification -> local_user (local_user_id));
-joinable!(registration_application -> local_user (local_user_id));
-joinable!(registration_application -> person (admin_id));
-joinable!(mod_hide_community -> person (mod_person_id));
-joinable!(mod_hide_community -> community (community_id));
-joinable!(post -> language (language_id));
-joinable!(comment -> language (language_id));
-joinable!(local_user_language -> language (language_id));
-joinable!(local_user_language -> local_user (local_user_id));
-joinable!(private_message_report -> private_message (private_message_id));
-joinable!(site_language -> language (language_id));
-joinable!(site_language -> site (site_id));
-joinable!(community_language -> language (language_id));
-joinable!(community_language -> community (community_id));
-joinable!(person_follower -> person (follower_id));
-
-joinable!(admin_purge_comment -> person (admin_person_id));
-joinable!(admin_purge_comment -> post (post_id));
-joinable!(admin_purge_community -> person (admin_person_id));
-joinable!(admin_purge_person -> person (admin_person_id));
-joinable!(admin_purge_post -> community (community_id));
-joinable!(admin_purge_post -> person (admin_person_id));
-
-joinable!(site -> instance (instance_id));
-joinable!(person -> instance (instance_id));
-joinable!(community -> instance (instance_id));
-joinable!(federation_allowlist -> instance (instance_id));
-joinable!(federation_blocklist -> instance (instance_id));
-joinable!(local_site -> site (site_id));
-joinable!(local_site_rate_limit -> local_site (local_site_id));
-joinable!(tagline -> local_site (local_site_id));
-joinable!(custom_emoji -> local_site (local_site_id));
-joinable!(custom_emoji_keyword -> custom_emoji (custom_emoji_id));
-
-allow_tables_to_appear_in_same_query!(
-  activity,
-  comment,
-  comment_aggregates,
-  community_block,
-  comment_like,
-  comment_report,
-  comment_saved,
-  community,
-  community_aggregates,
-  community_follower,
-  community_moderator,
-  community_person_ban,
-  local_user,
-  mod_add,
-  mod_add_community,
-  mod_transfer_community,
-  mod_ban,
-  mod_ban_from_community,
-  mod_lock_post,
-  mod_remove_comment,
-  mod_remove_community,
-  mod_remove_post,
-  mod_feature_post,
-  mod_hide_community,
-  password_reset_request,
-  person,
-  person_aggregates,
-  person_ban,
-  person_block,
-  person_mention,
-  person_post_aggregates,
-  comment_reply,
-  post,
-  post_aggregates,
-  post_like,
-  post_read,
-  post_report,
-  post_saved,
-  private_message,
-  private_message_report,
-  site,
-  site_aggregates,
-  admin_purge_comment,
-  admin_purge_community,
-  admin_purge_person,
-  admin_purge_post,
-  email_verification,
-  registration_application,
-  language,
-  tagline,
-  local_user_language,
-  site_language,
-  community_language,
-  instance,
-  federation_allowlist,
-  federation_blocklist,
-  local_site,
-  local_site_rate_limit,
-  person_follower,
-  custom_emoji,
-  custom_emoji_keyword,
+diesel::joinable!(admin_purge_comment -> person (admin_person_id));
+diesel::joinable!(admin_purge_comment -> post (post_id));
+diesel::joinable!(admin_purge_community -> person (admin_person_id));
+diesel::joinable!(admin_purge_person -> person (admin_person_id));
+diesel::joinable!(admin_purge_post -> community (community_id));
+diesel::joinable!(admin_purge_post -> person (admin_person_id));
+diesel::joinable!(comment -> language (language_id));
+diesel::joinable!(comment -> person (creator_id));
+diesel::joinable!(comment -> post (post_id));
+diesel::joinable!(comment_aggregates -> comment (comment_id));
+diesel::joinable!(comment_like -> comment (comment_id));
+diesel::joinable!(comment_like -> person (person_id));
+diesel::joinable!(comment_like -> post (post_id));
+diesel::joinable!(comment_reply -> comment (comment_id));
+diesel::joinable!(comment_reply -> person (recipient_id));
+diesel::joinable!(comment_report -> comment (comment_id));
+diesel::joinable!(comment_saved -> comment (comment_id));
+diesel::joinable!(comment_saved -> person (person_id));
+diesel::joinable!(community -> instance (instance_id));
+diesel::joinable!(community_aggregates -> community (community_id));
+diesel::joinable!(community_block -> community (community_id));
+diesel::joinable!(community_block -> person (person_id));
+diesel::joinable!(community_follower -> community (community_id));
+diesel::joinable!(community_follower -> person (person_id));
+diesel::joinable!(community_language -> community (community_id));
+diesel::joinable!(community_language -> language (language_id));
+diesel::joinable!(community_moderator -> community (community_id));
+diesel::joinable!(community_moderator -> person (person_id));
+diesel::joinable!(community_person_ban -> community (community_id));
+diesel::joinable!(community_person_ban -> person (person_id));
+diesel::joinable!(custom_emoji -> local_site (local_site_id));
+diesel::joinable!(custom_emoji_keyword -> custom_emoji (custom_emoji_id));
+diesel::joinable!(email_verification -> local_user (local_user_id));
+diesel::joinable!(federation_allowlist -> instance (instance_id));
+diesel::joinable!(federation_blocklist -> instance (instance_id));
+diesel::joinable!(local_site -> site (site_id));
+diesel::joinable!(local_site_rate_limit -> local_site (local_site_id));
+diesel::joinable!(local_user -> person (person_id));
+diesel::joinable!(local_user_language -> language (language_id));
+diesel::joinable!(local_user_language -> local_user (local_user_id));
+diesel::joinable!(mod_add_community -> community (community_id));
+diesel::joinable!(mod_ban_from_community -> community (community_id));
+diesel::joinable!(mod_feature_post -> person (mod_person_id));
+diesel::joinable!(mod_feature_post -> post (post_id));
+diesel::joinable!(mod_hide_community -> community (community_id));
+diesel::joinable!(mod_hide_community -> person (mod_person_id));
+diesel::joinable!(mod_lock_post -> person (mod_person_id));
+diesel::joinable!(mod_lock_post -> post (post_id));
+diesel::joinable!(mod_remove_comment -> comment (comment_id));
+diesel::joinable!(mod_remove_comment -> person (mod_person_id));
+diesel::joinable!(mod_remove_community -> community (community_id));
+diesel::joinable!(mod_remove_community -> person (mod_person_id));
+diesel::joinable!(mod_remove_post -> person (mod_person_id));
+diesel::joinable!(mod_remove_post -> post (post_id));
+diesel::joinable!(mod_transfer_community -> community (community_id));
+diesel::joinable!(password_reset_request -> local_user (local_user_id));
+diesel::joinable!(person -> instance (instance_id));
+diesel::joinable!(person_aggregates -> person (person_id));
+diesel::joinable!(person_ban -> person (person_id));
+diesel::joinable!(person_mention -> comment (comment_id));
+diesel::joinable!(person_mention -> person (recipient_id));
+diesel::joinable!(person_post_aggregates -> person (person_id));
+diesel::joinable!(person_post_aggregates -> post (post_id));
+diesel::joinable!(post -> community (community_id));
+diesel::joinable!(post -> language (language_id));
+diesel::joinable!(post -> person (creator_id));
+diesel::joinable!(post_aggregates -> post (post_id));
+diesel::joinable!(post_like -> person (person_id));
+diesel::joinable!(post_like -> post (post_id));
+diesel::joinable!(post_read -> person (person_id));
+diesel::joinable!(post_read -> post (post_id));
+diesel::joinable!(post_report -> post (post_id));
+diesel::joinable!(post_saved -> person (person_id));
+diesel::joinable!(post_saved -> post (post_id));
+diesel::joinable!(private_message_report -> private_message (private_message_id));
+diesel::joinable!(registration_application -> local_user (local_user_id));
+diesel::joinable!(registration_application -> person (admin_id));
+diesel::joinable!(site -> instance (instance_id));
+diesel::joinable!(site_aggregates -> site (site_id));
+diesel::joinable!(site_language -> language (language_id));
+diesel::joinable!(site_language -> site (site_id));
+diesel::joinable!(tagline -> local_site (local_site_id));
+
+diesel::allow_tables_to_appear_in_same_query!(
+    activity,
+    admin_purge_comment,
+    admin_purge_community,
+    admin_purge_person,
+    admin_purge_post,
+    comment,
+    comment_aggregates,
+    comment_like,
+    comment_reply,
+    comment_report,
+    comment_saved,
+    community,
+    community_aggregates,
+    community_block,
+    community_follower,
+    community_language,
+    community_moderator,
+    community_person_ban,
+    custom_emoji,
+    custom_emoji_keyword,
+    email_verification,
+    federation_allowlist,
+    federation_blocklist,
+    instance,
+    language,
+    local_site,
+    local_site_rate_limit,
+    local_user,
+    local_user_language,
+    mod_add,
+    mod_add_community,
+    mod_ban,
+    mod_ban_from_community,
+    mod_feature_post,
+    mod_hide_community,
+    mod_lock_post,
+    mod_remove_comment,
+    mod_remove_community,
+    mod_remove_post,
+    mod_transfer_community,
+    password_reset_request,
+    person,
+    person_aggregates,
+    person_ban,
+    person_block,
+    person_follower,
+    person_mention,
+    person_post_aggregates,
+    post,
+    post_aggregates,
+    post_like,
+    post_read,
+    post_report,
+    post_saved,
+    private_message,
+    private_message_report,
+    registration_application,
+    secret,
+    site,
+    site_aggregates,
+    site_language,
+    tagline,
 );
index 55d7d6fb8458033906949727b356c9ef2e34e112..c5c8dd359ecc29f9512667a2df94e4683d66d4b1 100644 (file)
@@ -11,7 +11,7 @@ pub struct Activity {
   pub published: chrono::NaiveDateTime,
   pub updated: Option<chrono::NaiveDateTime>,
   pub ap_id: DbUrl,
-  pub sensitive: Option<bool>,
+  pub sensitive: bool,
 }
 
 #[derive(Insertable)]
@@ -30,5 +30,5 @@ pub struct ActivityUpdateForm {
   pub data: Option<Value>,
   pub local: Option<bool>,
   pub updated: Option<Option<chrono::NaiveDateTime>>,
-  pub sensitive: Option<Option<bool>>,
+  pub sensitive: Option<bool>,
 }
index d2db46f2baed7223f27c5457e98af400708501ce..a7f46644793c3d17dc9c104b50aa30b4b517e422 100644 (file)
@@ -33,15 +33,15 @@ pub struct Community {
   pub inbox_url: DbUrl,
   #[serde(skip)]
   pub shared_inbox_url: Option<DbUrl>,
+  pub hidden: bool,
+  pub posting_restricted_to_mods: bool,
+  pub instance_id: InstanceId,
   /// Url where moderators collection is served over Activitypub
   #[serde(skip)]
   pub moderators_url: Option<DbUrl>,
   /// Url where featured posts collection is served over Activitypub
   #[serde(skip)]
   pub featured_url: Option<DbUrl>,
-  pub hidden: bool,
-  pub posting_restricted_to_mods: bool,
-  pub instance_id: InstanceId,
 }
 
 #[derive(Debug, Clone, TypedBuilder)]
index a6c50cff5c29d05ef176b386aae1f90fa105833b..cdbc81a705eead9a897a7c768fdbda50df6daaf0 100644 (file)
@@ -11,10 +11,10 @@ use typed_builder::TypedBuilder;
 pub struct Instance {
   pub id: InstanceId,
   pub domain: String,
-  pub software: Option<String>,
-  pub version: Option<String>,
   pub published: chrono::NaiveDateTime,
   pub updated: Option<chrono::NaiveDateTime>,
+  pub software: Option<String>,
+  pub version: Option<String>,
 }
 
 #[derive(Clone, TypedBuilder)]
index 976516c5ff91ff03f88e922f7c90f3c5f2eb9eb6..55ca9579187f68f9d1cb6375a242d6735aa2274b 100644 (file)
@@ -1,6 +1,10 @@
-use crate::newtypes::{LocalSiteId, SiteId};
 #[cfg(feature = "full")]
 use crate::schema::local_site;
+use crate::{
+  newtypes::{LocalSiteId, SiteId},
+  ListingType,
+  RegistrationMode,
+};
 use serde::{Deserialize, Serialize};
 use typed_builder::TypedBuilder;
 
@@ -19,7 +23,7 @@ pub struct LocalSite {
   pub application_question: Option<String>,
   pub private_instance: bool,
   pub default_theme: String,
-  pub default_post_listing_type: String,
+  pub default_post_listing_type: ListingType,
   pub legal_information: Option<String>,
   pub hide_modlog_mod_names: bool,
   pub application_email_admins: bool,
@@ -30,10 +34,10 @@ pub struct LocalSite {
   pub federation_worker_count: i32,
   pub captcha_enabled: bool,
   pub captcha_difficulty: String,
-  pub registration_mode: RegistrationMode,
-  pub reports_email_admins: bool,
   pub published: chrono::NaiveDateTime,
   pub updated: Option<chrono::NaiveDateTime>,
+  pub registration_mode: RegistrationMode,
+  pub reports_email_admins: bool,
 }
 
 #[derive(Clone, TypedBuilder)]
@@ -51,7 +55,7 @@ pub struct LocalSiteInsertForm {
   pub application_question: Option<String>,
   pub private_instance: Option<bool>,
   pub default_theme: Option<String>,
-  pub default_post_listing_type: Option<String>,
+  pub default_post_listing_type: Option<ListingType>,
   pub legal_information: Option<String>,
   pub hide_modlog_mod_names: Option<bool>,
   pub application_email_admins: Option<bool>,
@@ -79,7 +83,7 @@ pub struct LocalSiteUpdateForm {
   pub application_question: Option<Option<String>>,
   pub private_instance: Option<bool>,
   pub default_theme: Option<String>,
-  pub default_post_listing_type: Option<String>,
+  pub default_post_listing_type: Option<ListingType>,
   pub legal_information: Option<Option<String>>,
   pub hide_modlog_mod_names: Option<bool>,
   pub application_email_admins: Option<bool>,
@@ -94,18 +98,3 @@ pub struct LocalSiteUpdateForm {
   pub reports_email_admins: Option<bool>,
   pub updated: Option<Option<chrono::NaiveDateTime>>,
 }
-
-#[cfg(feature = "full")]
-#[derive(SqlType)]
-#[diesel(postgres_type(name = "registration_mode_enum"))]
-pub struct RegistrationModeType;
-
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
-#[cfg_attr(feature = "full", derive(FromSqlRow, AsExpression))]
-#[cfg_attr(feature = "full", diesel(sql_type = RegistrationModeType))]
-#[serde(rename_all = "lowercase")]
-pub enum RegistrationMode {
-  Closed,
-  RequireApplication,
-  Open,
-}
index 2a10350e5887322fce69786c1d67bb547f9d22e1..86545a66f7e422ddf5ef6180fae911898fb590c2 100644 (file)
@@ -1,6 +1,10 @@
-use crate::newtypes::{LocalUserId, PersonId};
 #[cfg(feature = "full")]
 use crate::schema::local_user;
+use crate::{
+  newtypes::{LocalUserId, PersonId},
+  ListingType,
+  SortType,
+};
 use serde::{Deserialize, Serialize};
 use typed_builder::TypedBuilder;
 
@@ -15,14 +19,14 @@ pub struct LocalUser {
   pub email: Option<String>,
   pub show_nsfw: bool,
   pub theme: String,
-  pub default_sort_type: i16,
-  pub default_listing_type: i16,
+  pub default_sort_type: SortType,
+  pub default_listing_type: ListingType,
   pub interface_language: String,
   pub show_avatars: bool,
   pub send_notifications_to_email: bool,
   pub validator_time: chrono::NaiveDateTime,
-  pub show_bot_accounts: bool,
   pub show_scores: bool,
+  pub show_bot_accounts: bool,
   pub show_read_posts: bool,
   pub show_new_post_notifs: bool,
   pub email_verified: bool,
@@ -44,8 +48,8 @@ pub struct LocalUserInsertForm {
   pub email: Option<String>,
   pub show_nsfw: Option<bool>,
   pub theme: Option<String>,
-  pub default_sort_type: Option<i16>,
-  pub default_listing_type: Option<i16>,
+  pub default_sort_type: Option<SortType>,
+  pub default_listing_type: Option<ListingType>,
   pub interface_language: Option<String>,
   pub show_avatars: Option<bool>,
   pub send_notifications_to_email: Option<bool>,
@@ -68,8 +72,8 @@ pub struct LocalUserUpdateForm {
   pub email: Option<Option<String>>,
   pub show_nsfw: Option<bool>,
   pub theme: Option<String>,
-  pub default_sort_type: Option<i16>,
-  pub default_listing_type: Option<i16>,
+  pub default_sort_type: Option<SortType>,
+  pub default_listing_type: Option<ListingType>,
   pub interface_language: Option<String>,
   pub show_avatars: Option<bool>,
   pub send_notifications_to_email: Option<bool>,
index 5d9bda273d02b59af4da387b84fd6a570d5264f2..3c14fd0642457a12a8e3489cb0ce2279df885340 100644 (file)
@@ -27,7 +27,7 @@ pub struct ModRemovePost {
   pub mod_person_id: PersonId,
   pub post_id: PostId,
   pub reason: Option<String>,
-  pub removed: Option<bool>,
+  pub removed: bool,
   pub when_: chrono::NaiveDateTime,
 }
 
@@ -47,7 +47,7 @@ pub struct ModLockPost {
   pub id: i32,
   pub mod_person_id: PersonId,
   pub post_id: PostId,
-  pub locked: Option<bool>,
+  pub locked: bool,
   pub when_: chrono::NaiveDateTime,
 }
 
@@ -88,7 +88,7 @@ pub struct ModRemoveComment {
   pub mod_person_id: PersonId,
   pub comment_id: CommentId,
   pub reason: Option<String>,
-  pub removed: Option<bool>,
+  pub removed: bool,
   pub when_: chrono::NaiveDateTime,
 }
 
@@ -109,7 +109,7 @@ pub struct ModRemoveCommunity {
   pub mod_person_id: PersonId,
   pub community_id: CommunityId,
   pub reason: Option<String>,
-  pub removed: Option<bool>,
+  pub removed: bool,
   pub expires: Option<chrono::NaiveDateTime>,
   pub when_: chrono::NaiveDateTime,
 }
@@ -133,7 +133,7 @@ pub struct ModBanFromCommunity {
   pub other_person_id: PersonId,
   pub community_id: CommunityId,
   pub reason: Option<String>,
-  pub banned: Option<bool>,
+  pub banned: bool,
   pub expires: Option<chrono::NaiveDateTime>,
   pub when_: chrono::NaiveDateTime,
 }
@@ -157,7 +157,7 @@ pub struct ModBan {
   pub mod_person_id: PersonId,
   pub other_person_id: PersonId,
   pub reason: Option<String>,
-  pub banned: Option<bool>,
+  pub banned: bool,
   pub expires: Option<chrono::NaiveDateTime>,
   pub when_: chrono::NaiveDateTime,
 }
@@ -177,9 +177,9 @@ pub struct ModHideCommunity {
   pub id: i32,
   pub community_id: CommunityId,
   pub mod_person_id: PersonId,
-  pub reason: Option<String>,
-  pub hidden: Option<bool>,
   pub when_: chrono::NaiveDateTime,
+  pub reason: Option<String>,
+  pub hidden: bool,
 }
 
 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@@ -200,7 +200,7 @@ pub struct ModAddCommunity {
   pub mod_person_id: PersonId,
   pub other_person_id: PersonId,
   pub community_id: CommunityId,
-  pub removed: Option<bool>,
+  pub removed: bool,
   pub when_: chrono::NaiveDateTime,
 }
 
@@ -221,7 +221,6 @@ pub struct ModTransferCommunity {
   pub mod_person_id: PersonId,
   pub other_person_id: PersonId,
   pub community_id: CommunityId,
-  pub removed: Option<bool>,
   pub when_: chrono::NaiveDateTime,
 }
 
@@ -231,7 +230,6 @@ pub struct ModTransferCommunityForm {
   pub mod_person_id: PersonId,
   pub other_person_id: PersonId,
   pub community_id: CommunityId,
-  pub removed: Option<bool>,
 }
 
 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
@@ -241,7 +239,7 @@ pub struct ModAdd {
   pub id: i32,
   pub mod_person_id: PersonId,
   pub other_person_id: PersonId,
-  pub removed: Option<bool>,
+  pub removed: bool,
   pub when_: chrono::NaiveDateTime,
 }
 
index 0b14b3f49407ddee2b49ad1c6a5349d2ed6d3ac8..f0b68a1e658e1199a344b4c91ef46d6a78f69bdb 100644 (file)
@@ -22,10 +22,10 @@ pub struct Post {
   pub nsfw: bool,
   pub embed_title: Option<String>,
   pub embed_description: Option<String>,
-  pub embed_video_url: Option<DbUrl>,
   pub thumbnail_url: Option<DbUrl>,
   pub ap_id: DbUrl,
   pub local: bool,
+  pub embed_video_url: Option<DbUrl>,
   pub language_id: LanguageId,
   pub featured_community: bool,
   pub featured_local: bool,
index 88c2770234ee99184aea8b55fed185cfcfe4e319..6e10ee7b68eebc7a1fcfc0bddf61be2608b49e2d 100644 (file)
@@ -17,7 +17,7 @@ impl PersonBlockView {
     let target_person_alias = diesel::alias!(person as person1);
 
     let res = person_block::table
-      .inner_join(person::table)
+      .inner_join(person::table.on(person_block::person_id.eq(person::id)))
       .inner_join(
         target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
       )
index 72206e6d152d9a4c9ec834894eaec91dbd30230f..124e1ea43c64b9ea857fc0ea32271041bd0adebf 100644 (file)
@@ -1,7 +1,7 @@
 use actix_web::{error::ErrorBadRequest, web, Error, HttpResponse, Result};
 use anyhow::anyhow;
 use lemmy_api_common::context::LemmyContext;
-use lemmy_db_schema::source::local_site::RegistrationMode;
+use lemmy_db_schema::RegistrationMode;
 use lemmy_db_views::structs::SiteView;
 use lemmy_utils::{error::LemmyError, version};
 use serde::{Deserialize, Serialize};
diff --git a/diesel.toml b/diesel.toml
new file mode 100644 (file)
index 0000000..ce23d47
--- /dev/null
@@ -0,0 +1,3 @@
+[print_schema]
+file = "crates/db_schema/src/schema.rs"
+patch_file = "crates/db_schema/src/diesel_ltree.patch"
diff --git a/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/down.sql b/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/down.sql
new file mode 100644 (file)
index 0000000..5d5f2f3
--- /dev/null
@@ -0,0 +1,62 @@
+-- Some fixes
+alter table community alter column hidden drop not null;
+alter table community alter column posting_restricted_to_mods drop not null;
+alter table activity alter column sensitive drop not null;
+alter table mod_add alter column removed drop not null;
+alter table mod_add_community alter column removed drop not null;
+alter table mod_ban alter column banned drop not null;
+alter table mod_ban_from_community alter column banned drop not null;
+alter table mod_hide_community alter column hidden drop not null;
+alter table mod_lock_post alter column locked drop not null;
+alter table mod_remove_comment alter column removed drop not null;
+alter table mod_remove_community alter column removed drop not null;
+alter table mod_remove_post alter column removed drop not null;
+alter table mod_transfer_community add column removed boolean default false;
+alter table language alter column code drop not null;
+alter table language alter column name drop not null;
+
+-- Fix the registration mode enums
+ALTER TYPE registration_mode_enum RENAME VALUE 'Closed' TO 'closed';
+ALTER TYPE registration_mode_enum RENAME VALUE 'RequireApplication' TO 'require_application';
+ALTER TYPE registration_mode_enum RENAME VALUE 'Open' TO 'open';
+
+-- add back old columns
+
+-- Alter the local_user table
+alter table local_user alter column default_sort_type drop default;
+alter table local_user alter column default_sort_type type smallint using
+    case default_sort_type
+        when 'Active' then 0
+        when 'Hot' then 1
+        when 'New' then 2
+        when 'Old' then 3
+        when 'TopDay' then 4
+        when 'TopWeek' then 5
+        when 'TopMonth' then 6
+        when 'TopYear' then 7
+        when 'TopAll' then 8
+        when 'MostComments' then 9
+        when 'NewComments' then 10
+        else 0
+    end;
+alter table local_user alter column default_sort_type set default 0;
+
+alter table local_user alter column default_listing_type drop default;
+alter table local_user alter column default_listing_type type smallint using
+    case default_listing_type
+        when 'All' then 0
+        when 'Local' then 1
+        when 'Subscribed' then 2
+        else 1
+    end;
+alter table local_user alter column default_listing_type set default 1;
+
+-- Alter the local site column
+
+alter table local_site alter column default_post_listing_type drop default;
+alter table local_site alter column default_post_listing_type type text;
+alter table local_site alter column default_post_listing_type set default 1;
+
+-- Drop the types
+drop type listing_type_enum;
+drop type sort_type_enum;
diff --git a/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/up.sql b/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/up.sql
new file mode 100644 (file)
index 0000000..8474f34
--- /dev/null
@@ -0,0 +1,61 @@
+-- A few DB fixes
+alter table community alter column hidden set not null;
+alter table community alter column posting_restricted_to_mods set not null;
+alter table activity alter column sensitive set not null;
+alter table mod_add alter column removed set not null;
+alter table mod_add_community alter column removed set not null;
+alter table mod_ban alter column banned set not null;
+alter table mod_ban_from_community alter column banned set not null;
+alter table mod_hide_community alter column hidden set not null;
+alter table mod_lock_post alter column locked set not null;
+alter table mod_remove_comment alter column removed set not null;
+alter table mod_remove_community alter column removed set not null;
+alter table mod_remove_post alter column removed set not null;
+alter table mod_transfer_community drop column removed;
+alter table language alter column code set not null;
+alter table language alter column name set not null;
+
+-- Fix the registration mode enums
+ALTER TYPE registration_mode_enum RENAME VALUE 'closed' TO 'Closed';
+ALTER TYPE registration_mode_enum RENAME VALUE 'require_application' TO 'RequireApplication';
+ALTER TYPE registration_mode_enum RENAME VALUE 'open' TO 'Open';
+
+-- Create the enums
+
+CREATE TYPE sort_type_enum AS ENUM ('Active', 'Hot', 'New', 'Old', 'TopDay', 'TopWeek', 'TopMonth', 'TopYear', 'TopAll', 'MostComments', 'NewComments');
+  
+CREATE TYPE listing_type_enum AS ENUM ('All', 'Local', 'Subscribed');
+
+-- Alter the local_user table
+alter table local_user alter column default_sort_type drop default;
+alter table local_user alter column default_sort_type type sort_type_enum using
+    case default_sort_type
+        when 0 then 'Active'
+        when 1 then 'Hot'
+        when 2 then 'New'
+        when 3 then 'Old'
+        when 4 then 'TopDay'
+        when 5 then 'TopWeek'
+        when 6 then 'TopMonth'
+        when 7 then 'TopYear'
+        when 8 then 'TopAll'
+        when 9 then 'MostComments'
+        when 10 then 'NewComments'
+        else 'Active'
+    end :: sort_type_enum;
+alter table local_user alter column default_sort_type set default 'Active';
+
+alter table local_user alter column default_listing_type drop default;
+alter table local_user alter column default_listing_type type listing_type_enum using
+    case default_listing_type
+        when 0 then 'All'
+        when 1 then 'Local'
+        when 2 then 'Subscribed'
+        else 'Local'
+    end :: listing_type_enum;
+alter table local_user alter column default_listing_type set default 'Local';
+
+-- Alter the local site column
+alter table local_site alter column default_post_listing_type drop default;
+alter table local_site alter column default_post_listing_type type listing_type_enum using default_post_listing_type::listing_type_enum;
+alter table local_site alter column default_post_listing_type set default 'Local';