fix: dumps and imports that quietly did the wrong thing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::{Result, anyhow, bail};
|
||||
use anyhow::{Result, bail};
|
||||
|
||||
use super::shape::Kind;
|
||||
use crate::cmd::{Cmd, PgIsReady, PgRestore, Ps, Psql};
|
||||
@@ -10,6 +10,8 @@ use crate::project::Project;
|
||||
|
||||
const READY_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
const POLL_INTERVAL: Duration = Duration::from_secs(1);
|
||||
// stands in for an id a dry run has no running container to look up
|
||||
const PLANNED_CONTAINER: &str = "<db container>";
|
||||
|
||||
pub(super) struct Database {
|
||||
pub(super) service: String,
|
||||
@@ -22,13 +24,24 @@ impl Database {
|
||||
pub(super) fn resolve(ctx: &Ctx) -> Result<Self> {
|
||||
let compose = Project::resolve(ctx)?;
|
||||
let service = compose.postgres()?;
|
||||
let (user, name) = compose.postgres_credentials(&service);
|
||||
let (user, name) = compose.postgres_credentials(&service)?;
|
||||
|
||||
let container = Ps::id_of(&service).capture(ctx)?.trim().to_string();
|
||||
let listed = Ps::id_of(&service).capture(ctx)?;
|
||||
let mut ids = listed.lines().map(str::trim).filter(|id| !id.is_empty());
|
||||
|
||||
if container.is_empty() {
|
||||
return Err(anyhow!("service {service} has no running container"));
|
||||
}
|
||||
let container = match (ids.next(), ids.next()) {
|
||||
(Some(id), None) => id.to_string(),
|
||||
// one id per line: a scaled service has several, and the whole
|
||||
// listing would go to docker exec as though it were a single id
|
||||
(Some(_), Some(_)) => bail!(
|
||||
"service {service} has more than one container running; \
|
||||
scale it to one first"
|
||||
),
|
||||
// a dry run only prints a plan, and it is worth printing with the
|
||||
// project down, which is when it is most likely to be asked for
|
||||
(None, _) if ctx.dry_run => PLANNED_CONTAINER.to_string(),
|
||||
(None, _) => bail!("service {service} has no running container"),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
service,
|
||||
|
||||
Reference in New Issue
Block a user