pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.66k stars 249 forks source link

gracefully handle `cargo pgrx new $EXISTING_DIR_WITH_FILES` #1645

Open jyn514 opened 7 months ago

jyn514 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

workingjubilee commented 7 months ago

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

workingjubilee commented 7 months ago

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

jyn514 commented 7 months ago

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

workingjubilee commented 7 months ago

Wait, keeps new files? Hm.

workingjubilee commented 6 months ago

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.

jyn514 commented 6 months ago

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.

workingjubilee commented 6 months ago

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

workingjubilee commented 6 months ago

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