pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

gracefully handle `cargo pgrx new $EXISTING_DIR_WITH_FILES`

Open jyn514 opened this issue 2 years ago • 10 comments

i just did the following things:

  1. cargo pgrx new with pgrx 0.11.3.
  2. cargo pgrx run with 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 on develop, so i
  3. cargo install --git https://github.com/pgcentralfoundation/pgrx --locked cargo-pgrx
  4. cargo pgrx run with 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?

jyn514 avatar Apr 09 '24 16:04 jyn514

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.

jyn514 avatar Apr 09 '24 16:04 jyn514

huh. apparently cargo pgrx new does not error if there's already a directory there. so that's another (albeit destructive) option.

jyn514 avatar Apr 09 '24 16:04 jyn514

:sweat_smile: uhh maybe we should fix that...

workingjubilee avatar Apr 09 '24 16:04 workingjubilee

@jyn514 does it nuke the entire directory or does it just rewrite the relevant files?

workingjubilee avatar Apr 09 '24 16:04 workingjubilee

nukes the entire directory, including src/lib.rs. it does seem to keep new files, but any file it knows about is completely overwritten.

jyn514 avatar Apr 09 '24 16:04 jyn514

Wait, keeps new files? Hm.

workingjubilee avatar Apr 09 '24 16:04 workingjubilee

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.

workingjubilee avatar Apr 16 '24 20:04 workingjubilee

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.

jyn514 avatar Apr 16 '24 20:04 jyn514

oh right, giving a coherent suggestion in that case was a much more trivial change, lemme fix.

workingjubilee avatar Apr 16 '24 21:04 workingjubilee

https://github.com/pgcentralfoundation/pgrx/pull/1659 for that part.

workingjubilee avatar Apr 16 '24 21:04 workingjubilee