migriation run command

This commit is contained in:
Dull Bananas 2024-05-11 20:45:27 +00:00
parent 542f81d4f1
commit d0d8139ff0
4 changed files with 44 additions and 15 deletions

View file

@ -132,17 +132,6 @@ steps:
- diff config/defaults.hjson config/defaults_current.hjson - diff config/defaults.hjson config/defaults_current.hjson
when: *slow_check_paths when: *slow_check_paths
check_diesel_schema:
image: willsquire/diesel-cli
environment:
CARGO_HOME: .cargo_home
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
when: *slow_check_paths
check_db_perf_tool: check_db_perf_tool:
image: *rust_image image: *rust_image
environment: environment:
@ -173,6 +162,18 @@ steps:
- mv target/debug/lemmy_server target/lemmy_server - mv target/debug/lemmy_server target/lemmy_server
when: *slow_check_paths when: *slow_check_paths
check_diesel_schema:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
commands:
- target/lemmy_server migration run
- diesel print-schema --config-file=diesel.toml > tmp.schema
- diff tmp.schema crates/db_schema/src/schema.rs
when: *slow_check_paths
cargo_test: cargo_test:
image: *rust_image image: *rust_image
environment: environment:

View file

@ -44,7 +44,7 @@ pub mod traits;
pub mod utils; pub mod utils;
#[cfg(feature = "full")] #[cfg(feature = "full")]
mod schema_setup; pub mod schema_setup;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString}; use strum_macros::{Display, EnumString};

View file

@ -9,8 +9,8 @@ cd $CWD/../
source scripts/start_dev_db.sh source scripts/start_dev_db.sh
diesel migration run cargo run --package lemmy_server -- migration run
pg_dump --no-owner --no-privileges --no-table-access-method --schema-only --no-sync -f schema.sqldump pg_dump --no-owner --no-privileges --no-table-access-method --schema-only --exclude-schema=r --no-sync -f schema.sqldump
pg_ctl stop pg_ctl stop
rm -rf $PGDATA rm -rf $PGDATA

View file

@ -23,7 +23,7 @@ use actix_web::{
HttpServer, HttpServer,
}; };
use actix_web_prom::PrometheusMetricsBuilder; use actix_web_prom::PrometheusMetricsBuilder;
use clap::Parser; use clap::{Parser, Subcommand};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
lemmy_db_views::structs::SiteView, lemmy_db_views::structs::SiteView,
@ -70,6 +70,7 @@ use url::Url;
about = "A link aggregator for the fediverse", about = "A link aggregator for the fediverse",
long_about = "A link aggregator for the fediverse.\n\nThis is the Lemmy backend API server. This will connect to a PostgreSQL database, run any pending migrations and start accepting API requests." long_about = "A link aggregator for the fediverse.\n\nThis is the Lemmy backend API server. This will connect to a PostgreSQL database, run any pending migrations and start accepting API requests."
)] )]
#[command(args_conflicts_with_subcommands = true)]
pub struct CmdArgs { pub struct CmdArgs {
/// Don't run scheduled tasks. /// Don't run scheduled tasks.
/// ///
@ -103,6 +104,23 @@ pub struct CmdArgs {
/// If set, make sure to set --federate-process-index differently for each. /// If set, make sure to set --federate-process-index differently for each.
#[arg(long, default_value_t = 1)] #[arg(long, default_value_t = 1)]
federate_process_count: i32, federate_process_count: i32,
#[command(subcommand)]
subcommand: Option<CmdSubcommand>,
}
#[derive(Subcommand, Debug)]
enum CmdSubcommand {
/// Do something with migrations, then exit.
Migration {
#[command(subcommand)]
subcommand: MigrationSubcommand,
},
}
#[derive(Subcommand, Debug)]
enum MigrationSubcommand {
/// Run all pending migrations.
Run,
} }
/// Placing the main function in lib.rs allows other crates to import it and embed Lemmy /// Placing the main function in lib.rs allows other crates to import it and embed Lemmy
@ -110,6 +128,16 @@ pub async fn start_lemmy_server(args: CmdArgs) -> LemmyResult<()> {
// Print version number to log // Print version number to log
println!("Lemmy v{VERSION}"); println!("Lemmy v{VERSION}");
if let Some(CmdSubcommand::Migration { subcommand }) = args.subcommand {
match subcommand {
MigrationSubcommand::Run => {}
}
lemmy_db_schema::schema_setup::run(&SETTINGS.get_database_url())?;
return Ok(());
}
// return error 503 while running db migrations and startup tasks // return error 503 while running db migrations and startup tasks
let mut startup_server_handle = None; let mut startup_server_handle = None;
if !args.disable_http_server { if !args.disable_http_server {