-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct migration callback AfterVersion range filter
Introduced in 1.5.0, SQLDelight had an off-by-one error for determining when to invoke an AfterMigration callback. This commit corrects the version range for which callbacks are invoked. Closes #2393.
- Loading branch information
Kevin Cianfarini
committed
May 12, 2021
1 parent
8858261
commit dcb7aa1
Showing
10 changed files
with
100 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
runtime/src/commonTest/kotlin/com/squareup/sqldelight/logs/SqlDriverMigrationCallbackTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.squareup.sqldelight.logs | ||
|
||
import com.squareup.sqldelight.db.AfterVersion | ||
import com.squareup.sqldelight.db.SqlDriver | ||
import com.squareup.sqldelight.db.migrateWithCallbacks | ||
import kotlin.test.Test | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class SqlDriverMigrationCallbackTest { | ||
|
||
@Test fun migrationCallbackInvokedOnCorrectVersion() { | ||
val schema = fakeSchema() | ||
|
||
var callbackInvoked = false | ||
|
||
schema.migrateWithCallbacks( | ||
driver = FakeSqlDriver(), | ||
oldVersion = 1, | ||
newVersion = 2, | ||
AfterVersion(1) { callbackInvoked = true } | ||
) | ||
|
||
assertTrue(callbackInvoked) | ||
} | ||
|
||
@Test fun migrationCallbacks() { | ||
val schema = fakeSchema() | ||
|
||
var callback1Invoked = false | ||
var callback2Invoked = false | ||
var callback3Invoked = false | ||
|
||
schema.migrateWithCallbacks( | ||
driver = FakeSqlDriver(), | ||
oldVersion = 0, | ||
newVersion = 4, | ||
AfterVersion(1) { callback1Invoked = true }, | ||
AfterVersion(2) { callback2Invoked = true }, | ||
AfterVersion(3) { callback3Invoked = true }, | ||
) | ||
|
||
assertTrue(callback1Invoked) | ||
assertTrue(callback2Invoked) | ||
assertTrue(callback3Invoked) | ||
} | ||
|
||
@Test fun migrationCallbackLessThanOldVersionNotCalled() { | ||
val schema = fakeSchema() | ||
|
||
var callback1Invoked = false | ||
var callback2Invoked = false | ||
var callback3Invoked = false | ||
|
||
schema.migrateWithCallbacks( | ||
driver = FakeSqlDriver(), | ||
oldVersion = 2, | ||
newVersion = 4, | ||
AfterVersion(1) { callback1Invoked = true }, | ||
AfterVersion(2) { callback2Invoked = true }, | ||
AfterVersion(3) { callback3Invoked = true }, | ||
) | ||
|
||
assertFalse(callback1Invoked) | ||
assertTrue(callback2Invoked) | ||
assertTrue(callback3Invoked) | ||
} | ||
|
||
@Test fun migrationCallbackGreaterThanNewVersionNotCalled() { | ||
val schema = fakeSchema() | ||
|
||
var callback1Invoked = false | ||
var callback2Invoked = false | ||
var callback3Invoked = false | ||
var callback4Invoked = false | ||
|
||
schema.migrateWithCallbacks( | ||
driver = FakeSqlDriver(), | ||
oldVersion = 0, | ||
newVersion = 4, | ||
AfterVersion(1) { callback1Invoked = true }, | ||
AfterVersion(2) { callback2Invoked = true }, | ||
AfterVersion(3) { callback3Invoked = true }, | ||
AfterVersion(4) { callback4Invoked = true }, | ||
) | ||
|
||
assertTrue(callback1Invoked) | ||
assertTrue(callback2Invoked) | ||
assertTrue(callback3Invoked) | ||
assertFalse(callback4Invoked) | ||
} | ||
|
||
private fun fakeSchema() = object : SqlDriver.Schema { | ||
override val version: Int = 1 | ||
override fun create(driver: SqlDriver) = Unit | ||
override fun migrate(driver: SqlDriver, oldVersion: Int, newVersion: Int) = Unit | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
sqldelight-gradle-plugin/src/test/integration-migration-callbacks/build.gradle
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
sqldelight-gradle-plugin/src/test/integration-migration-callbacks/settings.gradle
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...gration-migration-callbacks/src/main/sqldelight/com/squareup/sqldelight/integration/1.sqm
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
...gration-migration-callbacks/src/main/sqldelight/com/squareup/sqldelight/integration/2.sqm
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...gration-migration-callbacks/src/main/sqldelight/com/squareup/sqldelight/integration/3.sqm
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...ation-migration-callbacks/src/main/sqldelight/com/squareup/sqldelight/integration/test.sq
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
...migration-callbacks/src/test/java/com/squareup/sqldelight/integration/IntegrationTests.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters