1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-31 19:41:19 +00:00

Added RENAME COLUMN workaround

This commit is contained in:
M66B 2022-10-25 21:45:36 +02:00
parent 66ebf0623a
commit 1b6f0981ad
3 changed files with 2828 additions and 3 deletions

File diff suppressed because it is too large Load diff

View file

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 250,
version = 251,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -2011,11 +2011,11 @@ public abstract class DB extends RoomDatabase {
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
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("ALTER TABLE `folder` ADD COLUMN `auto_classify_target` INTEGER NOT NULL DEFAULT 0");
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" +
" AND (auto_classify" +
" OR type = '" + EntityFolder.INBOX + "'" +
" OR type = '" + EntityFolder.JUNK + "')");
}
@ -2505,6 +2505,22 @@ public abstract class DB extends RoomDatabase {
public void migrate(@NonNull SupportSQLiteDatabase db) {
db.execSQL("UPDATE `account` SET partial_fetch = 0 WHERE host = 'imap.mail.yahoo.com'");
}
}).addMigrations(new Migration(250, 251) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
// RENAME COLUMN workaround
boolean auto_classify;
boolean auto_classify_target;
try (Cursor cursor = db.query("SELECT * FROM `folder` LIMIT 0")) {
auto_classify = (cursor.getColumnIndex("auto_classify") >= 0);
auto_classify_target = (cursor.getColumnIndex("auto_classify_target") >= 0);
}
if (!auto_classify)
db.execSQL("ALTER TABLE `folder` ADD COLUMN `auto_classify` INTEGER NOT NULL DEFAULT 0");
if (!auto_classify_target)
db.execSQL("ALTER TABLE `folder` ADD COLUMN `auto_classify_target` INTEGER NOT NULL DEFAULT 0");
db.execSQL("UPDATE `folder` SET auto_classify_target = auto_classify WHERE auto_classify <> 0");
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

View file

@ -93,6 +93,8 @@ public class EntityFolder extends EntityOrder implements Serializable {
@NonNull
public Boolean download = true;
@NonNull
public Boolean auto_classify; // Obsolete
@NonNull
public Boolean auto_classify_source = false;
@NonNull
public Boolean auto_classify_target = false;