mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
Move embedded migrations to separate crate
This commit is contained in:
parent
dbfbc8660d
commit
44b1049970
9 changed files with 41 additions and 7 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -2637,6 +2637,13 @@ dependencies = [
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lemmy_db_migrations"
|
||||||
|
version = "0.17.1"
|
||||||
|
dependencies = [
|
||||||
|
"diesel_migrations",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lemmy_db_schema"
|
name = "lemmy_db_schema"
|
||||||
version = "0.17.1"
|
version = "0.17.1"
|
||||||
|
@ -2652,6 +2659,7 @@ dependencies = [
|
||||||
"diesel-derive-newtype",
|
"diesel-derive-newtype",
|
||||||
"diesel_ltree",
|
"diesel_ltree",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
|
"lemmy_db_migrations",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
|
@ -45,6 +45,7 @@ members = [
|
||||||
"crates/db_views",
|
"crates/db_views",
|
||||||
"crates/db_views_actor",
|
"crates/db_views_actor",
|
||||||
"crates/db_views_actor",
|
"crates/db_views_actor",
|
||||||
|
"crates/db_migrations",
|
||||||
"crates/routes"
|
"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 = { version = "=0.17.1", path = "./crates/db_views" }
|
||||||
lemmy_db_views_actor = { version = "=0.17.1", path = "./crates/db_views_actor" }
|
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_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"] }
|
activitypub_federation = { version = "0.4.0", default-features = false, features = ["actix-web"] }
|
||||||
diesel = "2.1.0"
|
diesel = "2.1.0"
|
||||||
diesel_migrations = "2.1.0"
|
diesel_migrations = "2.1.0"
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl PerformCrud for EditComment {
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let form = CommentUpdateForm::builder()
|
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)
|
.language_id(data.language_id)
|
||||||
.updated(Some(Some(naive_now())))
|
.updated(Some(Some(naive_now())))
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -218,7 +218,7 @@ impl Object for ApubPost {
|
||||||
PostInsertForm {
|
PostInsertForm {
|
||||||
name,
|
name,
|
||||||
url: url.map(Into::into),
|
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,
|
creator_id: creator.id,
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
|
|
17
crates/db_migrations/Cargo.toml
Normal file
17
crates/db_migrations/Cargo.toml
Normal file
|
@ -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 }
|
9
crates/db_migrations/src/lib.rs
Normal file
9
crates/db_migrations/src/lib.rs
Normal file
|
@ -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);
|
|
@ -16,7 +16,7 @@ doctest = false
|
||||||
[features]
|
[features]
|
||||||
full = ["diesel", "diesel-derive-newtype", "diesel-derive-enum", "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", "ts-rs"]
|
"diesel-async", "deadpool", "ts-rs", "lemmy_db_migrations"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
@ -28,6 +28,7 @@ strum_macros = { workspace = true }
|
||||||
serde_json = { workspace = true, optional = true }
|
serde_json = { workspace = true, optional = true }
|
||||||
activitypub_federation = { workspace = true, optional = true }
|
activitypub_federation = { workspace = true, optional = true }
|
||||||
lemmy_utils = { workspace = true, optional = true }
|
lemmy_utils = { workspace = true, optional = true }
|
||||||
|
lemmy_db_migrations = { 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 }
|
||||||
|
|
|
@ -13,7 +13,6 @@ extern crate diesel_derive_enum;
|
||||||
|
|
||||||
// this is used in tests
|
// this is used in tests
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
#[macro_use]
|
|
||||||
extern crate diesel_migrations;
|
extern crate diesel_migrations;
|
||||||
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
|
|
@ -24,7 +24,7 @@ use diesel_async::{
|
||||||
AsyncDieselConnectionManager,
|
AsyncDieselConnectionManager,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use diesel_migrations::EmbeddedMigrations;
|
use lemmy_db_migrations::MIGRATIONS;
|
||||||
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
@ -153,8 +153,6 @@ async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result<DbPoo
|
||||||
Ok(pool)
|
Ok(pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
|
||||||
|
|
||||||
pub fn run_migrations(db_url: &str) {
|
pub fn run_migrations(db_url: &str) {
|
||||||
// Needs to be a sync connection
|
// Needs to be a sync connection
|
||||||
let mut conn =
|
let mut conn =
|
||||||
|
|
Loading…
Reference in a new issue