-
-
Notifications
You must be signed in to change notification settings - Fork 116
fix: Reset options that are not available for chatmail #7624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,7 +214,7 @@ impl Sql { | |
| // this should be done before updates that use high-level objects that | ||
| // rely themselves on the low-level structure. | ||
|
|
||
| let recode_avatar = migrations::run(context, self) | ||
| let (recode_avatar, update_email_configs) = migrations::run(context, self) | ||
| .await | ||
| .context("failed to run migrations")?; | ||
|
|
||
|
|
@@ -242,6 +242,22 @@ impl Sql { | |
| } | ||
| } | ||
|
|
||
| // Reset some options if IsChatmail is true, | ||
| // because there were reports from users who had these options set to something else, | ||
| // and then couldn't change them because they are hidden in the UI for chatmail profiles | ||
| if update_email_configs && context.get_config_bool(Config::IsChatmail).await? { | ||
| // The default for MvboxMove is actually "1", and it's usually set to "0" in `configure.rs`. | ||
| context | ||
| .set_config_internal(Config::MvboxMove, Some("0")) | ||
| .await?; | ||
| context | ||
| .set_config_internal(Config::OnlyFetchMvbox, None) | ||
| .await?; | ||
| context | ||
| .set_config_internal(Config::ShowEmails, None) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above, the problem with these high-level APIs is that we may want to get rid of |
||
| .await?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,7 @@ tokio::task_local! { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static STOP_MIGRATIONS_AT: i32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub async fn run(context: &Context, sql: &Sql) -> Result<bool> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub async fn run(context: &Context, sql: &Sql) -> Result<(bool, bool)> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not add more of these high-level migrations, I have just removed stale ones: They tend to do something different from what they did initially later because high level APIs change. We can run some raw SQL statements once that look for is_chatmail and reset some setting, if we want to do it again we can just copy-paste the migration.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be something like the below, then (it compiles, but I didn't test it yet). I'm not convinced that's better, because it looks quite error-prone (e.g., if the line And if&when we remove these settings in the future, we can just remove the migration. But if you insist, I can also change it. inc_and_check(&mut migration_version, 144)?;
if dbversion < migration_version {
sql.execute_migration_transaction(
|transaction| {
let is_chatmail = crate::config::bool_from_config(
transaction
.query_one(
"SELECT value FROM config WHERE key='is_chatmail'",
(),
|row| row.get::<_, String>(0),
)
.optional()?
.as_deref(),
);
if is_chatmail {
transaction.execute_batch(
"\
DELETE FROM config WHERE keyname='only_fetch_mvbox';
DELETE FROM config WHERE keyname='show_emails'
UPDATE config SET value='0' WHERE keyname='mvbox_move'",
)?;
}
Ok(())
},
migration_version,
)
.await?;
}
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think it is better, because it is self-contained and we will never have to change it again once it is written unless some very low level We do this in migration 139: Lines 1350 to 1388 in 6a293ae
As for |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut exists_before_update = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut dbversion_before_update = DBVERSION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -69,6 +69,7 @@ pub async fn run(context: &Context, sql: &Sql) -> Result<bool> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let dbversion = dbversion_before_update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut recode_avatar = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut update_email_configs = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if dbversion < 1 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sql.execute_migration( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1466,6 +1467,12 @@ ALTER TABLE contacts ADD COLUMN name_normalized TEXT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .await?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inc_and_check(&mut migration_version, 144)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if dbversion < migration_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_email_configs = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sql.set_db_version(migration_version).await?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the app crashes right after this line? Next time it starts, |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let new_version = sql | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .get_raw_config_int(VERSION_CFG) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .await? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1480,7 +1487,7 @@ ALTER TABLE contacts ADD COLUMN name_normalized TEXT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info!(context, "Database version: v{new_version}."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok(recode_avatar) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok((recode_avatar, update_email_configs)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn migrate_key_contacts( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also error-prone because it runs after all migrations that we might add in the future. If we in the future add a migration that simply removes
is_chatmailfromconfigtable as a cleanup, then this code will do nothing and have different effect depending on whether the user upgrades release-by-release or jumps across multiple releases.