Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/cli-migrate-module-cfg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

The migration module is gated by platform, so the CLI builds where the copy cannot run (#1121)
2 changes: 2 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ jobs:
persist-credentials: false
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1.17.0
- name: Format, which covers the file Linux cannot reach
run: cargo fmt --all --check
- name: CLI builds on Windows
run: cargo build -p nostream-cli --no-default-features
- name: CLI refuses the migration on Windows
Expand Down
10 changes: 0 additions & 10 deletions crates/nostream-cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ pub fn run(options: MigrateOptions, out: &mut dyn Write) -> Result<CommandOutput
})
}

#[cfg(not(unix))]
pub fn run(_options: MigrateOptions, out: &mut dyn Write) -> Result<CommandOutput, CliError> {
writeln!(out, "migrate pg-to-lmdb is unsupported on this platform")
.map_err(|e| CliError::Migrate(e.to_string()))?;
Ok(CommandOutput {
lines: Vec::new(),
exit_code: 1,
})
}

/// The copy over an injected source, target and writer, which is how the whole run is tested
/// without a process and without a database.
///
Expand Down
38 changes: 38 additions & 0 deletions crates/nostream-cli/src/commands/migrate_unsupported.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! `migrate pg-to-lmdb` where the copy cannot run.
//!
//! The copy reads and writes Unix file modes, refuses a target by its owner's uid and reads the
//! caller's from `/proc/self/status`, so the whole command lives in `migrate.rs` behind
//! `cfg(unix)`. The command still has to exist everywhere — a `main.rs` that cannot name it would
//! need its own `cfg` arm — so this module supplies the same `MigrateOptions` and a `run` that
//! refuses with the reason, which is what an operator on another platform needs to read.

use std::io::Write;
use std::path::PathBuf;

use crate::config::CommandOutput;
use crate::error::CliError;

/// The options one run carries. Kept in step with `migrate::MigrateOptions`, which is the arm
/// that uses them.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MigrateOptions {
/// The store root: the environment is `<target>/lmdb`, the manifest `<target>/migration-manifest.json`.
pub target: PathBuf,
/// Rows per batch, which is also the page size verify reads with.
pub batch_size: usize,
/// Verify the target against its manifest and copy nothing.
pub verify: bool,
}

/// `migrate pg-to-lmdb`: refused, naming the platform as the reason and answering exit code 1.
///
/// `migrate_cli_unsupported.rs` pins the line and the code, and the `windows-latest` job in
/// `checks.yml` runs it there.
pub fn run(_options: MigrateOptions, out: &mut dyn Write) -> Result<CommandOutput, CliError> {
writeln!(out, "migrate pg-to-lmdb is unsupported on this platform")
.map_err(|e| CliError::Migrate(e.to_string()))?;
Ok(CommandOutput {
lines: Vec::new(),
exit_code: 1,
})
}
6 changes: 6 additions & 0 deletions crates/nostream-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub mod export;
pub mod import;
pub mod info;
pub mod invite;
/// The copy needs Unix file modes, so the whole command is Unix-only and the other platform
/// gets a refusal with the same option type, which is what keeps `main.rs` free of a `cfg` arm.
#[cfg(unix)]
pub mod migrate;
#[cfg(not(unix))]
#[path = "migrate_unsupported.rs"]
pub mod migrate;
pub mod seed;
pub mod setup;
Expand Down
Loading