mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 03:11:08 +00:00
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
|
||||||
api_tests/node_modules
|
api_tests/node_modules
|
||||||
|
api_tests/.yalc
|
||||||
|
api_tests/yalc.lock
|
||||||
|
|
||||||
# pictrs data
|
# pictrs data
|
||||||
pictrs/
|
pictrs/
|
||||||
|
|
|
@ -95,6 +95,16 @@ pipeline:
|
||||||
# when:
|
# when:
|
||||||
# platform: linux/amd64
|
# 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:
|
cargo_test:
|
||||||
image: *muslrust_image
|
image: *muslrust_image
|
||||||
environment:
|
environment:
|
||||||
|
|
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -1340,6 +1340,18 @@ dependencies = [
|
||||||
"tokio-postgres",
|
"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]]
|
[[package]]
|
||||||
name = "diesel-derive-newtype"
|
name = "diesel-derive-newtype"
|
||||||
version = "2.0.0-rc.0"
|
version = "2.0.0-rc.0"
|
||||||
|
@ -2505,6 +2517,7 @@ dependencies = [
|
||||||
"deadpool",
|
"deadpool",
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-async",
|
"diesel-async",
|
||||||
|
"diesel-derive-enum",
|
||||||
"diesel-derive-newtype",
|
"diesel-derive-newtype",
|
||||||
"diesel_ltree",
|
"diesel_ltree",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
|
|
|
@ -93,6 +93,7 @@ sha2 = "0.10.6"
|
||||||
regex = "1.6.0"
|
regex = "1.6.0"
|
||||||
once_cell = "1.15.0"
|
once_cell = "1.15.0"
|
||||||
diesel-derive-newtype = "2.0.0-rc.0"
|
diesel-derive-newtype = "2.0.0-rc.0"
|
||||||
|
diesel-derive-enum = {version = "2.0.1", features = ["postgres"] }
|
||||||
strum = "0.24.1"
|
strum = "0.24.1"
|
||||||
strum_macros = "0.24.3"
|
strum_macros = "0.24.3"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
"eslint": "^8.25.0",
|
"eslint": "^8.25.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"jest": "^27.0.6",
|
"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",
|
"node-fetch": "^2.6.1",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"ts-jest": "^27.0.3",
|
"ts-jest": "^27.0.3",
|
||||||
|
|
|
@ -615,8 +615,8 @@ export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
|
||||||
let form: SaveUserSettings = {
|
let form: SaveUserSettings = {
|
||||||
show_nsfw: true,
|
show_nsfw: true,
|
||||||
theme: "darkly",
|
theme: "darkly",
|
||||||
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
|
default_sort_type: SortType.Active,
|
||||||
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
default_listing_type: ListingType.All,
|
||||||
interface_language: "en",
|
interface_language: "en",
|
||||||
show_avatars: true,
|
show_avatars: true,
|
||||||
send_notifications_to_email: false,
|
send_notifications_to_email: false,
|
||||||
|
@ -634,8 +634,8 @@ export async function saveUserSettingsFederated(
|
||||||
let bio = "a changed bio";
|
let bio = "a changed bio";
|
||||||
let form: SaveUserSettings = {
|
let form: SaveUserSettings = {
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
default_sort_type: Object.keys(SortType).indexOf(SortType.Hot),
|
default_sort_type: SortType.Hot,
|
||||||
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
default_listing_type: ListingType.All,
|
||||||
interface_language: "",
|
interface_language: "",
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
jest.setTimeout(120000);
|
jest.setTimeout(120000);
|
||||||
import { PersonViewSafe } from "lemmy-js-client";
|
import { PersonView } from "lemmy-js-client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
alpha,
|
alpha,
|
||||||
|
@ -25,10 +25,7 @@ beforeAll(async () => {
|
||||||
|
|
||||||
let apShortname: string;
|
let apShortname: string;
|
||||||
|
|
||||||
function assertUserFederation(
|
function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
|
||||||
userOne?: PersonViewSafe,
|
|
||||||
userTwo?: PersonViewSafe
|
|
||||||
) {
|
|
||||||
expect(userOne?.person.name).toBe(userTwo?.person.name);
|
expect(userOne?.person.name).toBe(userTwo?.person.name);
|
||||||
expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
|
expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
|
||||||
expect(userOne?.person.bio).toBe(userTwo?.person.bio);
|
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:
|
dependencies:
|
||||||
safe-buffer "~5.1.1"
|
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:
|
cross-spawn@^7.0.2, cross-spawn@^7.0.3:
|
||||||
version "7.0.3"
|
version "7.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
|
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"
|
combined-stream "^1.0.8"
|
||||||
mime-types "^2.1.12"
|
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:
|
fs.realpath@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
|
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"
|
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||||
|
|
||||||
lemmy-js-client@0.17.2-rc.1:
|
lemmy-js-client@0.17.2-rc.6:
|
||||||
version "0.17.2-rc.1"
|
version "0.17.2-rc.6"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.1.tgz#fe8d1508311bbf245acc98c2c3e47e2165a95b14"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.6.tgz#cd488bc30edf7b65a02b91f1bc295d1b958e9b86"
|
||||||
integrity sha512-YrOXuCofgkqp28krmPTQZAfUWL5zEDA0sRJ0abKcgf/I8YYkYkUkPS9TOORN5Lv3bc8RAAz4+2/zLHqYL/Tnow==
|
integrity sha512-/EdzpLJpYOq3ypCQA1MyI7sX0DmHUIA1ZUIda2XTCUUP7a5pltF7WHTicFrQ9j6JwCiFMTVkw6S/L8LzfD6cGA==
|
||||||
dependencies:
|
dependencies:
|
||||||
node-fetch "2.6.6"
|
cross-fetch "^3.1.5"
|
||||||
|
form-data "^4.0.0"
|
||||||
|
|
||||||
leven@^3.1.0:
|
leven@^3.1.0:
|
||||||
version "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"
|
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
||||||
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==
|
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==
|
||||||
|
|
||||||
node-fetch@2.6.6:
|
node-fetch@2.6.7, node-fetch@^2.6.1:
|
||||||
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:
|
|
||||||
version "2.6.7"
|
version "2.6.7"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
|
||||||
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
|
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
|
||||||
|
|
|
@ -76,7 +76,6 @@ impl Perform for TransferCommunity {
|
||||||
mod_person_id: local_user_view.person.id,
|
mod_person_id: local_user_view.person.id,
|
||||||
other_person_id: data.person_id,
|
other_person_id: data.person_id,
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
removed: Some(false),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ModTransferCommunity::create(context.pool(), &form).await?;
|
ModTransferCommunity::create(context.pool(), &form).await?;
|
||||||
|
|
|
@ -5,10 +5,9 @@ use lemmy_api_common::{
|
||||||
person::{LoginResponse, PasswordChangeAfterReset},
|
person::{LoginResponse, PasswordChangeAfterReset},
|
||||||
utils::password_length_check,
|
utils::password_length_check,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::{
|
||||||
local_site::RegistrationMode,
|
source::{local_user::LocalUser, password_reset_request::PasswordResetRequest},
|
||||||
local_user::LocalUser,
|
RegistrationMode,
|
||||||
password_reset_request::PasswordResetRequest,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::sensitive::Sensitive;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
|
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, PostView};
|
use lemmy_db_views::structs::{CommentView, PostView};
|
||||||
|
@ -55,8 +56,8 @@ pub struct SaveUserSettings {
|
||||||
pub show_nsfw: Option<bool>,
|
pub show_nsfw: Option<bool>,
|
||||||
pub show_scores: Option<bool>,
|
pub show_scores: Option<bool>,
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
pub default_sort_type: Option<i16>,
|
pub default_sort_type: Option<SortType>,
|
||||||
pub default_listing_type: Option<i16>,
|
pub default_listing_type: Option<ListingType>,
|
||||||
pub interface_language: Option<String>,
|
pub interface_language: Option<String>,
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
pub banner: Option<String>,
|
pub banner: Option<String>,
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
use crate::sensitive::Sensitive;
|
use crate::sensitive::Sensitive;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
|
newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
|
||||||
source::{
|
source::{instance::Instance, language::Language, tagline::Tagline},
|
||||||
instance::Instance,
|
|
||||||
language::Language,
|
|
||||||
local_site::RegistrationMode,
|
|
||||||
tagline::Tagline,
|
|
||||||
},
|
|
||||||
ListingType,
|
ListingType,
|
||||||
ModlogActionType,
|
ModlogActionType,
|
||||||
|
RegistrationMode,
|
||||||
SearchType,
|
SearchType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -128,7 +124,7 @@ pub struct CreateSite {
|
||||||
pub application_question: Option<String>,
|
pub application_question: Option<String>,
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
pub default_theme: Option<String>,
|
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 legal_information: Option<String>,
|
||||||
pub application_email_admins: Option<bool>,
|
pub application_email_admins: Option<bool>,
|
||||||
pub hide_modlog_mod_names: Option<bool>,
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
|
@ -173,7 +169,7 @@ pub struct EditSite {
|
||||||
pub application_question: Option<String>,
|
pub application_question: Option<String>,
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
pub default_theme: Option<String>,
|
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 legal_information: Option<String>,
|
||||||
pub application_email_admins: Option<bool>,
|
pub application_email_admins: Option<bool>,
|
||||||
pub hide_modlog_mod_names: Option<bool>,
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use lemmy_db_schema::{
|
||||||
community::{Community, CommunityModerator, CommunityUpdateForm},
|
community::{Community, CommunityModerator, CommunityUpdateForm},
|
||||||
email_verification::{EmailVerification, EmailVerificationForm},
|
email_verification::{EmailVerification, EmailVerificationForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
local_site::{LocalSite, RegistrationMode},
|
local_site::LocalSite,
|
||||||
local_site_rate_limit::LocalSiteRateLimit,
|
local_site_rate_limit::LocalSiteRateLimit,
|
||||||
password_reset_request::PasswordResetRequest,
|
password_reset_request::PasswordResetRequest,
|
||||||
person::{Person, PersonUpdateForm},
|
person::{Person, PersonUpdateForm},
|
||||||
|
@ -20,6 +20,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::{Crud, Readable},
|
traits::{Crud, Readable},
|
||||||
utils::DbPool,
|
utils::DbPool,
|
||||||
|
RegistrationMode,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
||||||
use lemmy_db_views_actor::structs::{
|
use lemmy_db_views_actor::structs::{
|
||||||
|
|
|
@ -112,7 +112,7 @@ impl PerformCrud for CreateSite {
|
||||||
.application_question(application_question)
|
.application_question(application_question)
|
||||||
.private_instance(data.private_instance)
|
.private_instance(data.private_instance)
|
||||||
.default_theme(data.default_theme.clone())
|
.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))
|
.legal_information(diesel_option_overwrite(&data.legal_information))
|
||||||
.application_email_admins(data.application_email_admins)
|
.application_email_admins(data.application_email_admins)
|
||||||
.hide_modlog_mod_names(data.hide_modlog_mod_names)
|
.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;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
mod create;
|
mod create;
|
||||||
|
|
|
@ -17,7 +17,7 @@ use lemmy_db_schema::{
|
||||||
actor_language::SiteLanguage,
|
actor_language::SiteLanguage,
|
||||||
federation_allowlist::FederationAllowList,
|
federation_allowlist::FederationAllowList,
|
||||||
federation_blocklist::FederationBlockList,
|
federation_blocklist::FederationBlockList,
|
||||||
local_site::{LocalSite, LocalSiteUpdateForm, RegistrationMode},
|
local_site::{LocalSite, LocalSiteUpdateForm},
|
||||||
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
|
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
|
||||||
local_user::LocalUser,
|
local_user::LocalUser,
|
||||||
site::{Site, SiteUpdateForm},
|
site::{Site, SiteUpdateForm},
|
||||||
|
@ -26,6 +26,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
|
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
|
||||||
ListingType,
|
ListingType,
|
||||||
|
RegistrationMode,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
|
@ -33,7 +34,6 @@ use lemmy_utils::{
|
||||||
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditSite {
|
impl PerformCrud for EditSite {
|
||||||
|
@ -74,10 +74,9 @@ impl PerformCrud for EditSite {
|
||||||
.unwrap_or(local_site.registration_mode),
|
.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
|
// only allow all or local as default listing types
|
||||||
let val = ListingType::from_str(default_post_listing_type);
|
if listing_type != &ListingType::All && listing_type != &ListingType::Local {
|
||||||
if val != Ok(ListingType::All) && val != Ok(ListingType::Local) {
|
|
||||||
return Err(LemmyError::from_message(
|
return Err(LemmyError::from_message(
|
||||||
"invalid_default_post_listing_type",
|
"invalid_default_post_listing_type",
|
||||||
));
|
));
|
||||||
|
@ -113,7 +112,7 @@ impl PerformCrud for EditSite {
|
||||||
.application_question(application_question)
|
.application_question(application_question)
|
||||||
.private_instance(data.private_instance)
|
.private_instance(data.private_instance)
|
||||||
.default_theme(data.default_theme.clone())
|
.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))
|
.legal_information(diesel_option_overwrite(&data.legal_information))
|
||||||
.application_email_admins(data.application_email_admins)
|
.application_email_admins(data.application_email_admins)
|
||||||
.hide_modlog_mod_names(data.hide_modlog_mod_names)
|
.hide_modlog_mod_names(data.hide_modlog_mod_names)
|
||||||
|
|
|
@ -20,12 +20,12 @@ use lemmy_api_common::{
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PersonAggregates,
|
aggregates::structs::PersonAggregates,
|
||||||
source::{
|
source::{
|
||||||
local_site::RegistrationMode,
|
|
||||||
local_user::{LocalUser, LocalUserInsertForm},
|
local_user::{LocalUser, LocalUserInsertForm},
|
||||||
person::{Person, PersonInsertForm},
|
person::{Person, PersonInsertForm},
|
||||||
registration_application::{RegistrationApplication, RegistrationApplicationInsertForm},
|
registration_application::{RegistrationApplication, RegistrationApplicationInsertForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
|
RegistrationMode,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
|
|
|
@ -2,7 +2,6 @@ use activitypub_federation::config::Data;
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
|
use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
mod list_comments;
|
mod list_comments;
|
||||||
mod list_posts;
|
mod list_posts;
|
||||||
|
@ -30,9 +29,7 @@ fn listing_type_with_default(
|
||||||
) -> Result<ListingType, LemmyError> {
|
) -> Result<ListingType, LemmyError> {
|
||||||
// On frontpage use listing type from param or admin configured default
|
// On frontpage use listing type from param or admin configured default
|
||||||
let listing_type = if community_id.is_none() {
|
let listing_type = if community_id.is_none() {
|
||||||
type_.unwrap_or(ListingType::from_str(
|
type_.unwrap_or(local_site.default_post_listing_type)
|
||||||
&local_site.default_post_listing_type,
|
|
||||||
)?)
|
|
||||||
} else {
|
} else {
|
||||||
// inside of community show everything
|
// inside of community show everything
|
||||||
ListingType::All
|
ListingType::All
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub(crate) async fn get_activity(
|
||||||
.into();
|
.into();
|
||||||
let activity = Activity::read_from_apub_id(context.pool(), &activity_id).await?;
|
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 {
|
if !activity.local {
|
||||||
Err(err_object_not_local())
|
Err(err_object_not_local())
|
||||||
} else if sensitive {
|
} else if sensitive {
|
||||||
|
|
|
@ -14,7 +14,7 @@ path = "src/lib.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
[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",
|
"activitypub_federation", "sha2", "regex", "once_cell", "serde_json", "diesel_ltree",
|
||||||
"diesel-async", "deadpool"]
|
"diesel-async", "deadpool"]
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ lemmy_utils = { workspace = true, optional = true }
|
||||||
bcrypt = { workspace = true, optional = true }
|
bcrypt = { workspace = true, optional = true }
|
||||||
diesel = { workspace = true, features = ["postgres","chrono", "serde_json"], optional = true }
|
diesel = { workspace = true, features = ["postgres","chrono", "serde_json"], optional = true }
|
||||||
diesel-derive-newtype = { workspace = true, optional = true }
|
diesel-derive-newtype = { workspace = true, optional = true }
|
||||||
|
diesel-derive-enum = { workspace = true, optional = true }
|
||||||
diesel_migrations = { workspace = true, optional = true }
|
diesel_migrations = { workspace = true, optional = true }
|
||||||
diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true }
|
diesel-async = { workspace = true, features = ["postgres", "deadpool"], optional = true }
|
||||||
sha2 = { workspace = true, 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,
|
id: inserted_activity.id,
|
||||||
data: test_json,
|
data: test_json,
|
||||||
local: true,
|
local: true,
|
||||||
sensitive: Some(false),
|
sensitive: false,
|
||||||
published: inserted_activity.published,
|
published: inserted_activity.published,
|
||||||
updated: None,
|
updated: None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,25 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::local_site::dsl::local_site,
|
schema::local_site::dsl::local_site,
|
||||||
source::local_site::{
|
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
||||||
LocalSite,
|
|
||||||
LocalSiteInsertForm,
|
|
||||||
LocalSiteUpdateForm,
|
|
||||||
RegistrationMode,
|
|
||||||
RegistrationModeType,
|
|
||||||
},
|
|
||||||
utils::{get_conn, DbPool},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
deserialize,
|
|
||||||
deserialize::FromSql,
|
|
||||||
dsl::insert_into,
|
|
||||||
pg::{Pg, PgValue},
|
|
||||||
result::Error,
|
|
||||||
serialize,
|
|
||||||
serialize::{IsNull, Output, ToSql},
|
|
||||||
};
|
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
impl LocalSite {
|
impl LocalSite {
|
||||||
pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
||||||
|
@ -45,25 +30,3 @@ impl LocalSite {
|
||||||
diesel::delete(local_site).execute(conn).await
|
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,
|
post_id: inserted_post.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: Some(true),
|
removed: true,
|
||||||
when_: inserted_mod_remove_post.when_,
|
when_: inserted_mod_remove_post.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ mod tests {
|
||||||
id: inserted_mod_lock_post.id,
|
id: inserted_mod_lock_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
locked: Some(true),
|
locked: true,
|
||||||
when_: inserted_mod_lock_post.when_,
|
when_: inserted_mod_lock_post.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -681,7 +681,7 @@ mod tests {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: Some(true),
|
removed: true,
|
||||||
when_: inserted_mod_remove_comment.when_,
|
when_: inserted_mod_remove_comment.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -707,7 +707,7 @@ mod tests {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: Some(true),
|
removed: true,
|
||||||
expires: None,
|
expires: None,
|
||||||
when_: inserted_mod_remove_community.when_,
|
when_: inserted_mod_remove_community.when_,
|
||||||
};
|
};
|
||||||
|
@ -736,7 +736,7 @@ mod tests {
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_person_id: inserted_person.id,
|
other_person_id: inserted_person.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
banned: Some(true),
|
banned: true,
|
||||||
expires: None,
|
expires: None,
|
||||||
when_: inserted_mod_ban_from_community.when_,
|
when_: inserted_mod_ban_from_community.when_,
|
||||||
};
|
};
|
||||||
|
@ -757,7 +757,7 @@ mod tests {
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_person_id: inserted_person.id,
|
other_person_id: inserted_person.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
banned: Some(true),
|
banned: true,
|
||||||
expires: None,
|
expires: None,
|
||||||
when_: inserted_mod_ban.when_,
|
when_: inserted_mod_ban.when_,
|
||||||
};
|
};
|
||||||
|
@ -781,7 +781,7 @@ mod tests {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_person_id: inserted_person.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: Some(false),
|
removed: false,
|
||||||
when_: inserted_mod_add_community.when_,
|
when_: inserted_mod_add_community.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -798,7 +798,7 @@ mod tests {
|
||||||
id: inserted_mod_add.id,
|
id: inserted_mod_add.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_person_id: inserted_person.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: Some(false),
|
removed: false,
|
||||||
when_: inserted_mod_add.when_,
|
when_: inserted_mod_add.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,14 @@ use crate::{
|
||||||
traits::{ApubActor, Crud, Followable},
|
traits::{ApubActor, Crud, Followable},
|
||||||
utils::{functions::lower, get_conn, naive_now, DbPool},
|
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;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -183,7 +190,7 @@ impl PersonFollower {
|
||||||
use crate::schema::{person, person_follower, person_follower::person_id};
|
use crate::schema::{person, person_follower, person_follower::person_id};
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_follower::table
|
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_))
|
.filter(person_id.eq(person_id_))
|
||||||
.select(person::all_columns)
|
.select(person::all_columns)
|
||||||
.load(conn)
|
.load(conn)
|
||||||
|
|
|
@ -6,6 +6,11 @@ extern crate diesel;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel_derive_newtype;
|
extern crate diesel_derive_newtype;
|
||||||
|
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel_derive_enum;
|
||||||
|
|
||||||
// this is used in tests
|
// this is used in tests
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -20,6 +25,7 @@ pub mod aggregates;
|
||||||
pub mod impls;
|
pub mod impls;
|
||||||
pub mod newtypes;
|
pub mod newtypes;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
#[rustfmt::skip]
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
pub mod source;
|
pub mod source;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -30,7 +36,13 @@ pub mod utils;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum_macros::{Display, EnumString};
|
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 {
|
pub enum SortType {
|
||||||
Active,
|
Active,
|
||||||
Hot,
|
Hot,
|
||||||
|
@ -54,12 +66,31 @@ pub enum CommentSortType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
|
#[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 {
|
pub enum ListingType {
|
||||||
All,
|
All,
|
||||||
Local,
|
Local,
|
||||||
Subscribed,
|
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)]
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
pub enum SearchType {
|
pub enum SearchType {
|
||||||
All,
|
All,
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,7 @@ pub struct Activity {
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
pub ap_id: DbUrl,
|
pub ap_id: DbUrl,
|
||||||
pub sensitive: Option<bool>,
|
pub sensitive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
|
@ -30,5 +30,5 @@ pub struct ActivityUpdateForm {
|
||||||
pub data: Option<Value>,
|
pub data: Option<Value>,
|
||||||
pub local: Option<bool>,
|
pub local: Option<bool>,
|
||||||
pub updated: Option<Option<chrono::NaiveDateTime>>,
|
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,
|
pub inbox_url: DbUrl,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub shared_inbox_url: Option<DbUrl>,
|
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
|
/// Url where moderators collection is served over Activitypub
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub moderators_url: Option<DbUrl>,
|
pub moderators_url: Option<DbUrl>,
|
||||||
/// Url where featured posts collection is served over Activitypub
|
/// Url where featured posts collection is served over Activitypub
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub featured_url: Option<DbUrl>,
|
pub featured_url: Option<DbUrl>,
|
||||||
pub hidden: bool,
|
|
||||||
pub posting_restricted_to_mods: bool,
|
|
||||||
pub instance_id: InstanceId,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, TypedBuilder)]
|
#[derive(Debug, Clone, TypedBuilder)]
|
||||||
|
|
|
@ -11,10 +11,10 @@ use typed_builder::TypedBuilder;
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
pub id: InstanceId,
|
pub id: InstanceId,
|
||||||
pub domain: String,
|
pub domain: String,
|
||||||
pub software: Option<String>,
|
|
||||||
pub version: Option<String>,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub software: Option<String>,
|
||||||
|
pub version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, TypedBuilder)]
|
#[derive(Clone, TypedBuilder)]
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
use crate::newtypes::{LocalSiteId, SiteId};
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use crate::schema::local_site;
|
use crate::schema::local_site;
|
||||||
|
use crate::{
|
||||||
|
newtypes::{LocalSiteId, SiteId},
|
||||||
|
ListingType,
|
||||||
|
RegistrationMode,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -19,7 +23,7 @@ pub struct LocalSite {
|
||||||
pub application_question: Option<String>,
|
pub application_question: Option<String>,
|
||||||
pub private_instance: bool,
|
pub private_instance: bool,
|
||||||
pub default_theme: String,
|
pub default_theme: String,
|
||||||
pub default_post_listing_type: String,
|
pub default_post_listing_type: ListingType,
|
||||||
pub legal_information: Option<String>,
|
pub legal_information: Option<String>,
|
||||||
pub hide_modlog_mod_names: bool,
|
pub hide_modlog_mod_names: bool,
|
||||||
pub application_email_admins: bool,
|
pub application_email_admins: bool,
|
||||||
|
@ -30,10 +34,10 @@ pub struct LocalSite {
|
||||||
pub federation_worker_count: i32,
|
pub federation_worker_count: i32,
|
||||||
pub captcha_enabled: bool,
|
pub captcha_enabled: bool,
|
||||||
pub captcha_difficulty: String,
|
pub captcha_difficulty: String,
|
||||||
pub registration_mode: RegistrationMode,
|
|
||||||
pub reports_email_admins: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub registration_mode: RegistrationMode,
|
||||||
|
pub reports_email_admins: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, TypedBuilder)]
|
#[derive(Clone, TypedBuilder)]
|
||||||
|
@ -51,7 +55,7 @@ pub struct LocalSiteInsertForm {
|
||||||
pub application_question: Option<String>,
|
pub application_question: Option<String>,
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
pub default_theme: Option<String>,
|
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 legal_information: Option<String>,
|
||||||
pub hide_modlog_mod_names: Option<bool>,
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
pub application_email_admins: Option<bool>,
|
pub application_email_admins: Option<bool>,
|
||||||
|
@ -79,7 +83,7 @@ pub struct LocalSiteUpdateForm {
|
||||||
pub application_question: Option<Option<String>>,
|
pub application_question: Option<Option<String>>,
|
||||||
pub private_instance: Option<bool>,
|
pub private_instance: Option<bool>,
|
||||||
pub default_theme: Option<String>,
|
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 legal_information: Option<Option<String>>,
|
||||||
pub hide_modlog_mod_names: Option<bool>,
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
pub application_email_admins: Option<bool>,
|
pub application_email_admins: Option<bool>,
|
||||||
|
@ -94,18 +98,3 @@ pub struct LocalSiteUpdateForm {
|
||||||
pub reports_email_admins: Option<bool>,
|
pub reports_email_admins: Option<bool>,
|
||||||
pub updated: Option<Option<chrono::NaiveDateTime>>,
|
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")]
|
#[cfg(feature = "full")]
|
||||||
use crate::schema::local_user;
|
use crate::schema::local_user;
|
||||||
|
use crate::{
|
||||||
|
newtypes::{LocalUserId, PersonId},
|
||||||
|
ListingType,
|
||||||
|
SortType,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -15,14 +19,14 @@ pub struct LocalUser {
|
||||||
pub email: Option<String>,
|
pub email: Option<String>,
|
||||||
pub show_nsfw: bool,
|
pub show_nsfw: bool,
|
||||||
pub theme: String,
|
pub theme: String,
|
||||||
pub default_sort_type: i16,
|
pub default_sort_type: SortType,
|
||||||
pub default_listing_type: i16,
|
pub default_listing_type: ListingType,
|
||||||
pub interface_language: String,
|
pub interface_language: String,
|
||||||
pub show_avatars: bool,
|
pub show_avatars: bool,
|
||||||
pub send_notifications_to_email: bool,
|
pub send_notifications_to_email: bool,
|
||||||
pub validator_time: chrono::NaiveDateTime,
|
pub validator_time: chrono::NaiveDateTime,
|
||||||
pub show_bot_accounts: bool,
|
|
||||||
pub show_scores: bool,
|
pub show_scores: bool,
|
||||||
|
pub show_bot_accounts: bool,
|
||||||
pub show_read_posts: bool,
|
pub show_read_posts: bool,
|
||||||
pub show_new_post_notifs: bool,
|
pub show_new_post_notifs: bool,
|
||||||
pub email_verified: bool,
|
pub email_verified: bool,
|
||||||
|
@ -44,8 +48,8 @@ pub struct LocalUserInsertForm {
|
||||||
pub email: Option<String>,
|
pub email: Option<String>,
|
||||||
pub show_nsfw: Option<bool>,
|
pub show_nsfw: Option<bool>,
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
pub default_sort_type: Option<i16>,
|
pub default_sort_type: Option<SortType>,
|
||||||
pub default_listing_type: Option<i16>,
|
pub default_listing_type: Option<ListingType>,
|
||||||
pub interface_language: Option<String>,
|
pub interface_language: Option<String>,
|
||||||
pub show_avatars: Option<bool>,
|
pub show_avatars: Option<bool>,
|
||||||
pub send_notifications_to_email: Option<bool>,
|
pub send_notifications_to_email: Option<bool>,
|
||||||
|
@ -68,8 +72,8 @@ pub struct LocalUserUpdateForm {
|
||||||
pub email: Option<Option<String>>,
|
pub email: Option<Option<String>>,
|
||||||
pub show_nsfw: Option<bool>,
|
pub show_nsfw: Option<bool>,
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
pub default_sort_type: Option<i16>,
|
pub default_sort_type: Option<SortType>,
|
||||||
pub default_listing_type: Option<i16>,
|
pub default_listing_type: Option<ListingType>,
|
||||||
pub interface_language: Option<String>,
|
pub interface_language: Option<String>,
|
||||||
pub show_avatars: Option<bool>,
|
pub show_avatars: Option<bool>,
|
||||||
pub send_notifications_to_email: Option<bool>,
|
pub send_notifications_to_email: Option<bool>,
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct ModRemovePost {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub post_id: PostId,
|
pub post_id: PostId,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: bool,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ pub struct ModLockPost {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub post_id: PostId,
|
pub post_id: PostId,
|
||||||
pub locked: Option<bool>,
|
pub locked: bool,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ pub struct ModRemoveComment {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub comment_id: CommentId,
|
pub comment_id: CommentId,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: bool,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ pub struct ModRemoveCommunity {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: bool,
|
||||||
pub expires: Option<chrono::NaiveDateTime>,
|
pub expires: Option<chrono::NaiveDateTime>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ pub struct ModBanFromCommunity {
|
||||||
pub other_person_id: PersonId,
|
pub other_person_id: PersonId,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub banned: Option<bool>,
|
pub banned: bool,
|
||||||
pub expires: Option<chrono::NaiveDateTime>,
|
pub expires: Option<chrono::NaiveDateTime>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ pub struct ModBan {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub other_person_id: PersonId,
|
pub other_person_id: PersonId,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub banned: Option<bool>,
|
pub banned: bool,
|
||||||
pub expires: Option<chrono::NaiveDateTime>,
|
pub expires: Option<chrono::NaiveDateTime>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -177,9 +177,9 @@ pub struct ModHideCommunity {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub reason: Option<String>,
|
|
||||||
pub hidden: Option<bool>,
|
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
|
pub reason: Option<String>,
|
||||||
|
pub hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||||
|
@ -200,7 +200,7 @@ pub struct ModAddCommunity {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub other_person_id: PersonId,
|
pub other_person_id: PersonId,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub removed: Option<bool>,
|
pub removed: bool,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,6 @@ pub struct ModTransferCommunity {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub other_person_id: PersonId,
|
pub other_person_id: PersonId,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub removed: Option<bool>,
|
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +230,6 @@ pub struct ModTransferCommunityForm {
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub other_person_id: PersonId,
|
pub other_person_id: PersonId,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub removed: Option<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
|
@ -241,7 +239,7 @@ pub struct ModAdd {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_person_id: PersonId,
|
pub mod_person_id: PersonId,
|
||||||
pub other_person_id: PersonId,
|
pub other_person_id: PersonId,
|
||||||
pub removed: Option<bool>,
|
pub removed: bool,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,10 @@ pub struct Post {
|
||||||
pub nsfw: bool,
|
pub nsfw: bool,
|
||||||
pub embed_title: Option<String>,
|
pub embed_title: Option<String>,
|
||||||
pub embed_description: Option<String>,
|
pub embed_description: Option<String>,
|
||||||
pub embed_video_url: Option<DbUrl>,
|
|
||||||
pub thumbnail_url: Option<DbUrl>,
|
pub thumbnail_url: Option<DbUrl>,
|
||||||
pub ap_id: DbUrl,
|
pub ap_id: DbUrl,
|
||||||
pub local: bool,
|
pub local: bool,
|
||||||
|
pub embed_video_url: Option<DbUrl>,
|
||||||
pub language_id: LanguageId,
|
pub language_id: LanguageId,
|
||||||
pub featured_community: bool,
|
pub featured_community: bool,
|
||||||
pub featured_local: bool,
|
pub featured_local: bool,
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl PersonBlockView {
|
||||||
let target_person_alias = diesel::alias!(person as person1);
|
let target_person_alias = diesel::alias!(person as person1);
|
||||||
|
|
||||||
let res = person_block::table
|
let res = person_block::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table.on(person_block::person_id.eq(person::id)))
|
||||||
.inner_join(
|
.inner_join(
|
||||||
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
|
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 actix_web::{error::ErrorBadRequest, web, Error, HttpResponse, Result};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::context::LemmyContext;
|
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_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{error::LemmyError, version};
|
use lemmy_utils::{error::LemmyError, version};
|
||||||
use serde::{Deserialize, Serialize};
|
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