|
|
|
@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
|
|
|
|
|
// https://developer.android.com/topic/libraries/architecture/room.html
|
|
|
|
|
|
|
|
|
|
@Database(
|
|
|
|
|
version = 1,
|
|
|
|
|
version = 2,
|
|
|
|
|
entities = {
|
|
|
|
|
EntityIdentity.class,
|
|
|
|
|
EntityAccount.class,
|
|
|
|
@ -124,267 +124,9 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `poll_interval` INTEGER NOT NULL DEFAULT 9");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(2, 3) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `store_sent` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(3, 4) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("CREATE TABLE IF NOT EXISTS `answer` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `text` TEXT NOT NULL)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(4, 5) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `auth_type` INTEGER NOT NULL DEFAULT 1");
|
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `auth_type` INTEGER NOT NULL DEFAULT 1");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(5, 6) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_found` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(6, 7) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("CREATE TABLE IF NOT EXISTS `log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `time` INTEGER NOT NULL, `data` TEXT NOT NULL)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_log_time` ON `log` (`time`)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(7, 8) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_found` ON `message` (`ui_found`)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(8, 9) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `headers` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(9, 10) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `unified` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_folder_unified` ON `folder` (`unified`)");
|
|
|
|
|
db.execSQL("UPDATE `folder` SET unified = 1 WHERE type = '" + EntityFolder.INBOX + "'");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(10, 11) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `signature` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(11, 12) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `flagged` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_flagged` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(12, 13) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `avatar` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(13, 14) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `color` INTEGER");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(14, 15) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `attachment` ADD COLUMN `cid` TEXT");
|
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_attachment_message_cid` ON `attachment` (`message`, `cid`)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(15, 16) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `size` INTEGER");
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `content` INTEGER NOT NULL DEFAULT 1");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(16, 17) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `deliveredto` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(17, 18) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `display` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(18, 19) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `hide` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(19, 20) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll_interval` INTEGER");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(20, 21) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_ignored` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_ignored` ON `message` (`ui_ignored`)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(21, 22) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("DROP INDEX `index_message_folder_uid`");
|
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_message_folder_uid_ui_found` ON `message` (`folder`, `uid`, `ui_found`)");
|
|
|
|
|
db.execSQL("DROP INDEX `index_message_msgid_folder`");
|
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_message_msgid_folder_ui_found` ON `message` (`msgid`, `folder`, `ui_found`)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(22, 23) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `starttls` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `insecure` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `insecure` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(23, 24) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `preview` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(24, 25) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `created` INTEGER");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(25, 26) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `extra` TEXT");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(26, 27) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `color` INTEGER");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_identity_account_email` ON `identity` (`account`, `email`)");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.addMigrations(new Migration(27, 28) {
|
|
|
|
|
@Override
|
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
|
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
|
|
|
|
|
|
// https://www.sqlite.org/lang_altertable.html
|
|
|
|
|
db.execSQL("PRAGMA foreign_keys=OFF;");
|
|
|
|
|
|
|
|
|
|
db.execSQL("CREATE TABLE `message_new`" +
|
|
|
|
|
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT," +
|
|
|
|
|
" `account` INTEGER NOT NULL," +
|
|
|
|
|
" `folder` INTEGER NOT NULL," +
|
|
|
|
|
" `identity` INTEGER," +
|
|
|
|
|
" `extra` TEXT," +
|
|
|
|
|
" `replying` INTEGER," +
|
|
|
|
|
" `uid` INTEGER," +
|
|
|
|
|
" `msgid` TEXT," +
|
|
|
|
|
" `references` TEXT," +
|
|
|
|
|
" `deliveredto` TEXT," +
|
|
|
|
|
" `inreplyto` TEXT," +
|
|
|
|
|
" `thread` TEXT," +
|
|
|
|
|
" `avatar` TEXT," +
|
|
|
|
|
" `from` TEXT," +
|
|
|
|
|
" `to` TEXT," +
|
|
|
|
|
" `cc` TEXT," +
|
|
|
|
|
" `bcc` TEXT," +
|
|
|
|
|
" `reply` TEXT," +
|
|
|
|
|
" `headers` TEXT," +
|
|
|
|
|
" `subject` TEXT," +
|
|
|
|
|
" `size` INTEGER," +
|
|
|
|
|
" `content` INTEGER NOT NULL," +
|
|
|
|
|
" `preview` TEXT," +
|
|
|
|
|
" `sent` INTEGER," +
|
|
|
|
|
" `received` INTEGER NOT NULL," +
|
|
|
|
|
" `stored` INTEGER NOT NULL," +
|
|
|
|
|
" `seen` INTEGER NOT NULL," +
|
|
|
|
|
" `flagged` INTEGER NOT NULL," +
|
|
|
|
|
" `ui_seen` INTEGER NOT NULL," +
|
|
|
|
|
" `ui_flagged` INTEGER NOT NULL," +
|
|
|
|
|
" `ui_hide` INTEGER NOT NULL," +
|
|
|
|
|
" `ui_found` INTEGER NOT NULL," +
|
|
|
|
|
" `ui_ignored` INTEGER NOT NULL," +
|
|
|
|
|
" `error` TEXT," +
|
|
|
|
|
" FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ," +
|
|
|
|
|
" FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ," +
|
|
|
|
|
" FOREIGN KEY(`identity`) REFERENCES `identity`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL ," +
|
|
|
|
|
" FOREIGN KEY(`replying`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL" +
|
|
|
|
|
" )");
|
|
|
|
|
|
|
|
|
|
db.execSQL("DELETE from `message` WHERE account IS NULL;");
|
|
|
|
|
db.execSQL("INSERT INTO `message_new` SELECT * FROM `message`;");
|
|
|
|
|
db.execSQL("DROP TABLE `message`;");
|
|
|
|
|
db.execSQL("ALTER TABLE `message_new` RENAME TO `message`");
|
|
|
|
|
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_account` ON `message` (`account`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_folder` ON `message` (`folder`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_identity` ON `message` (`identity`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_replying` ON `message` (`replying`)");
|
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_message_folder_uid_ui_found` ON `message` (`folder`, `uid`, `ui_found`)");
|
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_message_msgid_folder_ui_found` ON `message` (`msgid`, `folder`, `ui_found`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_thread` ON `message` (`thread`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_received` ON `message` (`received`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_seen` ON `message` (`ui_seen`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_hide` ON `message` (`ui_hide`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_found` ON `message` (`ui_found`)");
|
|
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_ignored` ON `message` (`ui_ignored`)");
|
|
|
|
|
|
|
|
|
|
db.execSQL("PRAGMA foreign_key_check;");
|
|
|
|
|
db.execSQL("PRAGMA foreign_keys=ON;");
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build();
|
|
|
|
|