mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-13 22:22:10 +00:00
parent
a909d2d643
commit
47a4c35d8f
|
@ -16,7 +16,7 @@ enum DumpAction {
|
||||||
pub struct DiffChecker {
|
pub struct DiffChecker {
|
||||||
snapshot_conn: PgConnection,
|
snapshot_conn: PgConnection,
|
||||||
handles: Vec<thread::JoinHandle<()>>,
|
handles: Vec<thread::JoinHandle<()>>,
|
||||||
snapshot_sender: Option<Sender<((String,PgConnection), DumpAction)>>,
|
snapshot_sender: Option<Sender<(String, DumpAction)>>,
|
||||||
error: Receiver<Box<dyn Any + Send + 'static>>,
|
error: Receiver<Box<dyn Any + Send + 'static>>,
|
||||||
// todo rename to channels
|
// todo rename to channels
|
||||||
//dump_receivers: Arc<Mutex<HashMap<String, Receiver<String>>>>,
|
//dump_receivers: Arc<Mutex<HashMap<String, Receiver<String>>>>,
|
||||||
|
@ -43,14 +43,13 @@ impl DiffChecker {
|
||||||
let rx2 = rx.clone();
|
let rx2 = rx.clone();
|
||||||
let error_t = error_t.clone();
|
let error_t = error_t.clone();
|
||||||
handles.push(thread::spawn(move || if let Err(e) = std::panic::catch_unwind(move || {
|
handles.push(thread::spawn(move || if let Err(e) = std::panic::catch_unwind(move || {
|
||||||
while let Ok(((snapshot,conn), action)) = rx2.recv() {
|
while let Ok((snapshot, action)) = rx2.recv() {
|
||||||
let snapshot_arg = format!("--snapshot={snapshot}");
|
let snapshot_arg = format!("--snapshot={snapshot}");
|
||||||
let output = Command::new("pg_dump")
|
let output = Command::new("pg_dump")
|
||||||
.args(["--schema-only", &snapshot_arg])
|
.args(["--schema-only", &snapshot_arg])
|
||||||
.env("DATABASE_URL", SETTINGS.get_database_url())
|
.env("DATABASE_URL", SETTINGS.get_database_url())
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to start pg_dump process");
|
.expect("failed to start pg_dump process");
|
||||||
std::mem::drop(conn);
|
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
panic!("{}", String::from_utf8(output.stderr).expect(""));
|
panic!("{}", String::from_utf8(output.stderr).expect(""));
|
||||||
|
@ -78,8 +77,7 @@ impl DiffChecker {
|
||||||
|
|
||||||
fn check_err(&mut self) {
|
fn check_err(&mut self) {
|
||||||
if let Ok(e) = self.error.try_recv() {
|
if let Ok(e) = self.error.try_recv() {
|
||||||
//std::panic::resume_unwind(e);
|
std::panic::resume_unwind(e);
|
||||||
panic!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,15 +89,10 @@ impl DiffChecker {
|
||||||
self.check_err();
|
self.check_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_snapshot(&mut self) -> (String, PgConnection) {
|
fn get_snapshot(&mut self) -> String {
|
||||||
let db_url = SETTINGS.get_database_url();
|
diesel::select(pg_export_snapshot())
|
||||||
let mut conn = PgConnection::establish(&db_url).expect("conn2");
|
.get_result::<String>(&mut self.snapshot_conn)
|
||||||
conn.batch_execute("BEGIN;").expect("begin");
|
.expect("pg_export_snapshot failed")
|
||||||
//conn.batch_execute("SELECT * FROM __diesel_schema_migrations;").expect("b");
|
|
||||||
let snapshot = diesel::select(pg_export_snapshot())
|
|
||||||
.get_result::<String>(&mut conn)
|
|
||||||
.expect("pg_export_snapshot failed");
|
|
||||||
(snapshot,conn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_dump(&mut self) -> Receiver<String> {
|
pub fn get_dump(&mut self) -> Receiver<String> {
|
||||||
|
|
Loading…
Reference in a new issue