From 47a4c35d8f754838506e4971babd8c3a78cb3e53 Mon Sep 17 00:00:00 2001 From: Dull Bananas Date: Mon, 20 May 2024 19:35:50 +0000 Subject: [PATCH] Revert "attempt 2" This reverts commit a909d2d6438d0b53382f762cf916ee92286a9965. --- .../db_schema/src/schema_setup/diff_check.rs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/db_schema/src/schema_setup/diff_check.rs b/crates/db_schema/src/schema_setup/diff_check.rs index 842fa3ebb..4e8c63faa 100644 --- a/crates/db_schema/src/schema_setup/diff_check.rs +++ b/crates/db_schema/src/schema_setup/diff_check.rs @@ -16,7 +16,7 @@ enum DumpAction { pub struct DiffChecker { snapshot_conn: PgConnection, handles: Vec>, - snapshot_sender: Option>, + snapshot_sender: Option>, error: Receiver>, // todo rename to channels //dump_receivers: Arc>>>, @@ -43,14 +43,13 @@ impl DiffChecker { let rx2 = rx.clone(); let error_t = error_t.clone(); 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 output = Command::new("pg_dump") .args(["--schema-only", &snapshot_arg]) .env("DATABASE_URL", SETTINGS.get_database_url()) .output() .expect("failed to start pg_dump process"); - std::mem::drop(conn); if !output.status.success() { panic!("{}", String::from_utf8(output.stderr).expect("")); @@ -78,8 +77,7 @@ impl DiffChecker { fn check_err(&mut self) { if let Ok(e) = self.error.try_recv() { - //std::panic::resume_unwind(e); - panic!(); + std::panic::resume_unwind(e); } } @@ -91,15 +89,10 @@ impl DiffChecker { self.check_err(); } - fn get_snapshot(&mut self) -> (String, PgConnection) { - let db_url = SETTINGS.get_database_url(); - let mut conn = PgConnection::establish(&db_url).expect("conn2"); - conn.batch_execute("BEGIN;").expect("begin"); - //conn.batch_execute("SELECT * FROM __diesel_schema_migrations;").expect("b"); - let snapshot = diesel::select(pg_export_snapshot()) - .get_result::(&mut conn) - .expect("pg_export_snapshot failed"); - (snapshot,conn) + fn get_snapshot(&mut self) -> String { + diesel::select(pg_export_snapshot()) + .get_result::(&mut self.snapshot_conn) + .expect("pg_export_snapshot failed") } pub fn get_dump(&mut self) -> Receiver {