Skip to content

Commit 9df3529

Browse files
committed
fix: apply config migrations, even on first run
1 parent 83091fa commit 9df3529

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/desktop/src/app_settings.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,15 @@ impl AppSettings {
155155
config_dir: &Path,
156156
migration_file: &Path,
157157
) -> anyhow::Result<(AppSettingsValue, bool)> {
158+
// Apply any pending config migrations before reading the settings
159+
// file.
160+
apply_config_migrations(config_dir, migration_file)?;
161+
158162
let settings_path = config_dir.join("settings.json");
159163
let is_found = settings_path.exists();
160164

161-
// Apply any pending config migrations before reading the settings
162-
// file. If the file does not exist, initialize a default.
163-
if is_found {
164-
apply_config_migrations(config_dir, migration_file)?;
165-
} else {
165+
// If the file does not exist, initialize a default.
166+
if !is_found {
166167
Self::create_default(config_dir)?;
167168
}
168169

packages/desktop/src/config_migration.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ impl ConfigMigration {
3333
}
3434
}
3535

36-
/// Migrates config files to the latest version.
36+
/// Migrates existing config files to the latest version.
37+
///
38+
/// Any migrations that have already been applied will be skipped. If
39+
/// no migrations are needed, the function will no-op.
3740
pub fn apply_config_migrations(
3841
config_dir: &Path,
3942
migration_file: &Path,
@@ -74,6 +77,11 @@ pub fn apply_config_migrations(
7477
fn migrate_startup_config(config_dir: &Path) -> anyhow::Result<()> {
7578
let settings_path = config_dir.join("settings.json");
7679

80+
// Skip if the settings file does not exist.
81+
if !settings_path.exists() {
82+
return Ok(());
83+
}
84+
7785
let settings_json =
7886
read_and_parse_json::<serde_json::Value>(&settings_path)
7987
.context("Failed to parse settings.json")?;

0 commit comments

Comments
 (0)