Skip to content

Commit de620a6

Browse files
sdairsclaude
andcommitted
scope project data directories by version
Each ClickHouse version now stores its data in `.clickhouse/{version}/` instead of a shared `.clickhouse/` directory, preventing compatibility issues when switching between versions with `chv use`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dae6284 commit de620a6

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chv"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2024"
55

66
[dependencies]

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,23 @@ chv remove 25.12.5.44
4848
chv init
4949
```
5050

51-
This creates a `.clickhouse/` directory in the current folder to contain all ClickHouse data, logs, and temporary files. A `.gitignore` is included so it won't be committed.
51+
This creates a `.clickhouse/` directory in the current folder with a `.gitignore` so it won't be committed.
5252

5353
`chv run server` automatically runs `init` if needed, so you can skip this step.
5454

55+
Data is scoped by version — each ClickHouse version gets its own subdirectory under `.clickhouse/`, so switching versions with `chv use` won't cause compatibility issues:
56+
57+
```
58+
.clickhouse/
59+
├── .gitignore
60+
├── 25.12.5.44/
61+
│ ├── data/
62+
│ └── ...
63+
└── 26.1.2.11/
64+
├── data/
65+
└── ...
66+
```
67+
5568
### Running ClickHouse
5669

5770
```bash

src/init.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ pub fn init() -> Result<()> {
2626
Ok(())
2727
}
2828

29-
pub fn ensure_initialized() -> Result<()> {
29+
pub fn version_data_dir(version: &str) -> PathBuf {
30+
local_dir().join(version)
31+
}
32+
33+
pub fn ensure_initialized(version: &str) -> Result<()> {
3034
if !is_initialized() {
3135
init()?;
3236
}
37+
let vdir = version_data_dir(version);
38+
std::fs::create_dir_all(&vdir)?;
3339
Ok(())
3440
}
3541

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ fn run_clickhouse(args: RunArgs) -> Result<()> {
166166
cmd.arg("server");
167167
cmd.args(&args);
168168
if !has_config {
169-
init::ensure_initialized()?;
170-
cmd.current_dir(init::local_dir());
169+
init::ensure_initialized(&version)?;
170+
cmd.current_dir(init::version_data_dir(&version));
171171
cmd.args(init::server_flags());
172172
}
173173
let err = cmd.exec();

0 commit comments

Comments
 (0)