2018-08-02 13:33:06 +00:00
package eu.faircode.email ;
2021-08-07 15:06:11 +00:00
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD ;
2021-09-04 18:16:05 +00:00
import android.app.ActivityManager ;
2018-08-02 13:33:06 +00:00
import android.content.Context ;
2018-12-23 18:20:08 +00:00
import android.content.SharedPreferences ;
2018-08-24 09:20:14 +00:00
import android.database.Cursor ;
2022-09-26 07:01:55 +00:00
import android.database.sqlite.SQLiteDatabase ;
2022-08-31 08:23:24 +00:00
import android.database.sqlite.SQLiteDatabaseCorruptException ;
2020-06-25 07:14:05 +00:00
import android.net.Uri ;
2020-07-12 08:17:50 +00:00
import android.os.Build ;
2018-08-06 16:22:01 +00:00
import android.text.TextUtils ;
2018-08-02 13:33:06 +00:00
2019-05-31 06:57:23 +00:00
import androidx.annotation.NonNull ;
2020-04-14 06:32:54 +00:00
import androidx.lifecycle.Observer ;
2019-04-17 18:21:44 +00:00
import androidx.preference.PreferenceManager ;
import androidx.room.Database ;
2020-01-18 19:05:24 +00:00
import androidx.room.DatabaseConfiguration ;
2019-05-31 06:57:23 +00:00
import androidx.room.InvalidationTracker ;
2019-04-17 18:21:44 +00:00
import androidx.room.Room ;
import androidx.room.RoomDatabase ;
import androidx.room.TypeConverter ;
import androidx.room.TypeConverters ;
import androidx.room.migration.Migration ;
import androidx.sqlite.db.SupportSQLiteDatabase ;
2018-08-07 16:25:57 +00:00
import org.json.JSONArray ;
import org.json.JSONException ;
import org.json.JSONObject ;
2019-03-14 09:12:19 +00:00
import java.io.File ;
2020-04-14 08:14:58 +00:00
import java.lang.reflect.Field ;
2018-08-07 16:25:57 +00:00
import java.util.ArrayList ;
2021-12-13 16:49:30 +00:00
import java.util.Arrays ;
import java.util.Collections ;
2021-02-25 13:28:58 +00:00
import java.util.Date ;
2022-01-09 12:57:07 +00:00
import java.util.HashMap ;
2018-08-07 16:25:57 +00:00
import java.util.List ;
2020-04-14 08:14:58 +00:00
import java.util.Map ;
2021-08-13 14:56:52 +00:00
import java.util.Objects ;
2019-05-31 06:57:23 +00:00
import java.util.Set ;
2021-07-29 16:59:05 +00:00
import java.util.UUID ;
2019-01-04 14:48:55 +00:00
import java.util.concurrent.ExecutorService ;
2018-08-07 16:25:57 +00:00
import javax.mail.Address ;
import javax.mail.internet.InternetAddress ;
2018-08-02 13:33:06 +00:00
/ *
2018-08-14 05:53:24 +00:00
This file is part of FairEmail .
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software : you can redistribute it and / or modify
2018-08-02 13:33:06 +00:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful ,
2018-08-02 13:33:06 +00:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2018-10-29 10:46:49 +00:00
along with FairEmail . If not , see < http : //www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
2022-01-01 08:46:36 +00:00
Copyright 2018 - 2022 by Marcel Bokhorst ( M66B )
2018-08-02 13:33:06 +00:00
* /
// https://developer.android.com/topic/libraries/architecture/room.html
@Database (
2022-09-28 05:31:34 +00:00
version = 245 ,
2018-08-02 13:33:06 +00:00
entities = {
EntityIdentity . class ,
EntityAccount . class ,
EntityFolder . class ,
EntityMessage . class ,
2018-08-03 12:07:51 +00:00
EntityAttachment . class ,
2018-08-27 07:06:03 +00:00
EntityOperation . class ,
2019-02-13 09:24:06 +00:00
EntityContact . class ,
2019-12-03 12:59:27 +00:00
EntityCertificate . class ,
2018-08-27 07:06:03 +00:00
EntityAnswer . class ,
2019-01-17 13:29:35 +00:00
EntityRule . class ,
2021-09-24 11:36:06 +00:00
EntitySearch . class ,
2019-05-22 05:51:50 +00:00
EntityLog . class
2019-06-07 08:14:44 +00:00
} ,
views = {
2020-01-22 18:53:17 +00:00
TupleAccountView . class ,
TupleIdentityView . class ,
2020-11-27 18:09:14 +00:00
TupleFolderView . class
2018-08-08 10:22:12 +00:00
}
2018-08-02 13:33:06 +00:00
)
@TypeConverters ( { DB . Converters . class } )
public abstract class DB extends RoomDatabase {
public abstract DaoAccount account ( ) ;
2019-05-31 06:57:23 +00:00
public abstract DaoIdentity identity ( ) ;
2018-08-02 13:33:06 +00:00
public abstract DaoFolder folder ( ) ;
public abstract DaoMessage message ( ) ;
2018-08-03 12:07:51 +00:00
public abstract DaoAttachment attachment ( ) ;
2018-08-02 13:33:06 +00:00
public abstract DaoOperation operation ( ) ;
2019-02-13 09:24:06 +00:00
public abstract DaoContact contact ( ) ;
2019-12-03 12:59:27 +00:00
public abstract DaoCertificate certificate ( ) ;
2018-08-27 07:06:03 +00:00
public abstract DaoAnswer answer ( ) ;
2019-01-17 13:29:35 +00:00
public abstract DaoRule rule ( ) ;
2021-09-24 11:36:06 +00:00
public abstract DaoSearch search ( ) ;
2018-09-03 19:11:16 +00:00
public abstract DaoLog log ( ) ;
2021-04-25 14:13:26 +00:00
private static int sPid ;
2021-08-13 14:56:52 +00:00
private static Context sContext ;
2018-08-02 13:33:06 +00:00
private static DB sInstance ;
2022-06-18 10:18:35 +00:00
static final String DB_NAME = " fairemail " ;
2021-09-11 15:48:48 +00:00
static final int DEFAULT_QUERY_THREADS = 4 ; // AndroidX default thread count: 4
2021-12-10 20:49:50 +00:00
static final int DEFAULT_CACHE_SIZE = 10 ; // percentage of memory class
2022-09-25 06:20:46 +00:00
private static final int DB_JOURNAL_SIZE_LIMIT = 1048576 ; // requery/sqlite-android default
2020-02-01 10:40:29 +00:00
private static final int DB_CHECKPOINT = 1000 ; // requery/sqlite-android default
2020-01-20 19:24:08 +00:00
2020-02-01 10:40:29 +00:00
private static final String [ ] DB_TABLES = new String [ ] {
2021-09-24 11:36:06 +00:00
" identity " , " account " , " folder " , " message " , " attachment " , " operation " , " contact " , " certificate " , " answer " , " rule " , " search " , " log " } ;
2020-01-22 15:18:21 +00:00
2021-12-13 16:49:30 +00:00
private static final List < String > DB_PRAGMAS = Collections . unmodifiableList ( Arrays . asList (
2021-12-01 07:24:36 +00:00
" synchronous " , " journal_mode " ,
" wal_checkpoint " , " wal_autocheckpoint " , " journal_size_limit " ,
" page_count " , " page_size " , " max_page_count " , " freelist_count " ,
" cache_size " , " cache_spill " ,
" soft_heap_limit " , " hard_heap_limit " , " mmap_size " ,
2022-09-24 11:00:18 +00:00
" foreign_keys " , " auto_vacuum " ,
" compile_options "
2021-12-13 16:49:30 +00:00
) ) ;
2021-12-01 07:24:36 +00:00
2020-01-20 19:24:08 +00:00
@Override
public void init ( @NonNull DatabaseConfiguration configuration ) {
2022-08-31 08:23:24 +00:00
File dbfile = configuration . context . getDatabasePath ( DB_NAME ) ;
SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( configuration . context ) ;
boolean sqlite_integrity_check = prefs . getBoolean ( " sqlite_integrity_check " , true ) ;
// https://www.sqlite.org/pragma.html#pragma_integrity_check
if ( sqlite_integrity_check & & dbfile . exists ( ) ) {
2022-09-24 05:59:57 +00:00
String check = ( Helper . isRedmiNote ( ) | | Helper . isOnePlus ( ) | | Helper . isOppo ( ) | | BuildConfig . DEBUG
2022-08-31 08:23:24 +00:00
? " integrity_check " : " quick_check " ) ;
try ( SQLiteDatabase db = SQLiteDatabase . openDatabase ( dbfile . getPath ( ) , null , SQLiteDatabase . OPEN_READWRITE ) ) {
Log . i ( " PRAGMA " + check ) ;
try ( Cursor cursor = db . rawQuery ( " PRAGMA " + check + " ; " , null ) ) {
while ( cursor . moveToNext ( ) ) {
String line = cursor . getString ( 0 ) ;
if ( " ok " . equals ( line ) )
Log . i ( " PRAGMA " + check + " = " + line ) ;
else
Log . e ( " PRAGMA " + check + " = " + line ) ;
2020-01-21 07:16:32 +00:00
}
2020-01-20 19:24:08 +00:00
}
2022-08-31 08:23:24 +00:00
} catch ( SQLiteDatabaseCorruptException ex ) {
Log . e ( ex ) ;
dbfile . delete ( ) ;
}
}
// https://www.sqlite.org/pragma.html#pragma_wal_autocheckpoint
if ( BuildConfig . DEBUG & & dbfile . exists ( ) ) {
try ( SQLiteDatabase db = SQLiteDatabase . openDatabase ( dbfile . getPath ( ) , null , SQLiteDatabase . OPEN_READWRITE ) ) {
Log . i ( " Set PRAGMA wal_autocheckpoint= " + DB_CHECKPOINT ) ;
try ( Cursor cursor = db . rawQuery ( " PRAGMA wal_autocheckpoint= " + DB_CHECKPOINT + " ; " , null ) ) {
cursor . moveToNext ( ) ; // required
}
2020-01-20 19:24:08 +00:00
}
}
super . init ( configuration ) ;
}
2018-08-02 13:33:06 +00:00
2020-04-14 06:32:54 +00:00
static void setupViewInvalidation ( Context context ) {
// This needs to be done on a foreground thread
DB db = DB . getInstance ( context ) ;
db . account ( ) . liveAccountView ( ) . observeForever ( new Observer < List < TupleAccountView > > ( ) {
private List < TupleAccountView > last = null ;
@Override
public void onChanged ( List < TupleAccountView > accounts ) {
if ( accounts = = null )
accounts = new ArrayList < > ( ) ;
boolean changed = false ;
if ( last = = null | | last . size ( ) ! = accounts . size ( ) )
changed = true ;
else
for ( int i = 0 ; i < accounts . size ( ) ; i + + )
if ( ! accounts . get ( i ) . equals ( last . get ( i ) ) ) {
changed = true ;
last = accounts ;
}
if ( changed ) {
Log . i ( " Invalidating account view " ) ;
last = accounts ;
2020-04-14 08:58:11 +00:00
db . getInvalidationTracker ( ) . notifyObserversByTableNames ( " message " ) ;
2020-04-14 06:32:54 +00:00
}
}
} ) ;
db . identity ( ) . liveIdentityView ( ) . observeForever ( new Observer < List < TupleIdentityView > > ( ) {
private List < TupleIdentityView > last = null ;
@Override
public void onChanged ( List < TupleIdentityView > identities ) {
if ( identities = = null )
identities = new ArrayList < > ( ) ;
boolean changed = false ;
if ( last = = null | | last . size ( ) ! = identities . size ( ) )
changed = true ;
else
for ( int i = 0 ; i < identities . size ( ) ; i + + )
if ( ! identities . get ( i ) . equals ( last . get ( i ) ) ) {
changed = true ;
last = identities ;
}
if ( changed ) {
Log . i ( " Invalidating identity view " ) ;
last = identities ;
2020-04-14 08:58:11 +00:00
db . getInvalidationTracker ( ) . notifyObserversByTableNames ( " message " ) ;
2020-04-14 06:32:54 +00:00
}
}
} ) ;
db . folder ( ) . liveFolderView ( ) . observeForever ( new Observer < List < TupleFolderView > > ( ) {
private List < TupleFolderView > last = null ;
@Override
public void onChanged ( List < TupleFolderView > folders ) {
if ( folders = = null )
folders = new ArrayList < > ( ) ;
boolean changed = false ;
if ( last = = null | | last . size ( ) ! = folders . size ( ) )
changed = true ;
else
for ( int i = 0 ; i < folders . size ( ) ; i + + )
if ( ! folders . get ( i ) . equals ( last . get ( i ) ) ) {
changed = true ;
last = folders ;
}
if ( changed ) {
Log . i ( " Invalidating folder view " ) ;
last = folders ;
2020-04-26 07:11:21 +00:00
db . getInvalidationTracker ( ) . notifyObserversByTableNames ( " account " , " message " ) ;
2020-04-14 06:32:54 +00:00
}
}
} ) ;
}
2021-02-27 14:31:58 +00:00
static void createEmergencyBackup ( Context context ) {
Log . i ( " Creating emergency backup " ) ;
try {
DB db = DB . getInstance ( context ) ;
JSONArray jaccounts = new JSONArray ( ) ;
List < EntityAccount > accounts = db . account ( ) . getAccounts ( ) ;
for ( EntityAccount account : accounts ) {
JSONObject jaccount = account . toJSON ( ) ;
JSONArray jfolders = new JSONArray ( ) ;
List < EntityFolder > folders = db . folder ( ) . getFolders ( account . id , false , true ) ;
for ( EntityFolder folder : folders )
jfolders . put ( folder . toJSON ( ) ) ;
jaccount . put ( " folders " , jfolders ) ;
JSONArray jidentities = new JSONArray ( ) ;
List < EntityIdentity > identities = db . identity ( ) . getIdentities ( account . id ) ;
for ( EntityIdentity identity : identities )
jidentities . put ( identity . toJSON ( ) ) ;
jaccount . put ( " identities " , jidentities ) ;
jaccounts . put ( jaccount ) ;
}
File emergency = new File ( context . getFilesDir ( ) , " emergency.json " ) ;
Helper . writeText ( emergency , jaccounts . toString ( 2 ) ) ;
} catch ( Throwable ex ) {
Log . e ( ex ) ;
}
}
2021-02-27 15:03:20 +00:00
private static void checkEmergencyBackup ( Context context ) {
2021-02-27 14:31:58 +00:00
try {
File dbfile = context . getDatabasePath ( DB_NAME ) ;
if ( dbfile . exists ( ) ) {
Log . i ( " Emergency restore /dbfile " ) ;
return ;
}
File emergency = new File ( context . getFilesDir ( ) , " emergency.json " ) ;
if ( ! emergency . exists ( ) ) {
Log . i ( " Emergency restore /json " ) ;
return ;
}
DB db = DB . getInstance ( context ) ;
if ( db . account ( ) . getAccounts ( ) . size ( ) > 0 ) {
Log . e ( " Emergency restore /accounts " ) ;
return ;
}
Log . e ( " Emergency restore " ) ;
String json = Helper . readText ( emergency ) ;
JSONArray jaccounts = new JSONArray ( json ) ;
for ( int a = 0 ; a < jaccounts . length ( ) ; a + + ) {
JSONObject jaccount = jaccounts . getJSONObject ( a ) ;
EntityAccount account = EntityAccount . fromJSON ( jaccount ) ;
2021-02-28 06:52:15 +00:00
account . created = new Date ( ) . getTime ( ) ;
2021-02-27 14:31:58 +00:00
account . id = db . account ( ) . insertAccount ( account ) ;
JSONArray jfolders = jaccount . getJSONArray ( " folders " ) ;
for ( int f = 0 ; f < jfolders . length ( ) ; f + + ) {
EntityFolder folder = EntityFolder . fromJSON ( jfolders . getJSONObject ( f ) ) ;
folder . account = account . id ;
db . folder ( ) . insertFolder ( folder ) ;
}
JSONArray jidentities = jaccount . getJSONArray ( " identities " ) ;
for ( int i = 0 ; i < jidentities . length ( ) ; i + + ) {
EntityIdentity identity = EntityIdentity . fromJSON ( jidentities . getJSONObject ( i ) ) ;
identity . account = account . id ;
db . identity ( ) . insertIdentity ( identity ) ;
}
}
} catch ( Throwable ex ) {
Log . e ( ex ) ;
}
}
2019-07-22 14:28:48 +00:00
public static synchronized DB getInstance ( Context context ) {
2021-08-13 14:56:52 +00:00
int apid = android . os . Process . myPid ( ) ;
2021-04-25 14:13:26 +00:00
Context acontext = context . getApplicationContext ( ) ;
if ( sInstance ! = null & &
2021-08-13 14:56:52 +00:00
( sPid ! = apid | | ! Objects . equals ( sContext , acontext ) ) )
2021-04-25 14:13:26 +00:00
try {
2021-08-13 14:56:52 +00:00
Log . e ( " Orphan database instance pid= " + apid + " / " + sPid ) ;
2021-04-25 14:13:26 +00:00
sInstance = null ;
} catch ( Throwable ex ) {
Log . e ( ex ) ;
}
2021-08-13 14:56:52 +00:00
sPid = apid ;
2021-04-25 14:13:26 +00:00
sContext = acontext ;
2018-08-24 12:31:51 +00:00
if ( sInstance = = null ) {
2021-04-25 14:13:26 +00:00
Log . i ( " Creating database instance pid= " + sPid ) ;
2019-07-22 14:28:48 +00:00
2021-04-25 14:13:26 +00:00
sInstance = migrate ( sContext , getBuilder ( sContext ) ) . build ( ) ;
2019-07-22 14:28:48 +00:00
2021-02-27 10:22:17 +00:00
sInstance . getQueryExecutor ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
2021-04-25 14:13:26 +00:00
checkEmergencyBackup ( sContext ) ;
2021-02-27 10:22:17 +00:00
}
} ) ;
2020-04-14 08:14:58 +00:00
try {
Log . i ( " Disabling view invalidation " ) ;
2020-04-14 08:58:11 +00:00
Field fmViewTables = InvalidationTracker . class . getDeclaredField ( " mViewTables " ) ;
2020-04-14 08:14:58 +00:00
fmViewTables . setAccessible ( true ) ;
Map < String , Set < String > > mViewTables = ( Map ) fmViewTables . get ( sInstance . getInvalidationTracker ( ) ) ;
mViewTables . get ( " account_view " ) . clear ( ) ;
mViewTables . get ( " identity_view " ) . clear ( ) ;
mViewTables . get ( " folder_view " ) . clear ( ) ;
Log . i ( " Disabled view invalidation " ) ;
} catch ( ReflectiveOperationException ex ) {
Log . e ( ex ) ;
}
2020-04-14 08:58:11 +00:00
sInstance . getInvalidationTracker ( ) . addObserver ( new InvalidationTracker . Observer ( DB_TABLES ) {
2019-05-31 06:57:23 +00:00
@Override
public void onInvalidated ( @NonNull Set < String > tables ) {
2020-01-23 07:46:31 +00:00
Log . d ( " ROOM invalidated= " + TextUtils . join ( " , " , tables ) ) ;
2019-05-31 06:57:23 +00:00
}
} ) ;
2018-08-24 12:31:51 +00:00
}
2018-08-02 13:33:06 +00:00
return sInstance ;
}
2019-07-17 10:21:17 +00:00
private static RoomDatabase . Builder < DB > getBuilder ( Context context ) {
2020-06-18 06:03:39 +00:00
SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
2021-09-11 15:48:48 +00:00
int threads = prefs . getInt ( " query_threads " , DEFAULT_QUERY_THREADS ) ;
2021-02-24 17:10:53 +00:00
boolean wal = prefs . getBoolean ( " wal " , true ) ;
Log . i ( " DB query threads= " + threads + " wal= " + wal ) ;
2021-02-27 20:29:20 +00:00
ExecutorService executorQuery = Helper . getBackgroundExecutor ( threads , " query " ) ;
ExecutorService executorTransaction = Helper . getBackgroundExecutor ( 0 , " transaction " ) ;
2020-06-18 06:03:39 +00:00
2019-01-06 16:31:53 +00:00
return Room
2019-04-16 18:19:50 +00:00
. databaseBuilder ( context , DB . class , DB_NAME )
2022-09-26 07:01:55 +00:00
//.openHelperFactory(new RequerySQLiteOpenHelperFactory())
2021-02-27 20:29:20 +00:00
. setQueryExecutor ( executorQuery )
. setTransactionExecutor ( executorTransaction )
2021-02-24 17:10:53 +00:00
. setJournalMode ( wal ? JournalMode . WRITE_AHEAD_LOGGING : JournalMode . TRUNCATE ) // using the latest sqlite
2019-07-24 12:49:55 +00:00
. addCallback ( new Callback ( ) {
@Override
public void onOpen ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
Map < String , String > crumb = new HashMap < > ( ) ;
crumb . put ( " version " , Integer . toString ( db . getVersion ( ) ) ) ;
crumb . put ( " WAL " , Boolean . toString ( db . isWriteAheadLoggingEnabled ( ) ) ) ;
Log . breadcrumb ( " Database " , crumb ) ;
2020-01-18 19:05:24 +00:00
2022-07-07 08:52:50 +00:00
// https://www.sqlite.org/pragma.html#pragma_auto_vacuum
// https://android.googlesource.com/platform/external/sqlite.git/+/6ab557bdc070f11db30ede0696888efd19800475%5E!/
2022-08-31 07:09:42 +00:00
boolean sqlite_auto_vacuum = prefs . getBoolean ( " sqlite_auto_vacuum " , false ) ;
2022-07-07 08:52:50 +00:00
String mode = ( sqlite_auto_vacuum ? " FULL " : " INCREMENTAL " ) ;
2022-09-25 06:20:46 +00:00
Log . i ( " Set PRAGMA auto_vacuum= " + mode ) ;
try ( Cursor cursor = db . query ( " PRAGMA auto_vacuum= " + mode + " ; " , null ) ) {
2022-07-07 08:52:50 +00:00
cursor . moveToNext ( ) ; // required
2022-07-04 15:23:34 +00:00
}
2022-08-31 07:09:42 +00:00
// https://sqlite.org/pragma.html#pragma_synchronous
boolean sqlite_sync_extra = prefs . getBoolean ( " sqlite_sync_extra " , true ) ;
String sync = ( sqlite_sync_extra ? " EXTRA " : " NORMAL " ) ;
2022-09-25 06:20:46 +00:00
Log . i ( " Set PRAGMA synchronous= " + sync ) ;
try ( Cursor cursor = db . query ( " PRAGMA synchronous= " + sync + " ; " , null ) ) {
cursor . moveToNext ( ) ; // required
}
Log . i ( " Set PRAGMA journal_size_limit= " + DB_JOURNAL_SIZE_LIMIT ) ;
try ( Cursor cursor = db . query ( " PRAGMA journal_size_limit= " + DB_JOURNAL_SIZE_LIMIT + " ; " , null ) ) {
2022-08-31 07:09:42 +00:00
cursor . moveToNext ( ) ; // required
}
2021-10-16 18:36:50 +00:00
// https://www.sqlite.org/pragma.html#pragma_cache_size
Integer cache_size = getCacheSizeKb ( context ) ;
if ( cache_size ! = null ) {
cache_size = - cache_size ; // kibibytes
Log . i ( " Set PRAGMA cache_size= " + cache_size ) ;
try ( Cursor cursor = db . query ( " PRAGMA cache_size= " + cache_size + " ; " , null ) ) {
cursor . moveToNext ( ) ; // required
}
}
// Prevent long running operations from getting an exclusive lock
// https://www.sqlite.org/pragma.html#pragma_cache_spill
Log . i ( " Set PRAGMA cache_spill=0 " ) ;
try ( Cursor cursor = db . query ( " PRAGMA cache_spill=0; " , null ) ) {
cursor . moveToNext ( ) ; // required
}
2021-02-23 14:01:59 +00:00
// https://www.sqlite.org/pragma.html
2021-12-01 07:24:36 +00:00
for ( String pragma : DB_PRAGMAS )
2022-09-24 11:00:18 +00:00
if ( ! " compile_options " . equals ( pragma ) | | BuildConfig . DEBUG )
try ( Cursor cursor = db . query ( " PRAGMA " + pragma + " ; " ) ) {
boolean has = false ;
while ( cursor . moveToNext ( ) ) {
has = true ;
Log . i ( " Get PRAGMA " + pragma + " = " + ( cursor . isNull ( 0 ) ? " <null> " : cursor . getString ( 0 ) ) ) ;
}
if ( ! has )
Log . i ( " Get PRAGMA " + pragma + " =<?> " ) ;
}
2021-02-23 14:01:59 +00:00
2020-12-14 12:33:26 +00:00
if ( BuildConfig . DEBUG & & false ) {
2020-07-12 08:17:50 +00:00
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
}
2022-03-05 14:43:53 +00:00
2022-03-06 08:49:31 +00:00
createTriggers ( db ) ;
2019-07-24 12:49:55 +00:00
}
} ) ;
2019-01-06 16:31:53 +00:00
}
2021-10-16 18:36:50 +00:00
static Integer getCacheSizeKb ( Context context ) {
try {
SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
int sqlite_cache = prefs . getInt ( " sqlite_cache " , DEFAULT_CACHE_SIZE ) ;
2022-04-13 20:27:33 +00:00
ActivityManager am = Helper . getSystemService ( context , ActivityManager . class ) ;
2021-10-16 18:36:50 +00:00
int class_mb = am . getMemoryClass ( ) ;
int cache_size = sqlite_cache * class_mb * 1024 / 100 ;
return ( cache_size > 2000 ? cache_size : null ) ;
} catch ( Throwable ex ) {
Log . e ( ex ) ;
return null ;
}
}
2020-01-22 08:02:59 +00:00
private static void createTriggers ( @NonNull SupportSQLiteDatabase db ) {
2022-04-06 06:39:18 +00:00
List < String > image = new ArrayList < > ( ) ;
for ( String img : ImageHelper . IMAGE_TYPES )
image . add ( " ' " + img + " ' " ) ;
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . O )
for ( String img : ImageHelper . IMAGE_TYPES8 )
2021-08-18 17:37:35 +00:00
image . add ( " ' " + img + " ' " ) ;
2022-04-06 06:39:18 +00:00
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . S )
for ( String img : ImageHelper . IMAGE_TYPES12 )
image . add ( " ' " + img + " ' " ) ;
String images = TextUtils . join ( " , " , image ) ;
db . execSQL ( " CREATE TRIGGER IF NOT EXISTS attachment_insert " +
" AFTER INSERT ON attachment " +
" BEGIN " +
" UPDATE message SET attachments = attachments + 1 " +
" WHERE message.id = NEW.message " +
" AND NEW.encryption IS NULL " +
" AND NOT ((NEW.disposition = 'inline' OR (NEW.related IS NOT 0 AND NEW.cid IS NOT NULL)) AND NEW.type IN ( " + images + " )); " +
" END " ) ;
db . execSQL ( " CREATE TRIGGER IF NOT EXISTS attachment_delete " +
" AFTER DELETE ON attachment " +
" BEGIN " +
" UPDATE message SET attachments = attachments - 1 " +
" WHERE message.id = OLD.message " +
" AND OLD.encryption IS NULL " +
" AND NOT ((OLD.disposition = 'inline' OR (OLD.related IS NOT 0 AND OLD.cid IS NOT NULL)) AND OLD.type IN ( " + images + " )); " +
" END " ) ;
2020-01-22 08:02:59 +00:00
}
2022-01-09 13:47:46 +00:00
private static void logMigration ( int startVersion , int endVersion ) {
Map < String , String > crumb = new HashMap < > ( ) ;
crumb . put ( " startVersion " , Integer . toString ( startVersion ) ) ;
crumb . put ( " endVersion " , Integer . toString ( endVersion ) ) ;
Log . breadcrumb ( " Migration " , crumb ) ;
}
2020-01-20 19:33:25 +00:00
private static RoomDatabase . Builder < DB > migrate ( final Context context , RoomDatabase . Builder < DB > builder ) {
2018-11-13 09:05:33 +00:00
// https://www.sqlite.org/lang_altertable.html
2018-08-02 13:33:06 +00:00
return builder
2018-08-23 09:48:27 +00:00
. addMigrations ( new Migration ( 1 , 2 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-14 09:49:59 +00:00
db . execSQL ( " ALTER TABLE `folder` RENAME COLUMN `after` TO `sync_days` " ) ;
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `keep_days` INTEGER NOT NULL DEFAULT 30 " ) ;
db . execSQL ( " UPDATE `folder` SET keep_days = sync_days " ) ;
2018-11-12 13:45:02 +00:00
}
} )
2018-11-14 13:51:50 +00:00
. addMigrations ( new Migration ( 2 , 3 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-14 13:51:50 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `signature` TEXT " ) ;
db . execSQL ( " UPDATE `identity` SET signature = " +
" (SELECT account.signature FROM account WHERE account.id = identity.account) " ) ;
}
} )
2018-11-16 12:48:45 +00:00
. addMigrations ( new Migration ( 3 , 4 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-16 12:48:45 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `forwarding` INTEGER " +
" REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL " ) ;
2018-12-06 10:59:57 +00:00
db . execSQL ( " CREATE INDEX `index_message_forwarding` ON `message` (`forwarding`) " ) ;
2018-11-16 12:48:45 +00:00
}
} )
2018-11-19 13:14:02 +00:00
. addMigrations ( new Migration ( 4 , 5 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-19 13:14:02 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `last_connected` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `last_attempt` INTEGER " ) ;
}
} )
2018-11-24 08:26:34 +00:00
. addMigrations ( new Migration ( 5 , 6 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-24 08:26:34 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `notify` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2018-11-24 18:14:28 +00:00
. addMigrations ( new Migration ( 6 , 7 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-24 18:14:28 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `answered` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_answered` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2018-11-25 12:34:08 +00:00
. addMigrations ( new Migration ( 7 , 8 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-25 12:34:08 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `keywords` TEXT " ) ;
}
} )
2018-11-26 08:12:44 +00:00
. addMigrations ( new Migration ( 8 , 9 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-26 08:12:44 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `keywords` TEXT " ) ;
}
} )
2018-11-26 15:57:00 +00:00
. addMigrations ( new Migration ( 9 , 10 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-11-26 15:57:00 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_browsed` INTEGER NOT NULL DEFAULT 0 " ) ;
2018-12-06 10:59:57 +00:00
db . execSQL ( " CREATE INDEX `index_message_ui_browsed` ON `message` (`ui_browsed`) " ) ;
2018-11-26 15:57:00 +00:00
}
} )
2018-12-01 14:13:57 +00:00
. addMigrations ( new Migration ( 10 , 11 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-01 14:13:57 +00:00
db . execSQL ( " ALTER TABLE `operation` ADD COLUMN `error` TEXT " ) ;
}
} )
2018-12-02 13:19:54 +00:00
. addMigrations ( new Migration ( 11 , 12 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-02 13:19:54 +00:00
db . execSQL ( " DROP INDEX `index_operation_folder` " ) ;
db . execSQL ( " DROP INDEX `index_operation_message` " ) ;
db . execSQL ( " DROP TABLE `operation` " ) ;
db . execSQL ( " CREATE TABLE `operation` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , `folder` INTEGER NOT NULL " +
" , `message` INTEGER " +
" , `name` TEXT NOT NULL " +
" , `args` TEXT NOT NULL " +
" , `created` INTEGER NOT NULL " +
" , `error` TEXT " +
" , FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE " +
" , FOREIGN KEY(`message`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE) " ) ;
db . execSQL ( " CREATE INDEX `index_operation_folder` ON `operation` (`folder`) " ) ;
db . execSQL ( " CREATE INDEX `index_operation_message` ON `operation` (`message`) " ) ;
}
} )
2018-12-03 08:33:43 +00:00
. addMigrations ( new Migration ( 12 , 13 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " CREATE INDEX `index_message_ui_flagged` ON `message` (`ui_flagged`) " ) ;
2018-12-03 08:33:43 +00:00
}
} )
2018-12-03 09:39:44 +00:00
. addMigrations ( new Migration ( 13 , 14 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-03 09:39:44 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `level` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2018-12-03 12:41:36 +00:00
. addMigrations ( new Migration ( 14 , 15 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-03 12:41:36 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `sync_state` TEXT " ) ;
}
} )
2018-12-05 09:25:35 +00:00
. addMigrations ( new Migration ( 15 , 16 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-05 09:25:35 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `poll` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2018-12-06 10:59:57 +00:00
. addMigrations ( new Migration ( 16 , 17 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-06 10:59:57 +00:00
db . execSQL ( " DELETE FROM `message` WHERE ui_found " ) ;
db . execSQL ( " DROP INDEX `index_message_folder_uid_ui_found` " ) ;
db . execSQL ( " DROP INDEX `index_message_msgid_folder_ui_found` " ) ;
db . execSQL ( " CREATE UNIQUE INDEX `index_message_folder_uid` ON `message` (`folder`, `uid`) " ) ;
db . execSQL ( " CREATE UNIQUE INDEX `index_message_msgid_folder` ON `message` (`msgid`, `folder`) " ) ;
}
} )
2018-12-06 12:43:00 +00:00
. addMigrations ( new Migration ( 17 , 18 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-06 12:43:00 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `tbd` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `tbd` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `tbd` INTEGER " ) ;
}
} )
2018-12-07 15:48:52 +00:00
. addMigrations ( new Migration ( 18 , 19 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-07 15:48:52 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `delivery_receipt` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `read_receipt` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2018-12-09 08:38:23 +00:00
. addMigrations ( new Migration ( 19 , 20 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-09 08:38:23 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `notify` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " UPDATE `folder` SET notify = unified " ) ;
}
} )
2018-12-10 15:45:52 +00:00
. addMigrations ( new Migration ( 20 , 21 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-10 15:45:52 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `display` TEXT " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `bcc` TEXT " ) ;
}
} )
2018-12-11 11:18:26 +00:00
. addMigrations ( new Migration ( 21 , 22 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-11 11:18:26 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `initialize` INTEGER NOT NULL DEFAULT 1 " ) ;
db . execSQL ( " UPDATE `folder` SET sync_days = 1 " ) ;
}
} )
2018-12-14 11:31:25 +00:00
. addMigrations ( new Migration ( 22 , 23 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-14 11:31:25 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `download` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} )
2018-12-22 11:40:47 +00:00
. addMigrations ( new Migration ( 23 , 24 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-22 11:40:47 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `tbc` INTEGER " ) ;
}
} )
2018-12-22 17:39:16 +00:00
. addMigrations ( new Migration ( 24 , 25 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-22 17:39:16 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `prefix` TEXT " ) ;
}
} )
2018-12-23 18:20:08 +00:00
. addMigrations ( new Migration ( 25 , 26 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-23 18:20:08 +00:00
SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
int browse = ( prefs . getBoolean ( " browse " , true ) ? 1 : 0 ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `browse` INTEGER NOT NULL DEFAULT " + browse ) ;
}
} )
2018-12-27 11:32:20 +00:00
. addMigrations ( new Migration ( 26 , 27 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-27 11:32:20 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `sender` TEXT " ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " CREATE INDEX `index_message_sender` ON `message` (`sender`) " ) ;
2018-12-28 08:04:56 +00:00
}
} )
. addMigrations ( new Migration ( 27 , 28 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2018-12-27 11:32:20 +00:00
2019-02-22 15:59:23 +00:00
try ( Cursor cursor = db . query ( " SELECT `id`, `from` FROM message " ) ) {
2018-12-28 08:04:56 +00:00
while ( cursor . moveToNext ( ) )
try {
long id = cursor . getLong ( 0 ) ;
String json = cursor . getString ( 1 ) ;
Address [ ] from = Converters . decodeAddresses ( json ) ;
String sender = MessageHelper . getSortKey ( from ) ;
2018-12-27 11:32:20 +00:00
db . execSQL (
" UPDATE message SET sender = ? WHERE id = ? " ,
new Object [ ] { sender , id } ) ;
2018-12-28 08:04:56 +00:00
} catch ( Throwable ex ) {
Log . e ( ex ) ;
}
2018-12-27 11:32:20 +00:00
}
}
} )
2019-01-01 18:49:21 +00:00
. addMigrations ( new Migration ( 28 , 29 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-01 18:49:21 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `last_sync` INTEGER " ) ;
}
} )
2019-01-05 14:09:47 +00:00
. addMigrations ( new Migration ( 29 , 30 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-05 14:09:47 +00:00
db . execSQL ( " ALTER TABLE `attachment` ADD COLUMN `encryption` INTEGER " ) ;
db . execSQL ( " UPDATE attachment SET encryption = " + EntityAttachment . PGP_MESSAGE + " where name = 'encrypted.asc' " ) ;
}
} )
2019-01-06 11:00:08 +00:00
. addMigrations ( new Migration ( 30 , 31 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-06 11:00:08 +00:00
db . execSQL ( " ALTER TABLE `attachment` ADD COLUMN `disposition` TEXT " ) ;
}
} )
2019-01-07 15:05:24 +00:00
. addMigrations ( new Migration ( 31 , 32 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-07 15:05:24 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_snoozed` INTEGER " ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " CREATE INDEX `index_message_ui_snoozed` ON `message` (`ui_snoozed`) " ) ;
2019-01-07 15:05:24 +00:00
}
} )
2019-01-10 18:24:20 +00:00
. addMigrations ( new Migration ( 32 , 33 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-10 18:24:20 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `realm` TEXT " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `realm` TEXT " ) ;
}
} )
2019-01-16 17:37:45 +00:00
. addMigrations ( new Migration ( 33 , 34 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-16 17:37:45 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `raw` INTEGER " ) ;
}
} )
2019-01-16 18:27:03 +00:00
. addMigrations ( new Migration ( 34 , 35 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-16 18:27:03 +00:00
db . execSQL ( " ALTER TABLE `attachment` ADD COLUMN `error` TEXT " ) ;
}
} )
2019-01-17 10:49:18 +00:00
. addMigrations ( new Migration ( 35 , 36 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-17 10:49:18 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `warning` TEXT " ) ;
}
} )
2019-01-17 13:29:35 +00:00
. addMigrations ( new Migration ( 36 , 37 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-17 13:29:35 +00:00
db . execSQL ( " CREATE TABLE `rule` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT, " +
" `folder` INTEGER NOT NULL, " +
" `name` TEXT NOT NULL, " +
" `order` INTEGER NOT NULL, " +
2019-01-17 21:25:22 +00:00
" `enabled` INTEGER NOT NULL, " +
2019-01-17 13:29:35 +00:00
" `condition` TEXT NOT NULL, " +
" `action` TEXT NOT NULL, " +
" FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE) " ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " CREATE INDEX `index_rule_folder` ON `rule` (`folder`) " ) ;
db . execSQL ( " CREATE INDEX `index_rule_order` ON `rule` (`order`) " ) ;
2019-01-17 13:29:35 +00:00
}
} )
2019-01-18 10:58:55 +00:00
. addMigrations ( new Migration ( 37 , 38 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-18 10:58:55 +00:00
db . execSQL ( " ALTER TABLE `rule` ADD COLUMN `stop` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-01-20 15:22:21 +00:00
. addMigrations ( new Migration ( 38 , 39 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-20 15:22:21 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `swipe_left` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `swipe_right` INTEGER " ) ;
}
} )
2019-01-25 18:13:00 +00:00
. addMigrations ( new Migration ( 39 , 40 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-25 18:13:00 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `last_connected` INTEGER " ) ;
}
} )
2019-01-29 20:15:24 +00:00
. addMigrations ( new Migration ( 40 , 41 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-01-29 20:15:24 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `flags` TEXT " ) ;
}
} )
2019-02-09 12:54:58 +00:00
. addMigrations ( new Migration ( 41 , 42 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-09 12:54:58 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `plain_only` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-02-09 21:03:53 +00:00
. addMigrations ( new Migration ( 42 , 43 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-09 21:03:53 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `pop` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-02-13 09:24:06 +00:00
. addMigrations ( new Migration ( 43 , 44 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-13 09:24:06 +00:00
db . execSQL ( " CREATE TABLE IF NOT EXISTS `contact` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , `type` INTEGER NOT NULL " +
" , `email` TEXT NOT NULL " +
" , `name` TEXT) " ) ;
db . execSQL ( " CREATE UNIQUE INDEX `index_contact_email_type` ON `contact` (`email`, `type`) " ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " CREATE INDEX `index_contact_name_type` ON `contact` (`name`, `type`) " ) ;
2019-02-13 09:24:06 +00:00
}
} )
2019-02-17 18:29:00 +00:00
. addMigrations ( new Migration ( 44 , 45 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-17 18:29:00 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `ondemand` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-02-18 16:54:33 +00:00
. addMigrations ( new Migration ( 45 , 46 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-18 16:54:33 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `encrypt` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-02-21 19:13:11 +00:00
. addMigrations ( new Migration ( 46 , 47 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-21 19:13:11 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `use_ip` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-02-28 16:05:55 +00:00
. addMigrations ( new Migration ( 47 , 48 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-02-28 16:05:55 +00:00
db . execSQL ( " UPDATE `identity` SET use_ip = 1 " ) ;
}
} )
2019-03-03 12:59:58 +00:00
. addMigrations ( new Migration ( 48 , 49 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " CREATE INDEX `index_operation_name` ON `operation` (`name`) " ) ;
}
} )
. addMigrations ( new Migration ( 49 , 50 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-05 13:38:05 +00:00
db . execSQL ( " DROP INDEX `index_message_replying` " ) ;
db . execSQL ( " DROP INDEX `index_message_forwarding` " ) ;
db . execSQL ( " CREATE INDEX `index_message_subject` ON `message` (`subject`) " ) ;
2019-03-03 12:59:58 +00:00
}
} )
2019-03-07 08:45:10 +00:00
. addMigrations ( new Migration ( 50 , 51 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-25 16:47:52 +00:00
db . execSQL ( " DELETE FROM operation WHERE name = 'wait' " ) ;
2019-03-07 08:45:10 +00:00
}
} )
2019-03-09 08:20:46 +00:00
. addMigrations ( new Migration ( 51 , 52 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-09 08:20:46 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `total` INTEGER " ) ;
}
} )
2019-03-12 15:54:25 +00:00
. addMigrations ( new Migration ( 52 , 53 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-12 15:54:25 +00:00
db . execSQL ( " ALTER TABLE `operation` ADD COLUMN `account` INTEGER " ) ;
}
} )
2019-03-14 09:12:19 +00:00
. addMigrations ( new Migration ( 53 , 54 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-14 09:12:19 +00:00
File folder = new File ( context . getFilesDir ( ) , " attachments " ) ;
File [ ] attachments = folder . listFiles ( ) ;
if ( attachments ! = null )
for ( File source : attachments ) {
long id = Long . parseLong ( source . getName ( ) . split ( " \\ . " ) [ 0 ] ) ;
Cursor cursor = null ;
try {
cursor = db . query ( " SELECT name FROM attachment WHERE id = ? " , new Object [ ] { id } ) ;
if ( cursor ! = null & & cursor . moveToNext ( ) ) {
String name = cursor . getString ( 0 ) ;
if ( ! TextUtils . isEmpty ( name ) ) {
File target = new File ( folder , id + " . " + Helper . sanitizeFilename ( name ) ) ;
if ( source . renameTo ( target ) )
Log . i ( " Renamed attachment= " + target . getName ( ) ) ;
else {
Log . i ( " Unavailable attachment= " + source . getName ( ) ) ;
db . execSQL ( " UPDATE attachment SET available = 0 WHERE id = ? " , new Object [ ] { id } ) ;
}
}
}
} catch ( Throwable ex ) {
if ( cursor ! = null )
cursor . close ( ) ;
}
}
}
} )
2019-03-14 17:46:45 +00:00
. addMigrations ( new Migration ( 54 , 55 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-14 17:46:45 +00:00
db . execSQL ( " ALTER TABLE `contact` ADD COLUMN `avatar` TEXT " ) ;
db . execSQL ( " ALTER TABLE `contact` ADD COLUMN `times_contacted` INTEGER NOT NULL DEFAULT 1 " ) ;
db . execSQL ( " ALTER TABLE `contact` ADD COLUMN `last_contacted` INTEGER " ) ;
}
} )
2019-03-15 08:36:23 +00:00
. addMigrations ( new Migration ( 55 , 56 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-15 08:36:23 +00:00
db . execSQL ( " ALTER TABLE `contact` ADD COLUMN `favorite` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-03-15 08:50:31 +00:00
. addMigrations ( new Migration ( 56 , 57 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-15 08:50:31 +00:00
db . execSQL ( " CREATE INDEX `index_contact_times_contacted` ON `contact` (`times_contacted`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_last_contacted` ON `contact` (`last_contacted`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_favorite` ON `contact` (`favorite`) " ) ;
}
} )
2019-03-17 08:26:17 +00:00
. addMigrations ( new Migration ( 57 , 58 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-17 08:26:17 +00:00
db . execSQL ( " DROP TABLE `contact` " ) ;
db . execSQL ( " CREATE TABLE IF NOT EXISTS `contact` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , `account` INTEGER NOT NULL " +
" , `type` INTEGER NOT NULL " +
" , `email` TEXT NOT NULL " +
" , `name` TEXT, `avatar` TEXT " +
" , `times_contacted` INTEGER NOT NULL " +
" , `first_contacted` INTEGER NOT NULL " +
" , `last_contacted` INTEGER NOT NULL " +
" , `state` INTEGER NOT NULL " +
" , FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ) " ) ;
db . execSQL ( " CREATE UNIQUE INDEX `index_contact_account_type_email` ON `contact` (`account`, `type`, `email`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_email` ON `contact` (`email`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_name` ON `contact` (`name`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_times_contacted` ON `contact` (`times_contacted`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_last_contacted` ON `contact` (`last_contacted`) " ) ;
db . execSQL ( " CREATE INDEX `index_contact_state` ON `contact` (`state`) " ) ;
}
} )
2019-03-17 09:49:50 +00:00
. addMigrations ( new Migration ( 58 , 59 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-17 09:49:50 +00:00
db . execSQL ( " CREATE INDEX `index_contact_avatar` ON `contact` (`avatar`) " ) ;
}
} )
2019-03-17 19:32:57 +00:00
. addMigrations ( new Migration ( 59 , 60 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-17 19:32:57 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `parent` INTEGER " ) ;
}
} )
2019-03-18 08:33:40 +00:00
. addMigrations ( new Migration ( 60 , 61 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-18 08:33:40 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `collapsed` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-03-27 08:19:11 +00:00
. addMigrations ( new Migration ( 61 , 62 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-27 08:19:11 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `warning` TEXT " ) ;
}
} )
2019-03-31 14:36:41 +00:00
. addMigrations ( new Migration ( 62 , 63 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-03-31 14:36:41 +00:00
db . execSQL ( " DROP INDEX index_message_msgid_folder " ) ;
2019-03-31 17:09:46 +00:00
db . execSQL ( " CREATE INDEX `index_message_msgid` ON `message` (`msgid`) " ) ;
2019-03-31 14:36:41 +00:00
}
} )
2019-04-12 14:15:42 +00:00
. addMigrations ( new Migration ( 63 , 64 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-12 14:15:42 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `dkim` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `spf` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `dmarc` INTEGER " ) ;
}
} )
2019-04-17 15:27:57 +00:00
. addMigrations ( new Migration ( 64 , 65 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-17 15:27:57 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `sender_extra` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-04-17 18:21:44 +00:00
. addMigrations ( new Migration ( 65 , 66 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-17 18:21:44 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `receipt_request` INTEGER " ) ;
}
} )
2019-04-18 07:12:30 +00:00
. addMigrations ( new Migration ( 66 , 67 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-18 07:12:30 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `revision` INTEGER " ) ;
}
} )
2019-04-18 09:29:15 +00:00
. addMigrations ( new Migration ( 67 , 68 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-18 09:29:15 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `revisions` INTEGER " ) ;
db . execSQL ( " UPDATE message SET revisions = revision " ) ;
}
} )
2019-04-18 17:13:38 +00:00
. addMigrations ( new Migration ( 68 , 69 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-18 17:13:38 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `receipt_to` TEXT " ) ;
}
} )
2019-04-19 11:33:41 +00:00
. addMigrations ( new Migration ( 69 , 70 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-19 11:33:41 +00:00
db . execSQL ( " UPDATE message SET uid = NULL WHERE uid < 0 " ) ;
}
} )
2019-04-20 08:35:30 +00:00
. addMigrations ( new Migration ( 70 , 71 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-20 08:35:30 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `hide` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-04-23 09:47:56 +00:00
. addMigrations ( new Migration ( 71 , 72 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-23 09:47:56 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `list_post` TEXT " ) ;
}
} )
2019-04-25 06:18:01 +00:00
. addMigrations ( new Migration ( 72 , 73 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-25 06:18:01 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `order` INTEGER " ) ;
}
} )
2019-04-25 15:23:56 +00:00
. addMigrations ( new Migration ( 73 , 74 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-25 15:23:56 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `subscribed` INTEGER " ) ;
}
} )
2019-04-29 08:14:55 +00:00
. addMigrations ( new Migration ( 74 , 75 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-29 08:14:55 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `navigation` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-04-29 11:09:11 +00:00
. addMigrations ( new Migration ( 75 , 76 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-29 11:09:11 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `order` INTEGER " ) ;
}
} )
2019-04-30 07:06:32 +00:00
. addMigrations ( new Migration ( 76 , 77 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-04-30 07:06:32 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `read_only` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-05-01 09:26:32 +00:00
. addMigrations ( new Migration ( 77 , 78 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-01 09:26:32 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `auto_delete` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-05-04 18:52:21 +00:00
. addMigrations ( new Migration ( 78 , 79 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-04 18:52:21 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `plain_only` INTEGER " ) ;
}
} )
2019-05-08 08:32:37 +00:00
. addMigrations ( new Migration ( 79 , 80 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-08 08:32:37 +00:00
db . execSQL ( " DROP INDEX index_attachment_message_cid " ) ;
db . execSQL ( " CREATE INDEX `index_attachment_message_cid` ON `attachment` (`message`, `cid`) " ) ;
}
} )
2019-05-11 19:04:27 +00:00
. addMigrations ( new Migration ( 80 , 81 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-11 19:04:27 +00:00
db . execSQL ( " ALTER TABLE `operation` ADD COLUMN `state` TEXT " ) ;
}
} )
2019-05-11 19:30:09 +00:00
. addMigrations ( new Migration ( 81 , 82 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-11 19:30:09 +00:00
db . execSQL ( " CREATE INDEX `index_operation_account` ON `operation` (`account`) " ) ;
db . execSQL ( " CREATE INDEX `index_operation_state` ON `operation` (`state`) " ) ;
}
} )
2019-05-15 09:10:47 +00:00
. addMigrations ( new Migration ( 82 , 83 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-15 09:10:47 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `color` INTEGER " ) ;
}
} )
2019-05-25 14:01:51 +00:00
. addMigrations ( new Migration ( 83 , 84 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-25 14:01:51 +00:00
db . execSQL ( " UPDATE attachment SET disposition = lower(disposition) WHERE NOT disposition IS NULL " ) ;
}
} )
. addMigrations ( new Migration ( 84 , 85 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-05-25 14:01:51 +00:00
db . execSQL ( " UPDATE attachment SET size = NULL WHERE size = 0 " ) ;
}
} )
2019-06-07 08:14:44 +00:00
. addMigrations ( new Migration ( 85 , 86 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-06-07 08:14:44 +00:00
db . execSQL ( " CREATE VIEW `folderview` AS SELECT id, account, name, type, display, unified FROM folder " ) ;
}
} )
2019-06-07 15:01:06 +00:00
. addMigrations ( new Migration ( 86 , 87 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-10-20 05:48:12 +00:00
db . execSQL ( " DROP VIEW IF EXISTS `folderview` " ) ;
2019-06-07 15:01:06 +00:00
}
} )
2019-06-14 16:29:17 +00:00
. addMigrations ( new Migration ( 87 , 88 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-06-14 16:29:17 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `partial_fetch` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} )
2019-06-26 06:13:39 +00:00
. addMigrations ( new Migration ( 88 , 89 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-06-26 06:13:39 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `separator` INTEGER " ) ;
}
} )
2019-07-06 08:16:42 +00:00
. addMigrations ( new Migration ( 89 , 90 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-06 08:16:42 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `notifying` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-07-07 06:17:27 +00:00
. addMigrations ( new Migration ( 90 , 91 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-07 06:17:27 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `selectable` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} )
2019-07-08 17:23:07 +00:00
. addMigrations ( new Migration ( 91 , 92 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-08 17:23:07 +00:00
db . execSQL ( " UPDATE `account` SET poll_interval = 24 " ) ;
}
} )
2019-07-16 12:44:21 +00:00
. addMigrations ( new Migration ( 92 , 93 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-16 12:44:21 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `mx` INTEGER " ) ;
}
} )
2019-07-16 16:46:25 +00:00
. addMigrations ( new Migration ( 93 , 94 ) {
@Override
2019-07-17 10:21:17 +00:00
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-16 16:46:25 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `encrypt` INTEGER " ) ;
}
} )
2019-07-18 15:38:51 +00:00
. addMigrations ( new Migration ( 94 , 95 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-18 15:38:51 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `sign_key` INTEGER " ) ;
}
} )
2019-07-24 12:49:55 +00:00
. addMigrations ( new Migration ( 95 , 96 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-24 12:49:55 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `attachments` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " UPDATE message SET attachments = " +
" (SELECT COUNT(attachment.id) FROM attachment WHERE attachment.message = message.id) " ) ;
}
} )
2019-07-24 20:01:27 +00:00
. addMigrations ( new Migration ( 96 , 97 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-24 20:01:27 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `uidv` INTEGER " ) ;
}
} )
2019-07-29 19:53:32 +00:00
. addMigrations ( new Migration ( 97 , 98 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-07-29 19:53:32 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `rename` TEXT " ) ;
}
} )
2019-09-07 08:30:46 +00:00
. addMigrations ( new Migration ( 98 , 99 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-07 08:30:46 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `signature` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} )
2019-09-08 10:57:21 +00:00
. addMigrations ( new Migration ( 99 , 100 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-08 10:57:21 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `unsubscribe` TEXT " ) ;
}
} )
2019-09-23 08:47:05 +00:00
. addMigrations ( new Migration ( 100 , 101 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-23 08:47:05 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `sender_extra_regex` TEXT " ) ;
}
} )
2019-09-23 13:58:53 +00:00
. addMigrations ( new Migration ( 101 , 102 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-23 13:58:53 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `auto_seen` INTEGER NOT NULL DEFAULT 1 " ) ;
}
} )
2019-09-25 11:26:56 +00:00
. addMigrations ( new Migration ( 102 , 103 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-25 11:26:56 +00:00
db . execSQL ( " UPDATE `account` SET browse = 1 WHERE pop = 1 " ) ;
}
} )
2019-09-27 16:25:55 +00:00
. addMigrations ( new Migration ( 103 , 104 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-27 16:25:55 +00:00
db . execSQL ( " UPDATE `message` SET ui_hide = 1 WHERE ui_hide <> 0 " ) ;
}
} )
2019-09-30 14:55:58 +00:00
. addMigrations ( new Migration ( 104 , 105 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-30 14:55:58 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `priority` INTEGER " ) ;
}
} )
2019-09-30 19:00:28 +00:00
. addMigrations ( new Migration ( 105 , 106 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-09-30 19:00:28 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `total` INTEGER " ) ;
db . execSQL ( " UPDATE `message` SET total = size " ) ;
}
} )
2019-10-01 11:56:48 +00:00
. addMigrations ( new Migration ( 106 , 107 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-10-01 11:56:48 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `receipt` INTEGER " ) ;
}
} )
2019-10-07 16:15:02 +00:00
. addMigrations ( new Migration ( 107 , 108 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-10-07 16:15:02 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `color` INTEGER " ) ;
}
} )
2019-10-09 12:01:26 +00:00
. addMigrations ( new Migration ( 108 , 109 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-10-09 12:01:26 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `ignore_size` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-10-14 09:29:46 +00:00
. addMigrations ( new Migration ( 109 , 110 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-10-14 09:29:46 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_busy` INTEGER " ) ;
}
} )
2019-10-19 14:02:28 +00:00
. addMigrations ( new Migration ( 110 , 111 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-10-19 14:02:28 +00:00
db . execSQL ( " ALTER TABLE `rule` ADD COLUMN `applied` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-10-23 10:51:20 +00:00
. addMigrations ( new Migration ( 111 , 112 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-10-23 10:51:20 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `move_to` INTEGER " ) ;
}
} )
2019-11-15 20:19:33 +00:00
. addMigrations ( new Migration ( 112 , 113 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-11-15 20:19:33 +00:00
db . execSQL ( " CREATE TABLE IF NOT EXISTS `revision` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , `message` INTEGER NOT NULL " +
" , `sequence` INTEGER NOT NULL " +
" , `reference` INTEGER NOT NULL " +
2019-12-03 12:59:27 +00:00
" , FOREIGN KEY(`message`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE) " ) ;
2019-11-15 20:19:33 +00:00
db . execSQL ( " CREATE INDEX IF NOT EXISTS `index_revision_message` ON `revision` (`message`) " ) ;
db . execSQL ( " CREATE UNIQUE INDEX IF NOT EXISTS `index_revision_message_sequence` ON `revision` (`message`, `sequence`) " ) ;
}
2019-11-17 12:09:19 +00:00
} )
. addMigrations ( new Migration ( 113 , 114 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-11-17 12:09:19 +00:00
db . execSQL ( " UPDATE message SET encrypt = 1 WHERE id IN " +
" (SELECT DISTINCT message FROM attachment " +
" WHERE encryption = " + EntityAttachment . PGP_MESSAGE + " ) " ) ;
}
2019-11-15 20:19:33 +00:00
} )
2019-11-19 20:53:12 +00:00
. addMigrations ( new Migration ( 114 , 115 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-11-19 20:53:12 +00:00
db . execSQL ( " DROP TABLE revision " ) ;
}
} )
2019-12-01 13:18:24 +00:00
. addMigrations ( new Migration ( 115 , 116 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-01 13:18:24 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `use_date` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2019-12-03 12:59:27 +00:00
. addMigrations ( new Migration ( 116 , 117 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-03 12:59:27 +00:00
db . execSQL ( " CREATE TABLE IF NOT EXISTS `certificate` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , `subject` TEXT NOT NULL " +
" , `email` TEXT " +
" , `data` TEXT NOT NULL) " ) ;
db . execSQL ( " CREATE UNIQUE INDEX IF NOT EXISTS `index_certificate_subject` ON `certificate` (`subject`) " ) ;
db . execSQL ( " CREATE INDEX IF NOT EXISTS `index_certificate_email` ON `certificate` (`email`) " ) ;
}
} )
2019-12-04 09:45:53 +00:00
. addMigrations ( new Migration ( 117 , 118 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-04 09:45:53 +00:00
db . execSQL ( " DROP TABLE IF EXISTS `certificate` " ) ;
db . execSQL ( " CREATE TABLE IF NOT EXISTS `certificate` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , `fingerprint` TEXT NOT NULL " +
" , `email` TEXT NOT NULL " +
" , `subject` TEXT " +
" , `data` TEXT NOT NULL) " ) ;
db . execSQL ( " CREATE UNIQUE INDEX IF NOT EXISTS `index_certificate_fingerprint_email` ON `certificate` (`fingerprint`, `email`) " ) ;
db . execSQL ( " CREATE INDEX IF NOT EXISTS `index_certificate_email` ON `certificate` (`email`) " ) ;
}
} )
2019-12-05 19:23:31 +00:00
. addMigrations ( new Migration ( 118 , 119 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-05 19:23:31 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `sign_key_alias` TEXT " ) ;
}
} )
2019-12-06 10:32:41 +00:00
. addMigrations ( new Migration ( 119 , 120 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-06 10:32:41 +00:00
db . execSQL ( " ALTER TABLE `certificate` ADD COLUMN `after` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `certificate` ADD COLUMN `before` INTEGER " ) ;
}
} )
2019-12-08 14:00:15 +00:00
. addMigrations ( new Migration ( 120 , 121 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-08 14:00:15 +00:00
db . execSQL ( " UPDATE `account` SET ondemand = 0 " ) ;
}
} )
2019-12-13 08:09:45 +00:00
. addMigrations ( new Migration ( 121 , 122 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-13 08:09:45 +00:00
db . execSQL ( " UPDATE `message` SET raw = NULL " ) ;
File [ ] raws = new File ( context . getFilesDir ( ) , " raw " ) . listFiles ( ) ;
if ( raws ! = null )
for ( File file : raws )
file . delete ( ) ;
}
} )
2019-12-16 18:09:49 +00:00
. addMigrations ( new Migration ( 122 , 123 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-16 18:09:49 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `fingerprint` TEXT " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `fingerprint` TEXT " ) ;
}
} )
2019-12-21 15:03:57 +00:00
. addMigrations ( new Migration ( 123 , 124 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-21 15:03:57 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `provider` TEXT " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `provider` TEXT " ) ;
}
} )
2019-12-22 07:43:36 +00:00
. addMigrations ( new Migration ( 124 , 125 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-22 07:43:36 +00:00
SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
int previous_version = prefs . getInt ( " previous_version " , - 1 ) ;
if ( previous_version < = 848 & & Helper . isPlayStoreInstall ( ) ) {
// JavaMail didn't check server certificates
2020-10-25 21:20:48 +00:00
db . execSQL ( " UPDATE account SET insecure = 1 WHERE auth_type = " + AUTH_TYPE_PASSWORD ) ;
db . execSQL ( " UPDATE identity SET insecure = 1 WHERE auth_type = " + AUTH_TYPE_PASSWORD ) ;
2019-12-22 07:43:36 +00:00
}
}
} )
2019-12-24 16:18:48 +00:00
. addMigrations ( new Migration ( 125 , 126 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-24 16:18:48 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `autocrypt` TEXT " ) ;
}
} )
2019-12-28 19:35:41 +00:00
. addMigrations ( new Migration ( 126 , 127 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2019-12-28 19:35:41 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `keep_alive_ok` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `keep_alive_failed` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2020-01-07 16:43:27 +00:00
. addMigrations ( new Migration ( 127 , 128 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-07 16:43:27 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `quota_usage` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `quota_limit` INTEGER " ) ;
}
} )
2020-01-12 17:48:26 +00:00
. addMigrations ( new Migration ( 128 , 129 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-12 17:48:26 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `poll_exempted` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2020-01-14 21:39:35 +00:00
. addMigrations ( new Migration ( 129 , 130 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-14 21:39:35 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `fts` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2020-01-16 17:45:17 +00:00
. addMigrations ( new Migration ( 130 , 131 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-16 17:45:17 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `favorite` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
2020-01-18 10:28:37 +00:00
. addMigrations ( new Migration ( 131 , 132 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-18 10:28:37 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_encrypt` INTEGER " ) ;
db . execSQL ( " UPDATE `message` SET `ui_encrypt` = `encrypt` " ) ;
}
2020-01-21 14:15:48 +00:00
} )
. addMigrations ( new Migration ( 132 , 133 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-21 14:15:48 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `leave_on_server` INTEGER NOT NULL DEFAULT 1 " ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `leave_on_device` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " UPDATE `account` SET `leave_on_server` = `browse` WHERE `pop` = " + EntityAccount . TYPE_POP ) ;
}
2020-01-22 08:02:59 +00:00
} )
. addMigrations ( new Migration ( 133 , 134 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-22 15:18:21 +00:00
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
2022-04-06 06:39:18 +00:00
//createTriggers(db);
2020-01-22 08:02:59 +00:00
}
2020-01-22 15:18:21 +00:00
} )
. addMigrations ( new Migration ( 134 , 135 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2022-04-09 09:45:03 +00:00
//db.execSQL("CREATE VIEW IF NOT EXISTS `account_view` AS " + TupleAccountView.query);
//db.execSQL("CREATE VIEW IF NOT EXISTS `identity_view` AS " + TupleIdentityView.query);
2022-08-07 13:27:17 +00:00
//db.execSQL("CREATE VIEW IF NOT EXISTS `folder_view` AS " + TupleFolderView.query);
2020-01-22 15:18:21 +00:00
}
2020-01-30 13:19:15 +00:00
} )
. addMigrations ( new Migration ( 135 , 136 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-30 13:19:15 +00:00
db . execSQL ( " ALTER TABLE `certificate` ADD COLUMN `intermediate` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-01-30 17:24:46 +00:00
} )
. addMigrations ( new Migration ( 136 , 137 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-01-30 17:24:46 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `submitter` TEXT " ) ;
}
2020-02-01 12:51:32 +00:00
} )
. addMigrations ( new Migration ( 137 , 138 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-01 12:51:32 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `importance` INTEGER " ) ;
}
2020-02-02 16:17:58 +00:00
} )
. addMigrations ( new Migration ( 138 , 139 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-02 16:17:58 +00:00
db . execSQL ( " UPDATE `message` SET fts = 0 " ) ;
}
2020-02-04 10:51:26 +00:00
} )
. addMigrations ( new Migration ( 139 , 140 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-04 10:51:26 +00:00
db . execSQL ( " UPDATE `message` SET fts = 0 " ) ;
}
2020-02-09 12:58:16 +00:00
} )
. addMigrations ( new Migration ( 140 , 141 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-09 12:58:16 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `certificate` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `certificate` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-02-10 15:35:14 +00:00
} )
. addMigrations ( new Migration ( 141 , 142 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-10 15:35:14 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `certificate_alias` TEXT " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `certificate_alias` TEXT " ) ;
}
2020-02-11 16:46:04 +00:00
} )
. addMigrations ( new Migration ( 142 , 143 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-11 16:46:04 +00:00
db . execSQL ( " ALTER TABLE `operation` ADD COLUMN `tries` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-02-24 08:32:03 +00:00
} )
. addMigrations ( new Migration ( 143 , 144 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-24 08:32:03 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `inferiors` INTEGER NOT NULL DEFAULT 1 " ) ;
}
2020-02-25 20:06:17 +00:00
} )
. addMigrations ( new Migration ( 144 , 145 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-25 20:06:17 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `poll_factor` INTEGER NOT NULL DEFAULT 1 " ) ;
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `poll_count` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-02-26 12:16:09 +00:00
} )
. addMigrations ( new Migration ( 145 , 146 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-02-26 12:16:09 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `max_messages` INTEGER " ) ;
}
2020-03-08 10:08:28 +00:00
} )
. addMigrations ( new Migration ( 146 , 147 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-03-08 10:08:28 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `thread` INTEGER " ) ;
}
2020-03-22 10:28:44 +00:00
} )
. addMigrations ( new Migration ( 147 , 148 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-03-22 10:28:44 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `cc` TEXT " ) ;
}
2020-03-24 07:43:31 +00:00
} )
. addMigrations ( new Migration ( 148 , 149 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-03-24 07:43:31 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `leave_deleted` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-03-26 12:29:43 +00:00
} )
. addMigrations ( new Migration ( 149 , 150 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-03-26 12:29:43 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `language` TEXT " ) ;
}
2020-04-01 06:57:27 +00:00
} )
. addMigrations ( new Migration ( 150 , 151 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-04-01 06:57:27 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `keep_alive_succeeded` INTEGER NOT NULL DEFAULT 0 " ) ;
2020-04-01 09:26:27 +00:00
db . execSQL ( " UPDATE account SET keep_alive_failed = 0, keep_alive_ok = 0 " ) ;
2020-04-01 06:57:27 +00:00
}
2020-04-01 08:42:37 +00:00
} )
. addMigrations ( new Migration ( 151 , 152 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-04-01 08:42:37 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `hash` TEXT " ) ;
}
2020-04-13 07:11:25 +00:00
} )
. addMigrations ( new Migration ( 152 , 153 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-04-13 07:11:25 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `unicode` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-04-19 13:53:16 +00:00
} )
. addMigrations ( new Migration ( 153 , 154 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-04-19 13:53:16 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `ehlo` TEXT " ) ;
}
2020-04-23 09:28:16 +00:00
} )
. addMigrations ( new Migration ( 154 , 155 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-04-23 09:28:16 +00:00
db . execSQL ( " UPDATE `folder` SET `poll` = 1 WHERE `synchronize` = 0 " ) ;
}
2020-05-01 09:14:09 +00:00
} )
. addMigrations ( new Migration ( 155 , 156 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-05-01 09:14:09 +00:00
db . execSQL ( " CREATE INDEX IF NOT EXISTS `index_message_inreplyto` ON `message` (`inreplyto`) " ) ;
}
2020-05-06 12:50:30 +00:00
} )
. addMigrations ( new Migration ( 156 , 157 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-05-06 12:50:30 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `wasforwardedfrom` TEXT " ) ;
}
2020-05-09 05:56:06 +00:00
} )
. addMigrations ( new Migration ( 157 , 158 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-05-09 05:56:06 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `uidl` TEXT " ) ;
}
2020-05-19 10:46:35 +00:00
} )
. addMigrations ( new Migration ( 158 , 159 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-05-19 10:46:35 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_unsnoozed` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-05-20 05:55:21 +00:00
} )
. addMigrations ( new Migration ( 159 , 160 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2022-04-06 06:39:18 +00:00
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
//createTriggers(db);
2020-05-20 05:55:21 +00:00
}
2020-05-23 12:49:53 +00:00
} )
. addMigrations ( new Migration ( 160 , 161 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-05-23 12:49:53 +00:00
SharedPreferences prefs = PreferenceManager . getDefaultSharedPreferences ( context ) ;
String encrypt_method = prefs . getString ( " default_encrypt_method " , " pgp " ) ;
db . execSQL ( " UPDATE identity SET encrypt = " + ( " pgp " . equals ( encrypt_method ) ? 0 : 1 ) ) ;
prefs . edit ( ) . remove ( " default_encrypt_method " ) . apply ( ) ;
}
2020-06-06 10:14:32 +00:00
} )
. addMigrations ( new Migration ( 161 , 162 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-06-06 10:14:32 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `verified` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-06-14 15:30:00 +00:00
} )
. addMigrations ( new Migration ( 162 , 163 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2022-04-06 06:39:18 +00:00
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
//createTriggers(db);
2020-06-14 15:30:00 +00:00
}
} )
. addMigrations ( new Migration ( 163 , 164 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2022-04-06 06:39:18 +00:00
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
//createTriggers(db);
2020-06-14 15:30:00 +00:00
}
2020-06-19 13:18:43 +00:00
} )
. addMigrations ( new Migration ( 164 , 165 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-06-19 13:18:43 +00:00
db . execSQL ( " CREATE INDEX IF NOT EXISTS `index_attachment_message_type` ON `attachment` (`message`, `type`) " ) ;
2020-06-20 07:54:43 +00:00
}
} )
. addMigrations ( new Migration ( 165 , 166 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
db . execSQL ( " DROP INDEX `index_attachment_message_type` " ) ;
2020-06-19 13:18:43 +00:00
}
2020-06-25 07:14:05 +00:00
} )
. addMigrations ( new Migration ( 166 , 167 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-06-25 07:14:05 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `labels` TEXT " ) ;
}
2020-06-30 06:31:07 +00:00
} )
. addMigrations ( new Migration ( 167 , 168 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-06-30 06:31:07 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `self` INTEGER NOT NULL DEFAULT 1 " ) ;
}
2020-07-01 21:34:53 +00:00
} )
. addMigrations ( new Migration ( 168 , 169 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-07-01 21:34:53 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `max_size` INTEGER " ) ;
}
2020-07-03 07:57:43 +00:00
} )
. addMigrations ( new Migration ( 169 , 170 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-07-03 07:57:43 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `max_size` INTEGER " ) ;
}
2020-07-12 08:17:50 +00:00
} )
. addMigrations ( new Migration ( 170 , 171 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-07-12 08:17:50 +00:00
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
2022-04-06 06:39:18 +00:00
//createTriggers(db);
2020-07-12 08:17:50 +00:00
}
2020-07-22 12:57:47 +00:00
} )
. addMigrations ( new Migration ( 171 , 172 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-07-22 12:57:47 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `use_received` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-08-07 13:23:07 +00:00
} )
. addMigrations ( new Migration ( 172 , 173 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-08-07 13:23:07 +00:00
db . execSQL ( " ALTER TABLE `attachment` ADD COLUMN `subsequence` INTEGER " ) ;
db . execSQL ( " DROP INDEX `index_attachment_message_sequence` " ) ;
db . execSQL ( " CREATE UNIQUE INDEX IF NOT EXISTS `index_attachment_message_sequence_subsequence` ON `attachment` (`message`, `sequence`, `subsequence`) " ) ;
}
2020-09-05 15:06:58 +00:00
} )
. addMigrations ( new Migration ( 173 , 174 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-09-05 15:06:58 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `group` TEXT " ) ;
}
2020-09-13 16:50:47 +00:00
} )
. addMigrations ( new Migration ( 174 , 175 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-09-13 16:50:47 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `standard` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-10-02 13:54:45 +00:00
} )
. addMigrations ( new Migration ( 175 , 176 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-10-02 13:54:45 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `auto_submitted` INTEGER " ) ;
}
2020-10-29 19:03:09 +00:00
} )
. addMigrations ( new Migration ( 176 , 177 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-10-29 19:03:09 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `backoff_until` INTEGER " ) ;
}
2020-11-21 07:01:28 +00:00
} )
. addMigrations ( new Migration ( 177 , 178 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-11-21 07:01:28 +00:00
db . execSQL ( " UPDATE folder " +
" SET poll = 1 " +
" WHERE type <> ' " + EntityFolder . INBOX + " ' " +
" AND account IN " +
" (SELECT id FROM account " +
" WHERE host IN ('imap.arcor.de')) " ) ;
}
2020-12-17 14:05:44 +00:00
} )
. addMigrations ( new Migration ( 178 , 179 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-12-17 14:05:44 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `local` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2020-12-23 07:51:26 +00:00
} )
. addMigrations ( new Migration ( 179 , 180 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-12-23 07:51:26 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `reply_domain` INTEGER " ) ;
}
2020-12-24 07:30:03 +00:00
} )
. addMigrations ( new Migration ( 180 , 181 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2020-12-24 07:30:03 +00:00
db . execSQL ( " ALTER TABLE `rule` ADD COLUMN `last_applied` INTEGER " ) ;
}
2021-01-02 21:38:37 +00:00
} )
. addMigrations ( new Migration ( 181 , 182 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-01-02 21:38:37 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `auto_classify` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-01-04 08:27:27 +00:00
} )
. addMigrations ( new Migration ( 182 , 183 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-01-04 08:27:27 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `auto_classified` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-01-13 09:22:52 +00:00
} )
. addMigrations ( new Migration ( 183 , 184 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-01-13 09:22:52 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `auto_classify_source` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `folder` RENAME COLUMN `auto_classify` TO 'auto_classify_target' " ) ;
db . execSQL ( " UPDATE `folder` " +
" SET auto_classify_source = 1 " +
" WHERE (SELECT pop FROM account WHERE id = folder.account) = " + EntityAccount . TYPE_IMAP +
" AND (auto_classify_target " +
" OR type = ' " + EntityFolder . INBOX + " ' " +
" OR type = ' " + EntityFolder . JUNK + " ') " ) ;
}
2021-01-21 15:23:00 +00:00
} )
. addMigrations ( new Migration ( 184 , 185 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-01-21 15:23:00 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `notes` TEXT " ) ;
}
2021-02-01 10:54:43 +00:00
} )
. addMigrations ( new Migration ( 185 , 186 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-02-01 10:54:43 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `return_path` TEXT " ) ;
}
2021-02-11 08:51:48 +00:00
} )
. addMigrations ( new Migration ( 186 , 187 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-02-11 08:51:48 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `deleted` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_deleted` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-02-15 07:58:05 +00:00
} )
. addMigrations ( new Migration ( 187 , 188 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-02-15 07:58:05 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `ui_silent` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-02-26 08:39:26 +00:00
} )
. addMigrations ( new Migration ( 188 , 189 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-02-26 08:39:26 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `sign_default` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `encrypt_default` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-04-01 20:00:18 +00:00
} )
. addMigrations ( new Migration ( 189 , 190 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-01 20:00:18 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `selected_count` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} )
. addMigrations ( new Migration ( 190 , 191 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-01 20:00:18 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `selected_last` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-04-06 20:25:08 +00:00
} )
. addMigrations ( new Migration ( 191 , 192 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-06 20:25:08 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `modseq` INTEGER " ) ;
}
2021-04-08 07:40:21 +00:00
} )
. addMigrations ( new Migration ( 192 , 193 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-08 07:40:21 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `notes_color` INTEGER " ) ;
}
2021-04-13 07:00:56 +00:00
} )
. addMigrations ( new Migration ( 193 , 194 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-13 07:00:56 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `sender_extra_name` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-04-26 07:33:04 +00:00
} ) . addMigrations ( new Migration ( 194 , 195 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-26 07:33:04 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `receipt` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-04-30 11:09:55 +00:00
} ) . addMigrations ( new Migration ( 195 , 196 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-04-30 11:09:55 +00:00
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `internal` TEXT " ) ;
}
2021-05-13 15:25:34 +00:00
} ) . addMigrations ( new Migration ( 196 , 197 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-05-13 15:25:34 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `applied` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `last_applied` INTEGER " ) ;
}
2021-05-20 08:08:44 +00:00
} ) . addMigrations ( new Migration ( 197 , 198 ) {
2021-05-30 06:51:14 +00:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-05-30 06:51:14 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `show_images` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `show_full` INTEGER NOT NULL DEFAULT 0 " ) ;
}
} ) . addMigrations ( new Migration ( 198 , 199 ) {
2021-06-04 13:54:29 +00:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-06-04 13:54:29 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `capability_idle` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `capability_utf8` INTEGER " ) ;
}
} ) . addMigrations ( new Migration ( 199 , 200 ) {
2021-06-19 08:00:38 +00:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-06-19 08:00:38 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `blocklist` INTEGER " ) ;
}
} ) . addMigrations ( new Migration ( 200 , 201 ) {
2021-07-16 18:03:27 +00:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-07-16 18:03:27 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `bimi_selector` TEXT " ) ;
}
2021-07-19 09:54:28 +00:00
} ) . addMigrations ( new Migration ( 201 , 202 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-07-19 09:54:28 +00:00
db . execSQL ( " UPDATE identity SET use_ip = 0 WHERE host = 'smtp.office365.com' " ) ;
}
2021-07-23 20:31:23 +00:00
} ) . addMigrations ( new Migration ( 202 , 203 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-07-23 20:31:23 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `last_sync_count` INTEGER " ) ;
}
2021-07-29 16:59:05 +00:00
} ) . addMigrations ( new Migration ( 203 , 204 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-07-29 16:59:05 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT '' " ) ;
2022-06-27 06:57:35 +00:00
try ( Cursor cursor = db . query ( " SELECT id FROM account " ) ) {
2021-07-29 16:59:05 +00:00
while ( cursor ! = null & & cursor . moveToNext ( ) ) {
long id = cursor . getLong ( 0 ) ;
String uuid = UUID . randomUUID ( ) . toString ( ) ;
2022-06-27 06:57:35 +00:00
db . execSQL ( " UPDATE account SET uuid = ? WHERE id = ? " , new Object [ ] { uuid , id } ) ;
2021-07-29 16:59:05 +00:00
}
2022-06-27 13:52:19 +00:00
} catch ( Throwable ex ) {
Log . e ( ex ) ;
2021-07-29 16:59:05 +00:00
}
}
2021-08-01 14:14:48 +00:00
} ) . addMigrations ( new Migration ( 204 , 205 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-08-01 14:14:48 +00:00
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `external` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2021-08-07 15:06:11 +00:00
} ) . addMigrations ( new Migration ( 205 , 206 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-08-07 15:06:11 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `capabilities` TEXT " ) ;
}
2021-08-09 06:06:55 +00:00
} ) . addMigrations ( new Migration ( 206 , 207 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2022-04-09 09:45:03 +00:00
//db.execSQL("DROP VIEW IF EXISTS `account_view`");
//db.execSQL("CREATE VIEW IF NOT EXISTS `account_view` AS " + TupleAccountView.query);
2021-08-09 06:06:55 +00:00
}
2021-08-15 18:32:34 +00:00
} ) . addMigrations ( new Migration ( 207 , 208 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-08-16 07:36:23 +00:00
db . execSQL ( " ALTER TABLE `log` ADD COLUMN `type` INTEGER NOT NULL DEFAULT " + EntityLog . Type . General . ordinal ( ) ) ;
2021-08-15 18:32:34 +00:00
}
2021-08-16 11:07:41 +00:00
} ) . addMigrations ( new Migration ( 208 , 209 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-08-16 11:07:41 +00:00
db . execSQL ( " ALTER TABLE `log` ADD COLUMN `account` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `log` ADD COLUMN `folder` INTEGER " ) ;
db . execSQL ( " ALTER TABLE `log` ADD COLUMN `message` INTEGER " ) ;
}
2021-09-24 07:51:57 +00:00
} ) . addMigrations ( new Migration ( 209 , 210 ) {
2021-09-24 11:36:06 +00:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-09-24 11:36:06 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `namespace` TEXT " ) ;
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `separator` INTEGER " ) ;
db . execSQL ( " UPDATE folder SET separator = " +
" (SELECT separator FROM account WHERE account.id = folder.account) " ) ;
}
} ) . addMigrations ( new Migration ( 210 , 211 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-09-24 11:36:06 +00:00
db . execSQL ( " CREATE TABLE `search` " +
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT " +
" , name TEXT NOT NULL " +
" , `data` TEXT NOT NULL) " ) ;
}
2021-09-25 08:02:25 +00:00
} ) . addMigrations ( new Migration ( 211 , 212 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-09-25 08:02:25 +00:00
db . execSQL ( " ALTER TABLE `search` ADD COLUMN `color` INTEGER " ) ;
}
2021-10-03 19:45:18 +00:00
} ) . addMigrations ( new Migration ( 212 , 213 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-10-03 19:45:18 +00:00
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `category` TEXT " ) ;
}
2021-10-04 08:29:23 +00:00
} ) . addMigrations ( new Migration ( 213 , 214 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-10-04 08:29:23 +00:00
db . execSQL ( " CREATE INDEX `index_account_synchronize` ON `account` (`synchronize`) " ) ;
db . execSQL ( " CREATE INDEX `index_account_category` ON `account` (`category`) " ) ;
2021-10-20 05:48:12 +00:00
db . execSQL ( " DROP VIEW IF EXISTS `account_view` " ) ;
2021-10-04 08:29:23 +00:00
db . execSQL ( " CREATE VIEW IF NOT EXISTS `account_view` AS " + TupleAccountView . query ) ;
}
2021-10-26 07:39:31 +00:00
} ) . addMigrations ( new Migration ( 214 , 215 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-10-26 07:39:31 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `auto_add` INTEGER " ) ;
}
2021-11-09 17:44:54 +00:00
} ) . addMigrations ( new Migration ( 215 , 216 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-11-09 17:44:54 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `infrastructure` TEXT " ) ;
}
2021-12-07 08:16:36 +00:00
} ) . addMigrations ( new Migration ( 216 , 217 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-12-07 08:16:36 +00:00
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `last_sync_foreground` INTEGER " ) ;
}
2021-12-12 13:02:34 +00:00
} ) . addMigrations ( new Migration ( 217 , 218 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-12-12 13:02:34 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `smtp_from` TEXT " ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `from_domain` INTEGER " ) ;
}
2021-12-18 07:05:04 +00:00
} ) . addMigrations ( new Migration ( 218 , 219 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-12-18 07:05:04 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `resend` INTEGER " ) ;
}
2022-01-06 21:46:11 +00:00
} ) . addMigrations ( new Migration ( 219 , 220 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2022-01-06 21:46:11 +00:00
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `tls` INTEGER " ) ;
}
2022-01-18 09:07:13 +00:00
} ) . addMigrations ( new Migration ( 220 , 221 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `sensitivity` INTEGER " ) ;
}
2022-01-22 09:16:00 +00:00
} ) . addMigrations ( new Migration ( 221 , 222 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `color` INTEGER " ) ;
}
2022-02-12 19:39:49 +00:00
} ) . addMigrations ( new Migration ( 222 , 223 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `attachment` ADD COLUMN `related` INTEGER " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
2022-04-06 06:39:18 +00:00
//createTriggers(db);
2022-02-12 19:39:49 +00:00
}
2022-02-15 12:57:55 +00:00
} ) . addMigrations ( new Migration ( 223 , 224 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `attachment` ADD COLUMN `media_uri` TEXT " ) ;
}
2022-02-22 12:00:01 +00:00
} ) . addMigrations ( new Migration ( 224 , 225 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " UPDATE folder " +
" SET auto_delete = 0 " +
" WHERE type =' " + EntityFolder . JUNK + " ' " ) ;
}
2022-03-14 08:48:49 +00:00
} ) . addMigrations ( new Migration ( 225 , 226 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `snippet` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2022-03-19 16:32:35 +00:00
} ) . addMigrations ( new Migration ( 226 , 227 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_insert` " ) ;
db . execSQL ( " DROP TRIGGER IF EXISTS `attachment_delete` " ) ;
2022-04-06 06:39:18 +00:00
createTriggers ( db ) ;
2022-03-19 16:32:35 +00:00
}
2022-03-27 08:21:06 +00:00
} ) . addMigrations ( new Migration ( 227 , 228 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `contact` ADD COLUMN `group` TEXT " ) ;
}
2022-04-04 17:40:38 +00:00
} ) . addMigrations ( new Migration ( 228 , 229 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " DROP VIEW IF EXISTS `identity_view` " ) ;
db . execSQL ( " CREATE VIEW IF NOT EXISTS `identity_view` AS " + TupleIdentityView . query ) ;
}
2022-04-17 14:54:38 +00:00
} ) . addMigrations ( new Migration ( 229 , 230 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `hide_seen` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2022-04-17 15:50:57 +00:00
} ) . addMigrations ( new Migration ( 230 , 231 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " UPDATE `message` SET thread = account || ':' || thread " ) ;
}
2022-04-18 21:12:24 +00:00
} ) . addMigrations ( new Migration ( 231 , 232 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `contact` ADD COLUMN 'identity' INTEGER " ) ;
}
2022-04-22 13:36:32 +00:00
} ) . addMigrations ( new Migration ( 232 , 233 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN 'conditions' TEXT " ) ;
}
2022-05-07 17:00:48 +00:00
} ) . addMigrations ( new Migration ( 233 , 234 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " UPDATE account " +
2022-05-09 16:56:54 +00:00
" SET max_messages = MAX(max_messages, MIN(max_messages * 4, " +
2022-05-07 17:00:48 +00:00
" (SELECT COUNT(*) FROM folder " +
" JOIN message ON message.folder = folder.id " +
" WHERE folder.account = account.id " +
" AND folder.type = ' " + EntityFolder . INBOX + " ' " +
2022-05-09 16:56:54 +00:00
" AND NOT message.ui_hide))) " +
2022-05-07 17:00:48 +00:00
" WHERE pop = " + EntityAccount . TYPE_POP +
2022-05-10 05:32:06 +00:00
" AND NOT max_messages IS NULL " +
" AND NOT leave_on_device " ) ;
2022-05-07 17:00:48 +00:00
}
} ) . addMigrations ( new Migration ( 234 , 233 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
}
2022-05-28 09:25:08 +00:00
} ) . addMigrations ( new Migration ( 234 , 235 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `message` ADD COLUMN `recent` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2022-06-20 20:02:22 +00:00
} ) . addMigrations ( new Migration ( 235 , 236 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `octetmime` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2022-06-27 06:57:35 +00:00
} ) . addMigrations ( new Migration ( 236 , 237 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `rule` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT '' " ) ;
try ( Cursor cursor = db . query ( " SELECT id FROM rule " ) ) {
while ( cursor ! = null & & cursor . moveToNext ( ) ) {
long id = cursor . getLong ( 0 ) ;
String uuid = UUID . randomUUID ( ) . toString ( ) ;
db . execSQL ( " UPDATE rule SET uuid = ? WHERE id = ? " , new Object [ ] { uuid , id } ) ;
}
2022-06-27 13:52:19 +00:00
} catch ( Throwable ex ) {
Log . e ( ex ) ;
2022-06-27 06:57:35 +00:00
}
}
2022-06-27 07:08:13 +00:00
} ) . addMigrations ( new Migration ( 237 , 238 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `answer` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT '' " ) ;
try ( Cursor cursor = db . query ( " SELECT id FROM answer " ) ) {
while ( cursor ! = null & & cursor . moveToNext ( ) ) {
long id = cursor . getLong ( 0 ) ;
String uuid = UUID . randomUUID ( ) . toString ( ) ;
db . execSQL ( " UPDATE answer SET uuid = ? WHERE id = ? " , new Object [ ] { uuid , id } ) ;
}
2022-06-27 13:52:19 +00:00
} catch ( Throwable ex ) {
Log . e ( ex ) ;
}
}
} ) . addMigrations ( new Migration ( 238 , 239 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `identity` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT '' " ) ;
try ( Cursor cursor = db . query ( " SELECT id FROM identity " ) ) {
while ( cursor ! = null & & cursor . moveToNext ( ) ) {
long id = cursor . getLong ( 0 ) ;
String uuid = UUID . randomUUID ( ) . toString ( ) ;
db . execSQL ( " UPDATE identity SET uuid = ? WHERE id = ? " , new Object [ ] { uuid , id } ) ;
}
} catch ( Throwable ex ) {
Log . e ( ex ) ;
2022-06-27 07:08:13 +00:00
}
}
2022-07-19 13:25:12 +00:00
} ) . addMigrations ( new Migration ( 239 , 240 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `search` ADD COLUMN `order` INTEGER " ) ;
}
2022-08-07 13:27:17 +00:00
} ) . addMigrations ( new Migration ( 240 , 241 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `folder` ADD COLUMN `inherited_type` TEXT " ) ;
2022-09-17 07:24:04 +00:00
db . execSQL ( " DROP VIEW IF EXISTS `folder_view` " ) ;
2022-08-07 13:27:17 +00:00
db . execSQL ( " CREATE VIEW IF NOT EXISTS `folder_view` AS " + TupleFolderView . query ) ;
}
2022-08-12 20:09:50 +00:00
} ) . addMigrations ( new Migration ( 241 , 242 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `unicode` INTEGER NOT NULL DEFAULT 0 " ) ;
}
2022-09-03 09:22:44 +00:00
} ) . addMigrations ( new Migration ( 242 , 243 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " ALTER TABLE `account` ADD COLUMN `keep_alive_noop` INTEGER NOT NULL DEFAULT 0 " ) ;
db . execSQL ( " UPDATE account SET keep_alive_noop = 1 " +
" WHERE host = 'outlook.office365.com' AND pop = " + EntityAccount . TYPE_IMAP ) ;
}
2022-09-19 19:40:00 +00:00
} ) . addMigrations ( new Migration ( 243 , 244 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " UPDATE account SET keep_alive_noop = 0 " +
" WHERE host = 'outlook.office365.com' AND pop = " + EntityAccount . TYPE_IMAP ) ;
}
2022-09-28 05:31:34 +00:00
} ) . addMigrations ( new Migration ( 244 , 245 ) {
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
logMigration ( startVersion , endVersion ) ;
db . execSQL ( " UPDATE account SET keep_alive_noop = 1 " +
" WHERE host = 'outlook.office365.com' AND pop = " + EntityAccount . TYPE_IMAP ) ;
}
2021-07-16 18:03:27 +00:00
} ) . addMigrations ( new Migration ( 998 , 999 ) {
2021-05-20 08:08:44 +00:00
@Override
public void migrate ( @NonNull SupportSQLiteDatabase db ) {
2022-01-09 13:47:46 +00:00
logMigration ( startVersion , endVersion ) ;
2021-05-20 08:08:44 +00:00
db . execSQL ( " UPDATE account " +
" SET partial_fetch = 0 " +
" WHERE host = 'imap.vodafonemail.de' " +
" OR host = 'imap.arcor.de' " +
" OR host = 'imap.nexgo.de' " ) ;
}
2020-01-20 19:33:25 +00:00
} ) ;
2018-08-02 13:33:06 +00:00
}
2021-09-11 12:06:28 +00:00
public static void checkpoint ( Context context ) {
2021-02-25 13:28:58 +00:00
// https://www.sqlite.org/pragma.html#pragma_wal_checkpoint
2021-09-11 12:06:28 +00:00
DB db = getInstance ( context ) ;
db . getQueryExecutor ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
try {
long start = new Date ( ) . getTime ( ) ;
StringBuilder sb = new StringBuilder ( ) ;
SupportSQLiteDatabase sdb = db . getOpenHelper ( ) . getWritableDatabase ( ) ;
2022-07-20 14:06:23 +00:00
String mode = ( true ? " RESTART " : " PASSIVE " ) ;
2022-06-24 20:11:53 +00:00
try ( Cursor cursor = sdb . query ( " PRAGMA wal_checkpoint( " + mode + " ); " ) ) {
2021-09-11 12:06:28 +00:00
if ( cursor . moveToNext ( ) ) {
for ( int i = 0 ; i < cursor . getColumnCount ( ) ; i + + ) {
if ( i > 0 )
sb . append ( " , " ) ;
sb . append ( cursor . getInt ( i ) ) ;
}
}
}
long elapse = new Date ( ) . getTime ( ) - start ;
2022-07-21 07:11:18 +00:00
EntityLog . log ( context , " PRAGMA wal_checkpoint( " + mode + " )= " + sb +
" elapse= " + elapse + " ms " ) ;
2021-09-11 12:06:28 +00:00
} catch ( Throwable ex ) {
Log . e ( ex ) ;
2021-02-25 13:28:58 +00:00
}
}
2021-09-11 12:06:28 +00:00
} ) ;
}
2021-02-25 13:28:58 +00:00
2021-09-11 12:06:28 +00:00
public static void shrinkMemory ( Context context ) {
DB db = getInstance ( context ) ;
db . getQueryExecutor ( ) . execute ( new Runnable ( ) {
@Override
public void run ( ) {
try {
SupportSQLiteDatabase sdb = db . getOpenHelper ( ) . getWritableDatabase ( ) ;
try ( Cursor cursor = sdb . query ( " PRAGMA shrink_memory; " ) ) {
cursor . moveToNext ( ) ;
}
} catch ( Throwable ex ) {
Log . e ( ex ) ;
}
}
} ) ;
2021-02-25 13:28:58 +00:00
}
2019-05-30 10:57:57 +00:00
@Override
@SuppressWarnings ( " deprecation " )
public void beginTransaction ( ) {
super . beginTransaction ( ) ;
}
@Override
@SuppressWarnings ( " deprecation " )
public void setTransactionSuccessful ( ) {
super . setTransactionSuccessful ( ) ;
}
@Override
@SuppressWarnings ( " deprecation " )
public void endTransaction ( ) {
2022-09-26 07:01:55 +00:00
try {
super . endTransaction ( ) ;
} catch ( IllegalStateException ex ) {
if ( " Cannot perform this operation because there is no current transaction. " . equals ( ex . getMessage ( ) ) )
Log . w ( ex ) ;
else
throw ex ;
}
2019-05-30 10:57:57 +00:00
}
2018-08-02 13:33:06 +00:00
public static class Converters {
@TypeConverter
2018-11-25 12:34:08 +00:00
public static String [ ] toStringArray ( String value ) {
if ( value = = null )
return new String [ 0 ] ;
2020-06-25 07:14:05 +00:00
else {
String [ ] result = TextUtils . split ( value , " " ) ;
for ( int i = 0 ; i < result . length ; i + + )
result [ i ] = Uri . decode ( result [ i ] ) ;
return result ;
}
2018-08-02 13:33:06 +00:00
}
@TypeConverter
2018-11-25 12:34:08 +00:00
public static String fromStringArray ( String [ ] value ) {
if ( value = = null | | value . length = = 0 )
return null ;
2020-06-25 07:14:05 +00:00
else {
String [ ] copy = new String [ value . length ] ;
System . arraycopy ( value , 0 , copy , 0 , value . length ) ;
for ( int i = 0 ; i < copy . length ; i + + )
copy [ i ] = Uri . encode ( copy [ i ] ) ;
return TextUtils . join ( " " , copy ) ;
}
2018-08-02 13:33:06 +00:00
}
2018-08-07 16:25:57 +00:00
@TypeConverter
public static String encodeAddresses ( Address [ ] addresses ) {
if ( addresses = = null )
return null ;
JSONArray jaddresses = new JSONArray ( ) ;
2018-12-09 14:49:43 +00:00
for ( Address address : addresses )
try {
if ( address instanceof InternetAddress ) {
String a = ( ( InternetAddress ) address ) . getAddress ( ) ;
String p = ( ( InternetAddress ) address ) . getPersonal ( ) ;
JSONObject jaddress = new JSONObject ( ) ;
if ( a ! = null )
jaddress . put ( " address " , a ) ;
if ( p ! = null )
jaddress . put ( " personal " , p ) ;
jaddresses . put ( jaddress ) ;
} else {
JSONObject jaddress = new JSONObject ( ) ;
jaddress . put ( " address " , address . toString ( ) ) ;
jaddresses . put ( jaddress ) ;
2018-08-07 16:25:57 +00:00
}
2018-12-09 14:49:43 +00:00
} catch ( JSONException ex ) {
2018-12-24 12:27:45 +00:00
Log . e ( ex ) ;
2018-12-09 14:49:43 +00:00
}
2018-08-07 16:25:57 +00:00
return jaddresses . toString ( ) ;
}
@TypeConverter
public static Address [ ] decodeAddresses ( String json ) {
2020-05-07 11:14:21 +00:00
if ( json = = null )
2018-08-07 16:25:57 +00:00
return null ;
2020-05-08 06:15:39 +00:00
2020-05-07 11:14:30 +00:00
List < Address > result = new ArrayList < > ( ) ;
try {
JSONArray jroot = new JSONArray ( json ) ;
for ( int i = 0 ; i < jroot . length ( ) ; i + + ) {
Object item = jroot . get ( i ) ;
if ( jroot . get ( i ) instanceof JSONArray )
for ( int j = 0 ; j < ( ( JSONArray ) item ) . length ( ) ; j + + )
2020-05-08 06:15:39 +00:00
result . add ( InternetAddressJson . from ( ( JSONObject ) ( ( JSONArray ) item ) . get ( j ) ) ) ;
2020-05-07 11:14:30 +00:00
else
2020-05-08 06:15:39 +00:00
result . add ( InternetAddressJson . from ( ( JSONObject ) item ) ) ;
2020-05-07 11:14:30 +00:00
}
} catch ( Throwable ex ) {
// Compose can store invalid addresses
Log . w ( ex ) ;
2018-08-07 16:25:57 +00:00
}
2020-05-07 11:14:30 +00:00
return result . toArray ( new Address [ 0 ] ) ;
2018-08-07 16:25:57 +00:00
}
2021-08-16 07:36:23 +00:00
@TypeConverter
public static EntityLog . Type toLogType ( int ordinal ) {
return EntityLog . Type . values ( ) [ ordinal ] ;
}
@TypeConverter
public static int fromLogType ( EntityLog . Type type ) {
2021-08-17 12:21:08 +00:00
if ( type = = null )
type = EntityLog . Type . General ;
2021-08-16 07:36:23 +00:00
return type . ordinal ( ) ;
}
2018-08-02 13:33:06 +00:00
}
}