Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacetime publish: Add confirmation for -c #1038

Merged
merged 14 commits into from
May 14, 2024
Merged

Conversation

bfops
Copy link
Collaborator

@bfops bfops commented Apr 4, 2024

Description of Changes

Making this change in response to a request from the BitCraft team.

spacetime publish -c now asks for confirmation, unless a new --force is passed as well.

API and ABI breaking changes

This will break any automation using spacetime publish -c.

I think that's an acceptable level of break? @jdetter ?

Expected complexity level and risk

How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.

2

This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.

Testing

Basic publish still works fine, with no input:

  $ echo | spacetime publish -s local test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.15s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  Publishing module...
  Updated database with domain: test-module, address: 0d78dc56e0223a61218791b864064ab5


Publishing with `-c` (now) fails without confirmation:

  $ echo | spacetime publish -s local -c test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.16s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  This will DESTROY the current test-module module, and ALL corresponding data.
  Are you sure you want to proceed? (y/N) [deleting test-module] Aborting


...and it succeeds when given confirmation:

  $ echo 'y' | spacetime publish -s local -c test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.14s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  This will DESTROY the current test-module module, and ALL corresponding data.
  Are you sure you want to proceed? (y/N) [deleting test-module] Publishing module...
  Updated database with domain: test-module, address: 0d78dc56e0223a61218791b864064ab5


A "yes-like" answer is not good enough!

  $ echo 'yessir' | spacetime publish -s local -c test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.15s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  This will DESTROY the current test-module module, and ALL corresponding data.
  Are you sure you want to proceed? (y/N) [deleting test-module] Aborting

The clearly-named long flag works:

  $ echo | spacetime publish -s local --destroy-previous test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.15s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  This will DESTROY the current test-module module, and ALL corresponding data.
  Are you sure you want to proceed? (y/N) [deleting test-module] Aborting
  $ echo | spacetime publish -s local --destroy-previous --force test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.15s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  Skipping confirmation due to --force.
  Publishing module...
  Updated database with domain: test-module, address: 0d78dc56e0223a61218791b864064ab5

The deprecated long flag works like before:

  $ echo | spacetime publish -s local --clear-database test-module
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  checking crate with spacetimedb's clippy configuration
      Checking spacetime-module v0.1.0 (/tmp/cramtests-v9blcwxj/publish-test.t/module-test)
      Finished release [optimized] target(s) in 0.14s
      Finished release [optimized] target(s) in 0.06s
  Optimising module with wasm-opt...
  Could not find wasm-opt to optimise the module.
  For best performance install wasm-opt from https://github.com/WebAssembly/binaryen/releases.
  Continuing with unoptimised module.
  Uploading to local => http://127.0.0.1:3000
  Skipping confirmation due to --force.
  Publishing module...
  Updated database with domain: test-module, address: 0d78dc56e0223a61218791b864064ab5

@bfops bfops added bitcraft issue Active issue for the BitCraft team release-any To be landed in any release window labels Apr 4, 2024
@bfops bfops requested a review from jdetter April 4, 2024 20:32
@bfops bfops marked this pull request as ready for review April 4, 2024 21:39
Copy link
Collaborator

@jdetter jdetter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not try to preserve the API here, just break it and we'll merge this as part of 0.9 next week.

.requires("name_or_address")
.conflicts_with("destroy_previous")
.action(SetTrue)
.help("DEPRECATED - Use --destroy-previous"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we add this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is a backwards compatible thing - let's just mark this as an API break and merge it for 0.9.

@@ -110,7 +125,8 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
let name_or_address = args.get_one::<String>("name|address");
let path_to_project = args.get_one::<PathBuf>("project_path").unwrap();
let host_type = args.get_one::<String>("host_type").unwrap();
let clear_database = args.get_flag("clear_database");
let clear_database = args.get_flag("destroy_previous") || args.get_flag("deprecated_clear_database");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just break the API here and not change this

@@ -163,6 +175,31 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
database_host
);

if clear_database {
// This is to preserve backwards-compatibility with the old --clear-database.
if force || args.get_flag("deprecated_clear_database") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove || args.get_flag("deprecated_clear_database")

// TODO(jdetter): Rename this to --delete-tables (clear doesn't really implies the tables are being dropped)
Arg::new("clear_database")
.long("clear-database")
Arg::new("destroy_previous")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep this as clear-database - I realized that this was us trying to not break backwards compatibility but let's just break the API in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually renamed this because of the TODO above - I'm fine to revert, but I do agree with it in principle!

@bfops bfops requested a review from jdetter April 8, 2024 18:09
@cloutiertyler
Copy link
Contributor

Is there a reason we're renaming the long version, and not the short version? I don't think the inconsistency is worth it.

What is wrong with --clear-database?

@jdetter
Copy link
Collaborator

jdetter commented May 13, 2024

Is there a reason we're renaming the long version, and not the short version? I don't think the inconsistency is worth it.

What is wrong with --clear-database?

The feedback that you gave at the time was that --clear-database implies that you're just dropping all of the rows from the tables instead of deleting the tables completely and creating new ones.

Arg::new("clear_database")
.long("clear-database")
Arg::new("delete_tables")
.long("delete-tables")
.short('c')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping the -c flag here kinda seems like its legacy. I believe we can't use -d because we're using that for the debug flag. Maybe we just keep --clear-database and drop the TODO, what do you think @bfops @cloutiertyler ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tyler already responded on this PR - let's just change this back to --clear-database and this is good to merge, thanks Zeke 👍

@@ -163,6 +167,30 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
database_host
);

if delete_tables {
if force {
eprintln!("Skipping confirmation due to --force.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend just using println here instead of eprintln

}
query_params.push(("clear", "true"));
}

eprintln!("Publishing module...");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though its not part of this PR I would recommend changing this to println as well

Copy link
Collaborator

@jdetter jdetter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small request and then good to merge, thanks Zeke 👍

Arg::new("clear_database")
.long("clear-database")
Arg::new("delete_tables")
.long("delete-tables")
.short('c')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tyler already responded on this PR - let's just change this back to --clear-database and this is good to merge, thanks Zeke 👍

@bfops bfops requested a review from jdetter May 13, 2024 16:49
Copy link
Collaborator

@jdetter jdetter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Zeke 👍

@bfops bfops enabled auto-merge May 13, 2024 17:47
"--project-path", self.project_path,
*(["-c"] if clear else []),
Copy link
Collaborator Author

@bfops bfops May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • specifying -c without a domain is now a CLI error
  • added --force to avoid confirmation

@bfops bfops added this pull request to the merge queue May 14, 2024
Merged via the queue into master with commit 8ab55d2 May 14, 2024
7 checks passed
@bfops bfops deleted the bfops/confirm-publish-clear branch September 5, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bitcraft issue Active issue for the BitCraft team release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants