gracefully handle `cargo pgrx new $EXISTING_DIR_WITH_FILES`
i just did the following things:
-
cargo pgrx newwith pgrx 0.11.3. -
cargo pgrx runwith pgrx 0.11.3. that gave an error that i installed pgrx with 1.76, but the current toolchain is 1.79-nightly. i remembered @workingjubilee saying that restriction was removed ondevelop, so i -
cargo install --git https://github.com/pgcentralfoundation/pgrx --locked cargo-pgrx -
cargo pgrx runwith the new binary. that gives the following error:
Error:
0: The installed `cargo-pgrx` v0.12.0-alpha.1 is not compatible with the `pgrx = 0.11.3`, `pgrx-macros = 0.11.3`, `pgrx-sql-entity-graph = 0.11.3`, `pgrx-tests = 0.11.3` dependencies in `./Cargo.toml`. `cargo-pgrx` and pgrx dependency versions must be identical.
help: cargo install --version `pgrx = 0.11.3`, `pgrx-macros = 0.11.3`, `pgrx-sql-entity-graph = 0.11.3`, `pgrx-tests = 0.11.3` --locked
Location:
cargo-pgrx/src/metadata.rs:68
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
0: cargo_pgrx::metadata::validate
at cargo-pgrx/src/metadata.rs:30
1: cargo_pgrx::command::run::execute
at cargo-pgrx/src/command/run.rs:54
now the error makes some amount of sense to me, but the help: suggestion does not look right. those are dependency versions, not the version of cargo-pgrx itself. maybe https://github.com/pgcentralfoundation/pgrx/blob/82fe8b1ae32cb474a9e1819493725b1efb695d4b/cargo-pgrx/src/metadata.rs#L72 should be using cargo_pgrx_version instead of mismatches?
alternatively it could suggest to update the dependencies in Cargo.toml, which is what i'm about to do now, but that's hard to make copy/pasteable unless they already have cargo-edit installed.
huh. apparently cargo pgrx new does not error if there's already a directory there. so that's another (albeit destructive) option.
:sweat_smile: uhh maybe we should fix that...
@jyn514 does it nuke the entire directory or does it just rewrite the relevant files?
nukes the entire directory, including src/lib.rs. it does seem to keep new files, but any file it knows about is completely overwritten.
Wait, keeps new files? Hm.
Interpreting this as a feature request for cargo pgrx update, which is now https://github.com/pgcentralfoundation/pgrx/issues/1647
Retaining this issue because cargo pgrx new $EXISTING_DIR should not clobber your lib.rs! Not without using a --force flag or similar, anyways.
both of those make sense to me, but do note there's a third issue, which is that the error message has mismatches swapped with cargo_pgrx_version, so it suggests a cargo install command with invalid syntax.
oh right, giving a coherent suggestion in that case was a much more trivial change, lemme fix.
https://github.com/pgcentralfoundation/pgrx/pull/1659 for that part.