Skip to content

Conversation

@cloutiertyler
Copy link
Contributor

@cloutiertyler cloutiertyler commented Nov 7, 2025

Description of Changes

This PR modifies the --clear-database flag on spacetime publish and adds the --clear-database flag on spacetime dev.

In particular instead of --clear-database being a boolean, it is now a an enum:

  • always -> corresponds to the old value of true
  • never -> corresponds to the old value of false
  • on-conflict -> clears the database, but only if publishing would have required a manual migration

This flag does NOT change any behavior about prompting users to confirm if they want to delete the data. Users will still be prompted to confirm UNLESS they pass the separate --yes flag.

spacetime dev gets the same --clear-database flag. The default value of never is equivalent to the existing behavior. spacetime dev continues to publish with --yes just as before. This behavior is unchanged.

API and ABI breaking changes

Adds the flags specified above. This is NOT a breaking change to the CLI. Passing --clear-database is the equivalent of --clear-database=always.

This IS technically a breaking change to the pre_publish route. As far as I'm aware this is only used by our CLI however.

IMPORTANT SIDE NOTE: I would argue that --break-clients should really be renamed to --yes-break-clients because it actually behaves like the --yes force flag, but only for a subset of the user prompts. I have not made this change because it would be a breaking change, but if the reviewers agree, I will make this change.

Expected complexity level and risk

2, Very small change, but if we get it wrong users could accidentally lose data. I would ask reviewers to think about ways that users might accidentally pass --clear-database --yes.

Testing

  • I have not yet tested manually.

.short('c')
.num_args(0..=1)
.value_parser(value_parser!(ClearMode))
.require_equals(true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious about the UX choice behind require_equals for this arg but not others

.long("break-clients")
.action(SetTrue)
.help("Allow breaking changes when publishing to an existing database identity. This will break existing clients.")
.help("Allow breaking changes when publishing to an existing database identity. This will force publish even if it will break existing clients, but will NOT force publish if it would cause deletion of any data in the database. See --yes and --delete-data for details.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: are we sure we want to encourage them to look at --yes?

let mut builder = client.put(format!("{database_host}/v1/database/{domain}"));

if !clear_database {
if !(matches!(clear_database, ClearMode::Always)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I don't know that matches! is more readable than == for simple enum values 🤷

if matches!(clear_database, ClearMode::Never) {
println!("{}", manual.reason);
println!("Aborting publish due to required manual migration.");
anyhow::bail!("Publishing aborted by user");
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a correct bail message? Sure the user is ultimately responsible, but isn't it really just that they didn't choose to pass --clear-data? that feels like the user not doing something.

println!("{}", manual.reason);
println!("Aborting publish due to required manual migration.");
anyhow::bail!("Publishing aborted by user");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: should we maybe assert that clear_database isn't ClearMode::Always, or something similar? I feel like it takes me an extra pass or two reading this code to remember that the caller has chosen not to call this in that case.

Copy link
Collaborator

@bfops bfops left a comment

Choose a reason for hiding this comment

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

my code-owned changes LGTM, but left several small comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants