-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove now-redundant Repository.migrate method
- Loading branch information
Showing
3 changed files
with
0 additions
and
302 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
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 |
---|---|---|
|
@@ -405,70 +405,6 @@ open class RepositoryJdbi<EntityIdT : EntityId, EntityT : Entity<EntityIdT>>( | |
} | ||
} | ||
|
||
@ExperimentalMigrationApi | ||
override fun migrate(transformEntity: ((Versioned<EntityT>) -> EntityT)?) { | ||
transactional { | ||
useHandle(jdbi) { handle -> | ||
/** | ||
* The [org.jdbi.v3.core.result.ResultIterable] must be closed after iterating - but that is | ||
* automatically done after iterating through all results, which we do in | ||
* [executeBatchOperation] below. | ||
*/ | ||
val entities = | ||
handle | ||
.createQuery( | ||
""" | ||
SELECT id, data, version, created_at, modified_at | ||
FROM "${tableName}" | ||
FOR UPDATE | ||
""" | ||
.trimIndent(), | ||
) | ||
// If we don't specify fetch size, the JDBC driver for Postgres fetches all results | ||
// by default: | ||
// https://jdbc.postgresql.org/documentation/query/#getting-results-based-on-a-cursor | ||
// This can lead to out-of-memory errors here, since we fetch the entire table. | ||
// We really only want to fetch out a single batch at a time, since we process | ||
// entities in batches. To do that, we set the fetch size, which is the number of | ||
// rows to fetch at a time. Solution found here: | ||
// https://www.postgresql.org/message-id/[email protected] | ||
.setFetchSize(100) | ||
.map(rowMapper) | ||
|
||
val modifiedAt = Instant.now() | ||
|
||
executeBatchOperation( | ||
handle, | ||
entities, | ||
// We don't have to check version here, since we use FOR UPDATE above, so we know we | ||
// have the latest version | ||
statement = | ||
""" | ||
UPDATE "${tableName}" | ||
SET | ||
version = :nextVersion, | ||
data = :data::jsonb, | ||
modified_at = :modifiedAt | ||
WHERE | ||
id = :id | ||
""" | ||
.trimIndent(), | ||
bindParameters = { batch, entity -> | ||
val nextVersion = entity.version.next() | ||
val updatedEntity = | ||
if (transformEntity == null) entity.item else transformEntity(entity) | ||
|
||
batch | ||
.bind("nextVersion", nextVersion) | ||
.bind("data", serializationAdapter.toJson(updatedEntity)) | ||
.bind("id", entity.item.id) | ||
.bind("modifiedAt", modifiedAt) | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
override fun <ReturnT> transactional(block: () -> ReturnT): ReturnT { | ||
return transactional(jdbi, block) | ||
} | ||
|
199 changes: 0 additions & 199 deletions
199
src/test/kotlin/no/liflig/documentstore/repository/MigrationTest.kt
This file was deleted.
Oops, something went wrong.