Delete Onedrive cloud only when not set up (#405)
This commit is contained in:
parent
2613ba5eae
commit
1d808edd8d
@ -472,7 +472,7 @@ class UpgradeDatabaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun upgrade10To11() {
|
||||
fun upgrade10To11EmptyOnedriveCloudRemovesCloud() {
|
||||
Upgrade0To1().applyTo(db, 0)
|
||||
Upgrade1To2().applyTo(db, 1)
|
||||
Upgrade2To3(context).applyTo(db, 2)
|
||||
@ -509,4 +509,52 @@ class UpgradeDatabaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun upgrade10To11UsedOnedriveCloudPreservesCloud() {
|
||||
Upgrade0To1().applyTo(db, 0)
|
||||
Upgrade1To2().applyTo(db, 1)
|
||||
Upgrade2To3(context).applyTo(db, 2)
|
||||
Upgrade3To4().applyTo(db, 3)
|
||||
Upgrade4To5().applyTo(db, 4)
|
||||
Upgrade5To6().applyTo(db, 5)
|
||||
Upgrade6To7().applyTo(db, 6)
|
||||
Upgrade7To8().applyTo(db, 7)
|
||||
Upgrade8To9(sharedPreferencesHandler).applyTo(db, 8)
|
||||
Upgrade9To10(sharedPreferencesHandler).applyTo(db, 9)
|
||||
|
||||
Sql.insertInto("VAULT_ENTITY") //
|
||||
.integer("_id", 25) //
|
||||
.integer("FOLDER_CLOUD_ID", 3) //
|
||||
.text("FOLDER_PATH", "path") //
|
||||
.text("FOLDER_NAME", "name") //
|
||||
.text("CLOUD_TYPE", CloudType.ONEDRIVE.name) //
|
||||
.text("PASSWORD", "password") //
|
||||
.integer("POSITION", 10) //
|
||||
.executeOn(db)
|
||||
|
||||
Sql.query("CLOUD_ENTITY").executeOn(db).use {
|
||||
while (it.moveToNext()) {
|
||||
Sql.update("CLOUD_ENTITY")
|
||||
.where("_id", Sql.eq(3L))
|
||||
.set("ACCESS_TOKEN", Sql.toString("Access token 3000"))
|
||||
.set("USERNAME", Sql.toString("foo@bar.baz"))
|
||||
.executeOn(db)
|
||||
}
|
||||
}
|
||||
Sql.query("CLOUD_ENTITY").executeOn(db).use {
|
||||
Assert.assertThat(it.count, CoreMatchers.`is`(3))
|
||||
}
|
||||
|
||||
Upgrade10To11().applyTo(db, 10)
|
||||
|
||||
Sql.query("VAULT_ENTITY").executeOn(db).use {
|
||||
Assert.assertThat(it.count, CoreMatchers.`is`(1))
|
||||
}
|
||||
|
||||
Sql.query("CLOUD_ENTITY").executeOn(db).use {
|
||||
Assert.assertThat(it.count, CoreMatchers.`is`(3))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,14 +12,18 @@ internal class Upgrade10To11 @Inject constructor() : DatabaseUpgrade(10, 11) {
|
||||
override fun internalApplyTo(db: Database, origin: Int) {
|
||||
db.beginTransaction()
|
||||
try {
|
||||
Sql.deleteFrom("CLOUD_ENTITY")
|
||||
.where("_id", Sql.eq(onedriveCloudId))
|
||||
.where("TYPE", Sql.eq("ONEDRIVE"))
|
||||
.executeOn(db)
|
||||
|
||||
deleteOnedriveCloudIfNotSetUp(db)
|
||||
db.setTransactionSuccessful()
|
||||
} finally {
|
||||
db.endTransaction()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteOnedriveCloudIfNotSetUp(db: Database) {
|
||||
Sql.deleteFrom("CLOUD_ENTITY")
|
||||
.where("_id", Sql.eq(onedriveCloudId))
|
||||
.where("TYPE", Sql.eq("ONEDRIVE"))
|
||||
.where("ACCESS_TOKEN", Sql.isNull())
|
||||
.executeOn(db)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user