MCPcopy Create free account
hub / github.com/chatmail/core / run

Function run

src/sql/migrations.rs:782–2452  ·  view source on GitHub ↗
(context: &Context, sql: &Sql)

Source from the content-addressed store, hash-verified

780
781#[expect(clippy::arithmetic_side_effects)]
782pub async fn run(context: &Context, sql: &Sql) -> Result<bool> {
783 let mut exists_before_update = false;
784 let mut dbversion_before_update = DBVERSION;
785
786 if !sql
787 .table_exists("config")
788 .await
789 .context("failed to check if config table exists")?
790 {
791 sql.transaction(move |transaction| {
792 transaction.execute_batch(TABLES)?;
793
794 // set raw config inside the transaction
795 transaction.execute(
796 "INSERT INTO config (keyname, value) VALUES (?, ?);",
797 (VERSION_CFG, format!("{dbversion_before_update}")),
798 )?;
799 Ok(())
800 })
801 .await
802 .context("Creating tables failed")?;
803
804 let mut lock = context.sql.config_cache.write().await;
805 lock.insert(
806 VERSION_CFG.to_string(),
807 Some(format!("{dbversion_before_update}")),
808 );
809 drop(lock);
810 } else {
811 exists_before_update = true;
812 dbversion_before_update = sql
813 .get_raw_config_int(VERSION_CFG)
814 .await?
815 .unwrap_or_default();
816 }
817
818 let dbversion = dbversion_before_update;
819 let mut recode_avatar = false;
820
821 if dbversion < 1 {
822 sql.execute_migration(
823 r#"
824CREATE TABLE leftgrps ( id INTEGER PRIMARY KEY, grpid TEXT DEFAULT '');
825CREATE INDEX leftgrps_index1 ON leftgrps (grpid);"#,
826 1,
827 )
828 .await?;
829 }
830 if dbversion < 2 {
831 sql.execute_migration(
832 "ALTER TABLE contacts ADD COLUMN authname TEXT DEFAULT '';",
833 2,
834 )
835 .await?;
836 }
837 if dbversion < 7 {
838 sql.execute_migration(
839 "CREATE TABLE keypairs (\

Callers 3

test_migration_flagsFunction · 0.70
newMethod · 0.50
run_migrationsMethod · 0.50

Calls 15

get_provider_infoFunction · 0.85
inc_and_checkFunction · 0.85
migrate_key_contactsFunction · 0.85
timeFunction · 0.85
table_existsMethod · 0.80
transactionMethod · 0.80
executeMethod · 0.80
insertMethod · 0.80
get_raw_config_intMethod · 0.80
execute_migrationMethod · 0.80
set_raw_config_intMethod · 0.80
set_db_versionMethod · 0.80

Tested by 1

test_migration_flagsFunction · 0.56