You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds flag to publish to allow clearing on migration conflict. (#3601)
# Description of Changes
This PR modifies the `--delete-data` flag on `spacetime publish` and
adds the `--delete-data` flag on `spacetime dev`.
In particular instead of `--delete-data` 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 `--delete-data` 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 `--delete-data` is the equivalent of
`--delete-data=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 `--delete-data --yes`.
# Testing
- [ ] I have not yet tested manually.
---------
Signed-off-by: Tyler Cloutier <[email protected]>
Co-authored-by: Zeke Foppa <[email protected]>
Co-authored-by: Zeke Foppa <[email protected]>
Co-authored-by: John Detter <[email protected]>
Copy file name to clipboardExpand all lines: crates/bindings/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -662,7 +662,7 @@ The following changes are forbidden without a manual migration:
662
662
- ❌ **Changing whether a table is used for [scheduling](#scheduled-reducers).** <!-- TODO: update this if we ever actually implement it... -->
663
663
- ❌ **Adding `#[unique]`or`#[primary_key]` constraints.** This could result in existing tables being in an invalid state.
664
664
665
-
Currently, manual migration support is limited. The `spacetime publish --clear-database <DATABASE_IDENTITY>` command can be used to **COMPLETELY DELETE**and reinitialize your database, but naturally it should be used with EXTREME CAUTION.
665
+
Currently, manual migration support is limited. The `spacetime publish --delete-data <DATABASE_IDENTITY>` command can be used to **COMPLETELY DELETE**and reinitialize your database, but naturally it should be used with EXTREME CAUTION.
Copy file name to clipboardExpand all lines: crates/cli/src/common_args.rs
+25-1Lines changed: 25 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,12 @@
1
-
use clap::Arg;
2
1
use clap::ArgAction::SetTrue;
2
+
use clap::{value_parser,Arg,ValueEnum};
3
+
4
+
#[derive(Copy,Clone,Debug,ValueEnum,PartialEq)]
5
+
pubenumClearMode{
6
+
Always,// parses as "always"
7
+
OnConflict,// parses as "on-conflict"
8
+
Never,// parses as "never"
9
+
}
3
10
4
11
pubfnserver() -> Arg{
5
12
Arg::new("server")
@@ -37,3 +44,20 @@ pub fn confirmed() -> Arg {
37
44
.action(SetTrue)
38
45
.help("Instruct the server to deliver only updates of confirmed transactions")
39
46
}
47
+
48
+
pubfnclear_database() -> Arg{
49
+
Arg::new("clear-database")
50
+
.long("delete-data")
51
+
.alias("clear-database")
52
+
.short('c')
53
+
.num_args(0..=1)
54
+
.value_parser(value_parser!(ClearMode))
55
+
// Because we have a default value for this flag, invocations can be ambiguous between
56
+
//passing a value to this flag, vs using the default value and passing an anonymous arg
57
+
// to the rest of the command. Adding `require_equals` resolves this ambiguity.
58
+
.require_equals(true)
59
+
.default_missing_value("always")
60
+
.help(
61
+
"When publishing to an existing database identity, first DESTROY all data associated with the module. With 'on-conflict': only when breaking schema changes occur."
.about("Create and update a SpacetimeDB database")
19
20
.arg(
20
-
Arg::new("clear_database")
21
-
.long("delete-data")
22
-
.short('c')
23
-
.action(SetTrue)
21
+
common_args::clear_database()
24
22
.requires("name|identity")
25
-
.help("When publishing to an existing database identity, first DESTROY all data associated with the module"),
26
23
)
27
24
.arg(
28
25
Arg::new("build_options")
@@ -71,7 +68,7 @@ pub fn cli() -> clap::Command {
71
68
Arg::new("break_clients")
72
69
.long("break-clients")
73
70
.action(SetTrue)
74
-
.help("Allow breaking changes when publishing to an existing database identity. This will break existing clients.")
71
+
.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 file name to clipboardExpand all lines: docs/docs/06-Server Module Languages/04-csharp-reference.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1079,7 +1079,7 @@ The following changes are forbidden without a manual migration:
1079
1079
- ❌ **Changing whether a table is used for [scheduling](#scheduled-reducers).**<!-- TODO: update this if we ever actually implement it... -->
1080
1080
- ❌ **Adding `[Unique]` or `[PrimaryKey]` constraints.** This could result in existing tables being in an invalid state.
1081
1081
1082
-
Currently, manual migration support is limited. The `spacetime publish --clear-database <DATABASE_IDENTITY>` command can be used to **COMPLETELY DELETE** and reinitialize your database, but naturally it should be used with EXTREME CAUTION.
1082
+
Currently, manual migration support is limited. The `spacetime publish --delete-data <DATABASE_IDENTITY>` command can be used to **COMPLETELY DELETE** and reinitialize your database, but naturally it should be used with EXTREME CAUTION.
0 commit comments