diff --git a/Cargo.lock b/Cargo.lock index 1c687495e..94047f9b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2637,6 +2637,13 @@ dependencies = [ "uuid", ] +[[package]] +name = "lemmy_db_migrations" +version = "0.17.1" +dependencies = [ + "diesel_migrations", +] + [[package]] name = "lemmy_db_schema" version = "0.17.1" @@ -2652,6 +2659,7 @@ dependencies = [ "diesel-derive-newtype", "diesel_ltree", "diesel_migrations", + "lemmy_db_migrations", "lemmy_utils", "once_cell", "regex", diff --git a/Cargo.toml b/Cargo.toml index f275ddbf8..4d38ea265 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ members = [ "crates/db_views", "crates/db_views_actor", "crates/db_views_actor", + "crates/db_migrations", "crates/routes" ] @@ -59,6 +60,7 @@ lemmy_routes = { version = "=0.17.1", path = "./crates/routes" } lemmy_db_views = { version = "=0.17.1", path = "./crates/db_views" } lemmy_db_views_actor = { version = "=0.17.1", path = "./crates/db_views_actor" } lemmy_db_views_moderator = { version = "=0.17.1", path = "./crates/db_views_moderator" } +lemmy_db_migrations = { version = "=0.17.1", path = "./crates/db_migrations" } activitypub_federation = { version = "0.4.0", default-features = false, features = ["actix-web"] } diesel = "2.1.0" diesel_migrations = "2.1.0" diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index 730f6b3b8..027326d8b 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -68,7 +68,7 @@ impl PerformCrud for EditComment { let comment_id = data.comment_id; let form = CommentUpdateForm::builder() - .content(content_slurs_removed.map(|s| s.into_owned())) + .content(content_slurs_removed.map(std::borrow::Cow::into_owned)) .language_id(data.language_id) .updated(Some(Some(naive_now()))) .build(); diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 34ecef4fa..42dbafff1 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -218,7 +218,7 @@ impl Object for ApubPost { PostInsertForm { name, url: url.map(Into::into), - body: body_slurs_removed.map(|s| s.into_owned()), + body: body_slurs_removed.map(std::borrow::Cow::into_owned), creator_id: creator.id, community_id: community.id, removed: None, diff --git a/crates/db_migrations/Cargo.toml b/crates/db_migrations/Cargo.toml new file mode 100644 index 000000000..4e9cdcc74 --- /dev/null +++ b/crates/db_migrations/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "lemmy_db_migrations" +version.workspace = true +edition.workspace = true +description.workspace = true +license.workspace = true +homepage.workspace = true +documentation.workspace = true +repository.workspace = true + +[lib] +name = "lemmy_db_migrations" +path = "src/lib.rs" +doctest = false + +[dependencies] +diesel_migrations = { workspace = true } diff --git a/crates/db_migrations/src/lib.rs b/crates/db_migrations/src/lib.rs new file mode 100644 index 000000000..6d060381c --- /dev/null +++ b/crates/db_migrations/src/lib.rs @@ -0,0 +1,9 @@ +#![feature(trace_macros)] +#[macro_use] +extern crate diesel_migrations; + +use diesel_migrations::EmbeddedMigrations; + +trace_macros!(true); +pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); +trace_macros!(false); diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index aa26382c0..8642efd90 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -16,7 +16,7 @@ doctest = false [features] 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", "ts-rs"] + "diesel-async", "deadpool", "ts-rs", "lemmy_db_migrations"] [dependencies] chrono = { workspace = true } @@ -28,6 +28,7 @@ strum_macros = { workspace = true } serde_json = { workspace = true, optional = true } activitypub_federation = { workspace = true, optional = true } lemmy_utils = { workspace = true, optional = true } +lemmy_db_migrations = { 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 } diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 479972066..e8f55755e 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -13,7 +13,6 @@ extern crate diesel_derive_enum; // this is used in tests #[cfg(feature = "full")] -#[macro_use] extern crate diesel_migrations; #[cfg(feature = "full")] diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index bba1d810b..9288a2c63 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -24,7 +24,7 @@ use diesel_async::{ AsyncDieselConnectionManager, }, }; -use diesel_migrations::EmbeddedMigrations; +use lemmy_db_migrations::MIGRATIONS; use lemmy_utils::{error::LemmyError, settings::structs::Settings}; use once_cell::sync::Lazy; use regex::Regex; @@ -153,8 +153,6 @@ async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result