-
Notifications
You must be signed in to change notification settings - Fork 19
Add new schema options #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf89539
Add new schema options
simolus3 e4fdaca
Format
simolus3 5acd01c
Merge remote-tracking branch 'origin/main' into schema-options
simolus3 30259e7
Rename options
simolus3 fa97641
Reflect new names in changelog
simolus3 bb05e43
Merge remote-tracking branch 'origin/main' into schema-options
simolus3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt
This file contains hidden or 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,91 @@ | ||
package com.powersync | ||
|
||
import com.powersync.db.schema.Column | ||
import com.powersync.db.schema.IncludeOldOptions | ||
import com.powersync.db.schema.Schema | ||
import com.powersync.db.schema.Table | ||
import com.powersync.testutils.databaseTest | ||
import io.kotest.matchers.shouldBe | ||
import kotlin.test.Test | ||
|
||
class CrudTest { | ||
@Test | ||
fun includeMetadata() = | ||
databaseTest { | ||
database.updateSchema(Schema(Table("lists", listOf(Column.text("name")), includeMetadata = true))) | ||
|
||
database.execute("INSERT INTO lists (id, name, _metadata) VALUES (uuid(), ?, ?)", listOf("entry", "so meta")) | ||
val batch = database.getNextCrudTransaction() | ||
batch!!.crud[0].metadata shouldBe "so meta" | ||
} | ||
|
||
@Test | ||
fun includeOldValues() = | ||
databaseTest { | ||
database.updateSchema( | ||
Schema(Table("lists", listOf(Column.text("name"), Column.text("content")), includeOld = IncludeOldOptions())), | ||
) | ||
|
||
database.execute("INSERT INTO lists (id, name, content) VALUES (uuid(), ?, ?)", listOf("entry", "content")) | ||
database.execute("DELETE FROM ps_crud") | ||
database.execute("UPDATE lists SET name = ?", listOf("new name")) | ||
|
||
val batch = database.getNextCrudTransaction() | ||
batch!!.crud[0].oldData shouldBe mapOf("name" to "entry", "content" to "content") | ||
} | ||
|
||
@Test | ||
fun includeOldValuesWithFilter() = | ||
databaseTest { | ||
database.updateSchema( | ||
Schema( | ||
Table( | ||
"lists", | ||
listOf(Column.text("name"), Column.text("content")), | ||
includeOld = IncludeOldOptions(columnFilter = listOf("name")), | ||
), | ||
), | ||
) | ||
|
||
database.execute("INSERT INTO lists (id, name, content) VALUES (uuid(), ?, ?)", listOf("entry", "content")) | ||
database.execute("DELETE FROM ps_crud") | ||
database.execute("UPDATE lists SET name = ?, content = ?", listOf("new name", "new content")) | ||
|
||
val batch = database.getNextCrudTransaction() | ||
batch!!.crud[0].oldData shouldBe mapOf("name" to "entry") | ||
} | ||
|
||
@Test | ||
fun includeOldValuesWhenChanged() = | ||
databaseTest { | ||
database.updateSchema( | ||
Schema( | ||
Table( | ||
"lists", | ||
listOf(Column.text("name"), Column.text("content")), | ||
includeOld = IncludeOldOptions(onlyWhenChanged = true), | ||
), | ||
), | ||
) | ||
|
||
database.execute("INSERT INTO lists (id, name, content) VALUES (uuid(), ?, ?)", listOf("entry", "content")) | ||
database.execute("DELETE FROM ps_crud") | ||
database.execute("UPDATE lists SET name = ?", listOf("new name")) | ||
|
||
val batch = database.getNextCrudTransaction() | ||
batch!!.crud[0].oldData shouldBe mapOf("name" to "entry") | ||
} | ||
|
||
@Test | ||
fun ignoreEmptyUpdate() = | ||
databaseTest { | ||
database.updateSchema(Schema(Table("lists", listOf(Column.text("name"), Column.text("content")), ignoreEmptyUpdate = true))) | ||
|
||
database.execute("INSERT INTO lists (id, name, content) VALUES (uuid(), ?, ?)", listOf("entry", "content")) | ||
database.execute("DELETE FROM ps_crud") | ||
database.execute("UPDATE lists SET name = ?", listOf("entry")) | ||
|
||
val batch = database.getNextCrudTransaction() | ||
batch shouldBe null | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.