{"record":{"id":"ffb764c7cd6f1f84","repo":"clockworklabs/SpacetimeDB","slug":"env-only-cannot-reset-a-database","errorCode":null,"errorMessage":"--env-only cannot reset a database","messagePattern":"--env-only cannot reset a database","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/publish.rs","lineNumber":595,"sourceCode":"async fn execute_publish_configs<'a>(\n    config: &mut Config,\n    publish_configs: Vec<CommandConfig<'a>>,\n    using_config: bool,\n    config_dir: Option<&std::path::Path>,\n    clear_database: ClearMode,\n    yes: YesFlags,\n    environment_options: &EnvironmentOptions,\n) -> Result<(), anyhow::Error> {\n    // Execute publish for each config\n    for command_config in publish_configs {\n        // Get values using command_config.get_one() which merges CLI + config\n        let server_opt = command_config.get_one::<String>(\"server\")?;\n        let server = server_opt.as_deref();\n        let name_or_identity_opt = command_config.get_one::<String>(\"database\")?;\n        let name_or_identity = name_or_identity_opt.as_deref();\n        let anon_identity = command_config.get_one::<bool>(\"anon_identity\")?.unwrap_or(false);\n        if environment_options.only {\n            ensure!(clear_database == ClearMode::Never, \"--env-only cannot reset a database\");\n            environment::publish_only(\n                config,\n                server,\n                name_or_identity.context(\"--env-only requires an existing database name or identity\")?,\n                anon_identity,\n                yes,\n                command_config.get_config_value(\"env\"),\n                environment_options,\n            )\n            .await?;\n            continue;\n        }\n        let wasm_file = command_config.get_one::<PathBuf>(\"wasm_file\")?;\n        let js_file = command_config.get_one::<PathBuf>(\"js_file\")?;\n        let resolved_module_path = command_config.get_resolved_path(\"module_path\", config_dir)?;\n        let path_to_project = if wasm_file.is_some() || js_file.is_some() {\n            resolved_module_path\n        } else {","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/publish.rs#L577-L613","documentation":"`spacetime publish --env-only` publishes only updated environment variables to an existing database and must never clear/reset it. The CLI enforces this by rejecting any combination where `--env-only` is combined with a reset mode (`--clear-database` / `ClearMode` other than `Never`). The two options are semantically contradictory, so publish fails fast.","triggerScenarios":"Running `spacetime publish --env-only ...` together with `--clear-database yes|no` (any `ClearMode != Never`), or with defaults elsewhere wiring a non-Never clear mode while `environment_options.only` is set.","commonSituations":"Scripts or CI pipelines that always append `--clear-database` to publish invocations, then get an `--env-only` flag added for env-only redeploys; copy-pasting both flags from different runbooks.","solutions":["Remove `--clear-database` (or set it to `never`) from the command when using `--env-only`.","Split the operation: run a normal publish with the clear flag when a reset is needed, and a separate `--env-only` publish when only environment variables change.","Fix wrapper scripts/CI templates so the clear flag is only passed on full publishes.","Use `--env-only` as-is for pure env updates — it already requires only an existing database name/identity."],"exampleFix":"# before\nspacetime publish --env-only --clear-database yes my-db\n# after (env-only update, no reset)\nspacetime publish --env-only my-db","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# guard in publish wrapper\nif echo \"$ARGS\" | grep -q -- '--env-only' && echo \"$ARGS\" | grep -q -- '--clear-database'; then\n  echo \"--env-only cannot be combined with --clear-database\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never template publish commands with both --env-only and --clear-database","Keep env-only redeploy and reset workflows as separate CI jobs","Default wrapper scripts to ClearMode::Never when --env-only is set"],"tags":["rust","cli","conflicting-options","publish"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}