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
This commit is contained in:
parent
f5511cfd25
commit
d8722b6e91
39 changed files with 867 additions and 671 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -18,6 +18,8 @@ query_testing/**/reports/*.json
|
|||
|
||||
# API tests
|
||||
api_tests/node_modules
|
||||
api_tests/.yalc
|
||||
api_tests/yalc.lock
|
||||
|
||||
# pictrs data
|
||||
pictrs/
|
||||
|
|
|
@ -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:
|
||||
|
|
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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==
|
||||
|
|
|
@ -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?;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lemmy_db_schema::source::local_site::RegistrationMode;
|
||||
use lemmy_db_schema::RegistrationMode;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
||||
mod create;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 }
|
||||
|
|
36
crates/db_schema/src/diesel_ltree.patch
Normal file
36
crates/db_schema/src/diesel_ltree.patch
Normal file
|
@ -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,
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_,
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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>,
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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))),
|
||||
)
|
||||
|
|
|
@ -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};
|
||||
|
|
3
diesel.toml
Normal file
3
diesel.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[print_schema]
|
||||
file = "crates/db_schema/src/schema.rs"
|
||||
patch_file = "crates/db_schema/src/diesel_ltree.patch"
|
|
@ -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;
|
|
@ -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';
|
Loading…
Reference in a new issue