From: Dessalines Date: Mon, 17 Apr 2023 19:19:51 +0000 (-0400) Subject: Adding diesel enums for SortType and ListingType (#2808) X-Git-Url: http://these/git/%22https:/nerdica.net/photo/contact/80/maint-mode.css?a=commitdiff_plain;h=d8722b6e91a79878001d968150687d25c5d6905e;p=lemmy.git Adding diesel enums for SortType and ListingType (#2808) * 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 --- diff --git a/.gitignore b/.gitignore index ea0a2585..2a689fe7 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ query_testing/**/reports/*.json # API tests api_tests/node_modules +api_tests/.yalc +api_tests/yalc.lock # pictrs data pictrs/ diff --git a/.woodpecker.yml b/.woodpecker.yml index 9bed578c..74061409 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -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: diff --git a/Cargo.lock b/Cargo.lock index b98acdc2..77681962 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 52e1a8be..9c8dcab0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/api_tests/package.json b/api_tests/package.json index 2901a375..3237d22a 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -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", diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 835f119c..b8e97db0 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -615,8 +615,8 @@ export async function saveUserSettingsBio(api: API): Promise { 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, diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 4b4eaab3..b2083c66 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -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); diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index 1a1d7979..eaab0c47 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -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== diff --git a/crates/api/src/community/transfer.rs b/crates/api/src/community/transfer.rs index c163b195..a34dfb40 100644 --- a/crates/api/src/community/transfer.rs +++ b/crates/api/src/community/transfer.rs @@ -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?; diff --git a/crates/api/src/local_user/change_password_after_reset.rs b/crates/api/src/local_user/change_password_after_reset.rs index 392fcaa3..04571e47 100644 --- a/crates/api/src/local_user/change_password_after_reset.rs +++ b/crates/api/src/local_user/change_password_after_reset.rs @@ -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}; diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index b6a59ec4..10a0e806 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -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, pub show_scores: Option, pub theme: Option, - pub default_sort_type: Option, - pub default_listing_type: Option, + pub default_sort_type: Option, + pub default_listing_type: Option, pub interface_language: Option, pub avatar: Option, pub banner: Option, diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index a290beb1..8e559514 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -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, pub private_instance: Option, pub default_theme: Option, - pub default_post_listing_type: Option, + pub default_post_listing_type: Option, pub legal_information: Option, pub application_email_admins: Option, pub hide_modlog_mod_names: Option, @@ -173,7 +169,7 @@ pub struct EditSite { pub application_question: Option, pub private_instance: Option, pub default_theme: Option, - pub default_post_listing_type: Option, + pub default_post_listing_type: Option, pub legal_information: Option, pub application_email_admins: Option, pub hide_modlog_mod_names: Option, diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index c94a799d..ee3ee844 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -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::{ diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index ecafa9b2..d45caaa8 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -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) diff --git a/crates/api_crud/src/site/mod.rs b/crates/api_crud/src/site/mod.rs index 5155e3d0..d0c09b93 100644 --- a/crates/api_crud/src/site/mod.rs +++ b/crates/api_crud/src/site/mod.rs @@ -1,4 +1,4 @@ -use lemmy_db_schema::source::local_site::RegistrationMode; +use lemmy_db_schema::RegistrationMode; use lemmy_utils::error::LemmyError; mod create; diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index eb29a6da..03ff5901 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -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) diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index f90393c2..8ae6de39 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -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::{ diff --git a/crates/apub/src/api/mod.rs b/crates/apub/src/api/mod.rs index 1b2217a8..9099dbd0 100644 --- a/crates/apub/src/api/mod.rs +++ b/crates/apub/src/api/mod.rs @@ -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 { // 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 diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index 7a4a362f..0b8c8f15 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -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 { diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 87278a20..8a390fe1 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -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 index 00000000..d7d49f03 --- /dev/null +++ b/crates/db_schema/src/diesel_ltree.patch @@ -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, diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index a19d20f3..9187e736 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -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, }; diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index dd3d06d6..b9e920d1 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -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 { @@ -45,25 +30,3 @@ impl LocalSite { diesel::delete(local_site).execute(conn).await } } - -impl ToSql 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 for RegistrationMode { - fn from_sql(bytes: PgValue<'_>) -> deserialize::Result { - 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()), - } - } -} diff --git a/crates/db_schema/src/impls/moderator.rs b/crates/db_schema/src/impls/moderator.rs index 7540e487..ab8398cf 100644 --- a/crates/db_schema/src/impls/moderator.rs +++ b/crates/db_schema/src/impls/moderator.rs @@ -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_, }; diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 032e2e01..2c315e9c 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -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) diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index b0e56393..055c68e0 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -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, diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index b4fbefe2..f2ccf5e2 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -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, ap_id -> Text, - sensitive -> Nullable, + sensitive -> Bool, + } +} + +diesel::table! { + admin_purge_comment (id) { + id -> Int4, + admin_person_id -> Int4, + post_id -> Int4, + reason -> Nullable, + when_ -> Timestamp, + } +} + +diesel::table! { + admin_purge_community (id) { + id -> Int4, + admin_person_id -> Int4, + reason -> Nullable, + 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, + when_ -> Timestamp, + } +} + +diesel::table! { + admin_purge_post (id) { + id -> Int4, + admin_person_id -> Int4, + community_id -> Int4, + reason -> Nullable, + 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, public_key -> Text, last_refreshed_at -> Timestamp, - icon -> Nullable, - banner -> Nullable, + icon -> Nullable, + banner -> Nullable, followers_url -> Varchar, inbox_url -> Varchar, shared_inbox_url -> Nullable, - moderators_url -> Nullable, - featured_url -> Nullable, hidden -> Bool, posting_restricted_to_mods -> Bool, instance_id -> Int4, + moderators_url -> Nullable, + featured_url -> Nullable, } } -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, + } +} + +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, + } +} + +diesel::table! { + federation_blocklist (id) { + id -> Int4, + instance_id -> Int4, + published -> Timestamp, + updated -> Nullable, + } +} + +diesel::table! { + instance (id) { + id -> Int4, + domain -> Varchar, + published -> Timestamp, + updated -> Nullable, + software -> Nullable, + version -> Nullable, + } +} + +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, + private_instance -> Bool, + default_theme -> Text, + default_post_listing_type -> ListingTypeEnum, + legal_information -> Nullable, + hide_modlog_mod_names -> Bool, + application_email_admins -> Bool, + slur_filter_regex -> Nullable, + 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, + 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, + } +} + +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, 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, - 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, + 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, + removed -> Bool, when_ -> Timestamp, } } -table! { +diesel::table! { mod_ban (id) { id -> Int4, mod_person_id -> Int4, other_person_id -> Int4, reason -> Nullable, - banned -> Nullable, + banned -> Bool, expires -> Nullable, 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, - banned -> Nullable, + banned -> Bool, expires -> Nullable, 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, + hidden -> Bool, + } +} + +diesel::table! { mod_lock_post (id) { id -> Int4, mod_person_id -> Int4, post_id -> Int4, - locked -> Nullable, + locked -> Bool, when_ -> Timestamp, } } -table! { +diesel::table! { mod_remove_comment (id) { id -> Int4, mod_person_id -> Int4, comment_id -> Int4, reason -> Nullable, - removed -> Nullable, + removed -> Bool, when_ -> Timestamp, } } -table! { +diesel::table! { mod_remove_community (id) { id -> Int4, mod_person_id -> Int4, community_id -> Int4, reason -> Nullable, - removed -> Nullable, + removed -> Bool, expires -> Nullable, when_ -> Timestamp, } } -table! { +diesel::table! { mod_remove_post (id) { id -> Int4, mod_person_id -> Int4, post_id -> Int4, reason -> Nullable, - removed -> Nullable, + 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, - avatar -> Nullable, + avatar -> Nullable, banned -> Bool, published -> Timestamp, updated -> Nullable, @@ -311,7 +537,7 @@ table! { private_key -> Nullable, public_key -> Text, last_refreshed_at -> Timestamp, - banner -> Nullable, + banner -> Nullable, deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, @@ -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, + url -> Nullable, body -> Nullable, creator_id -> Int4, community_id -> Int4, @@ -378,27 +623,17 @@ table! { nsfw -> Bool, embed_title -> Nullable, embed_description -> Nullable, - embed_video_url -> Nullable, thumbnail_url -> Nullable, ap_id -> Varchar, local -> Bool, + embed_video_url -> Nullable, 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, + deny_reason -> Nullable, + published -> Timestamp, + } +} + +diesel::table! { + secret (id) { + id -> Int4, + jwt_secret -> Varchar, + } +} + +diesel::table! { site (id) { id -> Int4, name -> Varchar, sidebar -> Nullable, published -> Timestamp, updated -> Nullable, - icon -> Nullable, - banner -> Nullable, - description -> Nullable, - actor_id -> Text, + icon -> Nullable, + banner -> Nullable, + description -> Nullable, + actor_id -> Varchar, last_refreshed_at -> Timestamp, - inbox_url -> Text, + inbox_url -> Varchar, private_key -> Nullable, 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, - 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, - when_ -> Timestamp, - } -} - -table! { - admin_purge_person (id) { - id -> Int4, - admin_person_id -> Int4, - reason -> Nullable, - when_ -> Timestamp, - } -} - -table! { - admin_purge_post (id) { - id -> Int4, - admin_person_id -> Int4, - community_id -> Int4, - reason -> Nullable, - when_ -> Timestamp, - } -} - -table! { - registration_application (id) { - id -> Int4, - local_user_id -> Int4, - answer -> Text, - admin_id -> Nullable, - deny_reason -> Nullable, - published -> Timestamp, - } -} - -table! { - mod_hide_community (id) { - id -> Int4, - community_id -> Int4, - mod_person_id -> Int4, - reason -> Nullable, - hidden -> Nullable, - 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, - version -> Nullable, - published -> Timestamp, - updated -> Nullable, - } -} - -table! { - federation_allowlist(id) { - id -> Int4, - instance_id -> Int4, - published -> Timestamp, - updated -> Nullable, - } -} - -table! { - federation_blocklist(id) { - id -> Int4, - instance_id -> Int4, - published -> Timestamp, - updated -> Nullable, - } -} - -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, - private_instance -> Bool, - default_theme -> Text, - default_post_listing_type -> Text, - legal_information -> Nullable, - hide_modlog_mod_names -> Bool, - application_email_admins -> Bool, - slur_filter_regex -> Nullable, - 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, - } -} - -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, - } -} - -table! { - tagline(id) { - id -> Int4, - local_site_id -> Int4, - content -> Text, - published -> Timestamp, - updated -> Nullable, - } -} - -table! { - person_follower (id) { - id -> Int4, - person_id -> Int4, - follower_id -> Int4, + local_site_id -> Int4, + content -> Text, published -> Timestamp, - pending -> Bool, + updated -> Nullable, } } -table! { - custom_emoji (id) { - id -> Int4, - local_site_id -> Int4, - shortcode -> Varchar, - image_url -> Text, - alt_text -> Text, - category -> Text, - published -> Timestamp, - updated -> Nullable, - } -} - -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, ); diff --git a/crates/db_schema/src/source/activity.rs b/crates/db_schema/src/source/activity.rs index 55d7d6fb..c5c8dd35 100644 --- a/crates/db_schema/src/source/activity.rs +++ b/crates/db_schema/src/source/activity.rs @@ -11,7 +11,7 @@ pub struct Activity { pub published: chrono::NaiveDateTime, pub updated: Option, pub ap_id: DbUrl, - pub sensitive: Option, + pub sensitive: bool, } #[derive(Insertable)] @@ -30,5 +30,5 @@ pub struct ActivityUpdateForm { pub data: Option, pub local: Option, pub updated: Option>, - pub sensitive: Option>, + pub sensitive: Option, } diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index d2db46f2..a7f46644 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -33,15 +33,15 @@ pub struct Community { pub inbox_url: DbUrl, #[serde(skip)] pub shared_inbox_url: Option, + 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, /// Url where featured posts collection is served over Activitypub #[serde(skip)] pub featured_url: Option, - pub hidden: bool, - pub posting_restricted_to_mods: bool, - pub instance_id: InstanceId, } #[derive(Debug, Clone, TypedBuilder)] diff --git a/crates/db_schema/src/source/instance.rs b/crates/db_schema/src/source/instance.rs index a6c50cff..cdbc81a7 100644 --- a/crates/db_schema/src/source/instance.rs +++ b/crates/db_schema/src/source/instance.rs @@ -11,10 +11,10 @@ use typed_builder::TypedBuilder; pub struct Instance { pub id: InstanceId, pub domain: String, - pub software: Option, - pub version: Option, pub published: chrono::NaiveDateTime, pub updated: Option, + pub software: Option, + pub version: Option, } #[derive(Clone, TypedBuilder)] diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index 976516c5..55ca9579 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -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, pub private_instance: bool, pub default_theme: String, - pub default_post_listing_type: String, + pub default_post_listing_type: ListingType, pub legal_information: Option, 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, + pub registration_mode: RegistrationMode, + pub reports_email_admins: bool, } #[derive(Clone, TypedBuilder)] @@ -51,7 +55,7 @@ pub struct LocalSiteInsertForm { pub application_question: Option, pub private_instance: Option, pub default_theme: Option, - pub default_post_listing_type: Option, + pub default_post_listing_type: Option, pub legal_information: Option, pub hide_modlog_mod_names: Option, pub application_email_admins: Option, @@ -79,7 +83,7 @@ pub struct LocalSiteUpdateForm { pub application_question: Option>, pub private_instance: Option, pub default_theme: Option, - pub default_post_listing_type: Option, + pub default_post_listing_type: Option, pub legal_information: Option>, pub hide_modlog_mod_names: Option, pub application_email_admins: Option, @@ -94,18 +98,3 @@ pub struct LocalSiteUpdateForm { pub reports_email_admins: Option, pub updated: Option>, } - -#[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, -} diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 2a10350e..86545a66 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -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, 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, pub show_nsfw: Option, pub theme: Option, - pub default_sort_type: Option, - pub default_listing_type: Option, + pub default_sort_type: Option, + pub default_listing_type: Option, pub interface_language: Option, pub show_avatars: Option, pub send_notifications_to_email: Option, @@ -68,8 +72,8 @@ pub struct LocalUserUpdateForm { pub email: Option>, pub show_nsfw: Option, pub theme: Option, - pub default_sort_type: Option, - pub default_listing_type: Option, + pub default_sort_type: Option, + pub default_listing_type: Option, pub interface_language: Option, pub show_avatars: Option, pub send_notifications_to_email: Option, diff --git a/crates/db_schema/src/source/moderator.rs b/crates/db_schema/src/source/moderator.rs index 5d9bda27..3c14fd06 100644 --- a/crates/db_schema/src/source/moderator.rs +++ b/crates/db_schema/src/source/moderator.rs @@ -27,7 +27,7 @@ pub struct ModRemovePost { pub mod_person_id: PersonId, pub post_id: PostId, pub reason: Option, - pub removed: Option, + 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, + 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, - pub removed: Option, + 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, - pub removed: Option, + pub removed: bool, pub expires: Option, pub when_: chrono::NaiveDateTime, } @@ -133,7 +133,7 @@ pub struct ModBanFromCommunity { pub other_person_id: PersonId, pub community_id: CommunityId, pub reason: Option, - pub banned: Option, + pub banned: bool, pub expires: Option, pub when_: chrono::NaiveDateTime, } @@ -157,7 +157,7 @@ pub struct ModBan { pub mod_person_id: PersonId, pub other_person_id: PersonId, pub reason: Option, - pub banned: Option, + pub banned: bool, pub expires: Option, 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, - pub hidden: Option, pub when_: chrono::NaiveDateTime, + pub reason: Option, + 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, + 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, 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, } #[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, + pub removed: bool, pub when_: chrono::NaiveDateTime, } diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index 0b14b3f4..f0b68a1e 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -22,10 +22,10 @@ pub struct Post { pub nsfw: bool, pub embed_title: Option, pub embed_description: Option, - pub embed_video_url: Option, pub thumbnail_url: Option, pub ap_id: DbUrl, pub local: bool, + pub embed_video_url: Option, pub language_id: LanguageId, pub featured_community: bool, pub featured_local: bool, diff --git a/crates/db_views_actor/src/person_block_view.rs b/crates/db_views_actor/src/person_block_view.rs index 88c27702..6e10ee7b 100644 --- a/crates/db_views_actor/src/person_block_view.rs +++ b/crates/db_views_actor/src/person_block_view.rs @@ -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))), ) diff --git a/crates/routes/src/nodeinfo.rs b/crates/routes/src/nodeinfo.rs index 72206e6d..124e1ea4 100644 --- a/crates/routes/src/nodeinfo.rs +++ b/crates/routes/src/nodeinfo.rs @@ -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 index 00000000..ce23d470 --- /dev/null +++ b/diesel.toml @@ -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 index 00000000..5d5f2f3a --- /dev/null +++ b/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/down.sql @@ -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 index 00000000..8474f34e --- /dev/null +++ b/migrations/2023-04-14-175955_add_listingtype_sorttype_enums/up.sql @@ -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';